Re: [luabind] Returning function from Lua
Brought to you by:
arvidn,
daniel_wallin
From: Vladislav I. S. <v.s...@kg...> - 2006-08-30 12:10:13
|
=20 =20 ________________________________ From: Vladislav I. Sobkovskiy=20 Sent: Wednesday, August 30, 2006 2:18 PM To: 'lua...@li...' Subject: RE: [luabind] Returning function from Lua =20 Why you use tables? Luabind classes it is better think, take a look on my test code: =20 test3.lua ---------------------- class 'entity' =20 function entity:__init(name) self.name =3D name print('entity init') end =20 function entity:dump() print('\n --- entity dump ---\nname: ' .. self.name) end =20 function entity:foo() print('entity foo') end =20 class 'test' (entity) function test:__init(name) super(name) print('test init') end =20 function test:foo() entity.foo(self) =20 print("test foo") =20 end =20 function test:bar() print('test bar') end =20 =20 C++ code ------------------------------ object *o1; object *o2; =20 // manual controlled 'live of objects' void g() { o1 =3D new object( (globals(interpreter->state())["test"])("Entity1") ); o2 =3D new object( (globals(interpreter->state())["test"])("Entity2") ); call_member<void> (*o1, "dump"); call_member<void> (*o2, "dump"); delete o1; delete o2; } =20 // automatically controlled 'live of objects' void w() { object o =3D globals(interpreter->state())["test"]; object e =3D object(o("Entity3")); =20 call_member<void> (e, "dump"); } =20 Try this one. =20 -----Original Message----- From: lua...@li... [mailto:lua...@li...] On Behalf Of Steven Lecompte Sent: Wednesday, August 30, 2006 1:42 PM To: lua...@li... Subject: [luabind] Returning function from Lua =20 First of all I use Luabind as an interface between Lua (5.1) and C++ =20 I want to return a table with lua functions that I can call in C++. When I read the docs I had the idea to use a luabind object te catch the result and then to execute this object. Now in practice this doesn't really work. Here is my test code: =20 =20 Lua: ---- =20 Commands =3D {} =20 Commands.Attack =3D function (FromProxy, TargetProxy) print ("Attack") = end Commands.Defend =3D function (FromProxy, TargetProxy) print ("Defend") = end Commands.Construct =3D function (FromProxy, TargetProxy) print=20 ("Construct") end Commands.Destroy =3D function (FromProxy, TartgetProxy) print = ("Destroy") end =20 function SetPropertyCommand (Type) =20 return Commands =20 end =20 =20 =20 =20 C++: (Commands_ is the luabind::object) ---- =20 Commandgroup::Commandgroup (std::string Type, LuaStateObject& Luahandling): Luahandling_ (Luahandling) { Commands_ =3D luabind::call_function <luabind::object>=20 (Luahandling_.Getstate(), "SetPropertyCommand", Type); } =20 void Commandgroup::ExecCommand (std::string CommandName, ProxyObj&=20 Target, ProxyObj& Source) { //TEST luabind::call_function <void> (Commands_[1], boost::ref(Target), boost::ref(Source)); //error //TEST } =20 =20 =20 Error: ------ =20 Assertion failed: crep && "you are trying to use an unregistered type", file ../ ../../../Luabind/luabind/luabind/luabind/detail/policy.hpp, line 808 =20 This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. =20 Press any key to continue. =20 =20 Now I wonder if Lua returns this as a 'pass by value' or as a reference I have also tried to pass a luabind object as a reference argument (with boost::ref) but this didn't work either. Sorry if this is a noob question but I'm totally new with Lua and Laubind. =20 Thanks for your help =20 =20 ------------------------------------------------------------------------ - 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=3Dlnk&kid=3D120709&bid=3D263057&dat=3D= 121642 _______________________________________________ luabind-user mailing list lua...@li... https://lists.sourceforge.net/lists/listinfo/luabind-user =20 =20 =20 __________ NOD32 1.1668 (20060719) Information __________ =20 This message was checked by NOD32 antivirus system. http://www.eset.com =20 =20 |