Returning derived classes to C++ from Lua

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Returning derived classes to C++ from Lua

Jason McKesson
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.

------------------------------------------------------------------------------

_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Returning derived classes to C++ from Lua

Daniel Wallin
On Mon, May 24, 2010 at 07:57:54PM -0700, Jason McKesson wrote:
> 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.

Hi Jason,

Sorry for the late response. Have you been able to resolve this?

--
Daniel Wallin
BoostPro Computing
http://www.boostpro.com

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user