[luabind] Creating instances by C++ of a class defined in lua
Brought to you by:
arvidn,
daniel_wallin
From: Christian <zap...@gm...> - 2004-12-02 14:50:45
|
Hello! I have defined a class in lua like this one: --------------------------------------------- class 'luaclass' function luaclass:__init() self.val = 0; end function luaclass:setVal(num) self.val = num; end function luaclass:e() print(self.val); end --------------------------------------------- I want to create instances of "luaclass" by C++. I have tried it this way, which doesn't give any error but calls to memberfunctions of "luaclass" dont work correctly. If I do something like the following it looks like only one instance was created. --------------------------------------------- luabind::object my_class(luabind::get_globals(L_)["luaclass"]); luabind::object my_class2(luabind::get_globals(L_)["luaclass"]); luabind::call_member<void>(my_class, "setVal", 10); luabind::call_member<void>(my_class2, "setVal", 20); luabind::call_member<void>(my_class, "e"); luabind::call_member<void>(my_class2, "e"); luabind::call_member<void>(my_class, "setVal", 11); luabind::call_member<void>(my_class2, "setVal", 22); luabind::call_member<void>(my_class, "e"); luabind::call_member<void>(my_class2, "e"); --------------------------------------------- I expected (hoped) to get this: 10 20 11 22 ... but got this: 20 20 22 22 I would be very thankful for any advice how to do this in the right way. Greetings, Christian |