assigning extra fields to object of luabinded class in lua and keeping that extra field between function calls.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

assigning extra fields to object of luabinded class in lua and keeping that extra field between function calls.

Gmail-3
Hi all,
what i am doing is trying to call a lua function from c++ using call_function method and passing an object of luabinded class that works great thanks to you :), but now i need to store extra variables to that object so if that c++ object is used again as a parameter to another lua function call and that function needs to access that extra lua variable it would find it.
C++:
object function1(<func1 from lua stack retreived from MyTable table>);
object function1(<func2 from lua stack retreived from MyTable table>);
call_function<void>(function1,this);
call_function<void>(function2,this);
LUA:
funtion MyTable:func1()
       self.extra_field = 2 --this is a new assignment, extra_field is not binded from luabind
end
funtion MyTable:func2()
       print(self.extra_field)  --prints nil
end
As a thought, can i set a metatable to self before sending it to lua and override __index and__newindex to set and retreive data from a hidden lua table when new fields are introduced, but when i try to do setmetatable from lua on self it causes error that it expects a table not a userdata, also how to identify the object sent to lua so i create the hidden table for that specifeic object or lookup for that table when trying to retreive extra data,if there is other approaches please tell me about them.
Sorry for enlargement.
Thanks
--
Kariem

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, &
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user