Re: How to call a Lua function which has been defined in a table ?

Tony Kostanjsek <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
hi Nicolas,

try to pull the function from the table first before calling it:
luabind::object func = luabind::globals["mytable"]["func"];
luabind::call_function<void>(L, func);
In Lua, this would be the dot notation: mytable.func()
If it is a method with implicit "self" parameter then you need to specify it as 
the first one in the call:
luabind::object myobject = luabind::globals["myobject"];
luabind::object func = luabind::globals["myobject"]["func"];
luabind::call_function<void>(L, func, myobject);
This would be equivalent to myobject:func() in Lua (note the colon). Add more 
parameters as required.
Don't forget to check for nil values.
Something like this should work.
Best,
Tony 






________________________________
Von: Nicolas Goles <[email protected]>
An: [email protected]
Gesendet: Montag, den 13. Dezember 2010, 19:39:49 Uhr
Betreff: [luabind] How to call a Lua function which has been defined in a table 
?

Hello!,

I'm trying to call a Lua Function which has been defined inside a     table:

table = {}

function table:test()
    print("Lua Rocks")
end


How can I call that function from C++ ? I'm trying to use luabind::call_function 
resulting in:

terminate called after throwing an instance of 'luabind::error'
  what():  lua runtime error

I tried :

            luabind::call_function<void>(L "table:test",     NULL);

Help is appreciated :)

Thanks.

_Nicolas



-- 
Nicolas Goles Domic
Founder         & Lead Developer
Gando Games

------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d

_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.