Accessing non-existant members of luabind classes.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Accessing non-existant members of luabind classes.

Alexander Gladysh
Hi, all!

Is there a way to restrict access to existing members of my
Luabind-class in Lua?

luabind::class<foo>("foo")
  .constructor<>()
  .def_readwrite(bar, &foo::bar)
  ;

local f = foo()
f.bar = "bar"
f.bad_member = 7 -- Should fail.

I've found such mistake to be very common in our code.

Thanks in advance,
Alexander.


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
<a href="http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642">http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Accessing non-existant members of luabind classes.

Dmitriy Iassenev
Hello Alexander,

Thursday, April 20, 2006, 7:13:17 PM, you wrote:
AG> Is there a way to restrict access to existing members of my
AG> Luabind-class in Lua?

AG> luabind::class<foo>("foo")
AG>   .constructor<>()
AG>   .def_readwrite(bar, &foo::bar)
AG>   ;

AG> local f = foo()
AG> f.bar = "bar"
AG> f.bad_member = 7 -- Should fail.
you should setup metatable to your class instance table, which raises
assertion when __newindex method is called, i.e. something like this:

local f = foo()
local previous_metatable = getmetatable(f)
if (previous_metatable ~= nil) then
    setmetatable   (
        f,
        {
            __newindex = function (table,key) assert(false) end,
            __index = previous_metatable.__index,
        }
    )
else
    setmetatable   (
        f,
        {
            __newindex = function (table,key) assert(false) end,
        }
    )
end

--
Best regards,
 Dmitriy                            mailto:[hidden email]



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Accessing non-existant members of luabind classes.

Alexander Gladysh
> AG> Is there a way to restrict access to existing members of my
> AG> Luabind-class in Lua?

[...]

> AG> f.bad_member = 7 -- Should fail.

> you should setup metatable to your class instance table, which raises
> assertion when __newindex method is called, i.e. something like this:

[...]

The problem is that I have many entities registered in Luabind. Is
there a way to do this (semi-)automatically for every class
registered?

Thanks,
Alexander.


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
<a href="http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642">http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re[2]: Accessing non-existant members of luabind classes.

Dmitriy Iassenev
Hello Alexander,

Thursday, April 20, 2006, 8:06:31 PM, you wrote:

>> AG> Is there a way to restrict access to existing members of my
>> AG> Luabind-class in Lua?

AG> [...]

>> AG> f.bad_member = 7 -- Should fail.

>> you should setup metatable to your class instance table, which raises
>> assertion when __newindex method is called, i.e. something like this:

AG> [...]

AG> The problem is that I have many entities registered in Luabind. Is
AG> there a way to do this (semi-)automatically for every class
AG> registered?

you should try to find a place in luabind where class instance
instantiation is performed and place that metatable stuff there.

--
Best regards,
 Dmitriy                            mailto:[hidden email]



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re[3]: Accessing non-existant members of luabind classes.

Dmitriy Iassenev
AG>> [...]

DI> you should try to find a place in luabind where class instance
DI> instantiation is performed and place that metatable stuff there.

Probably, this point is here (I've been using beta7 rc4 Devil branch
still):

class_registry.cpp, line 79,
int create_cpp_instance_metatable(lua_State* L)

you can specify your own function for __newindex method

--
Best regards,
 Dmitriy                            mailto:[hidden email]



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user