Hi there, I've got subclassing working pretty well between Lua and C++. So I have a C++ base class, and can create subclasses in Lua and instantiate them there, add them to my "world", have them traversed and their methods called from C++, etc.
What I don't understand how to do is how to create instances of Lua classes from C++. Is this possible? I have the name of the classes, because I call my own "register" method from Lua, so my app knows the names of available subclasses. But how can I create a new instance of one of them from C++?
class 'Derived' (app.Base)
app.Base.__init(self, str .. " (Derived)")
Later on, in C++, I'd like to do the Lua equivalent of:
x = Derived("hello")
Then I can do:
world = app.getWorld()
All I can think of is something like:
shared_ptr<Base> x = luabind::call_function<shared_ptr<Base> >(luaState, "createObject", "Derived", "hello");
world->addObject(x); // and so on...
Any ideas? I can't just call new on my luabind::wrap_base - derived object, then register that with Lua/luabind somehow (and tell it what Lua subclass it should be using)? (that would be nice ;-)