Returning derived classes to C++ from Lua
Jason McKesson <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
What I want to do is expose a base class to Lua, then have one or more Lua scripts derive a class from it that they will return back to C++. The C++ code can access these derived instances through the base class members, and the C++ code will destroy these instances when the time comes. I've got most of it working now. I can expose a base class to Lua, and have Lua derive a new class from it. Lua scripts can call the derived class members and get the appropriate values. I'm using a wrapper class, as the example suggests. The problem is passing them back from Lua to C++. Here is how I call the script chunk (after compiling the string and getting the compiled chunk as a luabind::object): TestClass *pTestClass = lb::call_function<TestClass*>(compiledScript); This works only if the script returns a TestClass instances. If the script returns an instance of its derived class, a pointer is returned, but it isn't a legal pointer; attempting to use it causes execution to fail. And I can't seem to make policies happen at all. They won't even compile. I know the policy has to go in [] after the lb::call_function, but when I put [lb::adopt(result)] at the end, the compiler complains that it can't find adopt or result. I'm using Luabind 8.1, if that causes any problems. I'd rather not have to upgrade to get this working. My compiler is VS2008. ------------------------------------------------------------------------------