tolua++: Adding lua functions to a C++ class that has been exported to Lua
Posted
by
skyeagle
on Stack Overflow
See other posts from Stack Overflow
or by skyeagle
Published on 2011-01-09T23:46:49Z
Indexed on
2011/01/09
23:53 UTC
Read the original article
Hit count: 640
I am using tolua++ to export some C++ classes to Lua.
My understanding that each class is 'implemented' on the lua side, as a lua table. I am wondering if it is possible therefore, to add new (Lua) methods to the C++ object table so that I can achieve the effect of adding new methods to the C++ class.
Assume that I am exporting the class Foobar.
Methods of Foobar will be accessisble in Lua as follows:
Foobar:method1()
Foobar:method2()
...
etc.
I would like to be able to add new methods (newmethod1, and newmethod2) to the Foobar table "object"
I have the following questions:
- Is it possible to 'extend' the functionality of an exported C++ object in the manner I described above?
- How would one go about add new functions to the Foobar table? (I am relatively new to Lua)
© Stack Overflow or respective owner