Archived

This topic is now archived and is closed to further replies.

Lua and Methods

This topic is 5150 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello- From the reading I''ve done, Lua seems very function-centric. Calling my C++ functions from Lua is no problem, but calling a class method seems impossible. lua_register simply doesn''t accept pointers to class methods. From what I can tell, luabind is much for being able to declare C++ objects within your Lua script, but I simply need to register a class method to be called from within my Lua script. Any help is much appreciated-

Share this post


Link to post
Share on other sites
ever tried to make a function pointer to a class member function?
-> won''t work (unless using tricks like functors)

so you could make something like:

class someclass
{
void wantthat();
};

void callwantthat(lua_state *l)
{
((someclass)l->toUserdata(l,1))->wantthat();
}


this won''t compile with 99% probability as it was typed off my head and function names/parameters, especially of toUserdata(), are wrong, but i hope you get the idea.

you could also look at tolua/luabind how they do it (if they can) but i have not used them so i can''t really tell.

Share this post


Link to post
Share on other sites