🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Lua and Methods

Started by
0 comments, last by Quasimodem 20 years, 7 months ago
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-
Advertisement
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.

http://mitglied.lycos.de/lousyphreak/

This topic is closed to new replies.

Advertisement