lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Colm Sloan wrote:
I have an unusual situation. I have an object in C++ that is given many many values in C++. I can grab this object and get its Lua equivalent:
<code>

I want to make it so I can create a Lua object that inherits all of the values associated with that C++ object. I made it so I pass the object to another class but it can't use the syntactical sugar of ":", making it feel very unnatural:

<code>
I understand this is a complicated post so all input is appreciated.
I'm having difficulty understanding what you're trying to accomplish. I believe you're trying to create derived classes in Lua, using the C++ userdata object as a base class of sorts? If I'm understanding what you're trying to do, you're attempting to override some default functionality provided by the metatable of the C++ object with a Lua replacement. Specifically you're trying to override the method for 'Setup' with your own function defined in Lua, and have the C++ 'base' Setup method call the correct 'derived' method according to the Lua class name.

Since you can store data in your C++ object's associated Lua table (I'm basing this assumption on 'self.luaClassName'), I'd suggest you merge your data defined in the Lua class's table directly into the associated table. If your __index metaevent handler prioritizes content in the associated table over content in the metatable, when you call 'self:Setup()' it should invoke the Lua method that was stored in your associated table. This should then work for all merged methods/data members.

Olivier