Re: Getting a C++ object back from a luabind::object?
"Josh Klint" <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <000901cc15c2$ef943cd0$cebcb670$@com> |
Your suggestion gives me the following error in VS 2008:
"Unhandled exception at 0x7c812afb in LE3.exe: Microsoft C++ exception:
luabind::cast_failed at memory location 0x0012f894..."
Object* Interpreter::ToObject(const int& index)
{
luabind::object o = luabind::object(L,index);
//return luabind::touserdata<Object>(o);
return luabind::object_cast<Object*>(o);
}
Best Regards,
Josh Klint
CEO
Leadwerks Software
www.leadwerks.com
-----Original Message-----
From: Nigel Atkinson [mailto:[email protected]]
Sent: Wednesday, May 18, 2011 4:31 PM
To: [email protected]
Subject: Re: [luabind] Getting a C++ object back from a luabind::object?
Perhaps
return luabind::touserdata<Object*>(o);
instead? I.e. cast to a pointer rather than an object it self. Perhaps
underneath, it uses dynamic_cast.
I haven't used luabind::touserdata before though - I'm just guessing.
Personally I would have gone with
return luabind::object_cast<Object*>(o);
Nigel
On Wed, 2011-05-18 at 09:26 -0700, Josh Klint wrote:
> Here's what I'm trying:
>
> void Interpreter::PushObject(Object* o)
> {
> if (objectmap[o]==NULL) objectmap[o] = new luabind::object(L,o);
> objectmap[o]->push(L);
> }
>
> Object* Interpreter::ToObject(const int& index)
> {
> luabind::object o = luabind::object(L,index);
> return luabind::touserdata<Object>(o);
> }
>
> But if I use this code:
> Entity* entity = new Entity; //The class "Entity" is derived from "Object"
> PushObject(entity);
> entity = (Entity*)ToObject(-1);
>
> The value returned from ToObject() is NULL.
>
>
> Best Regards,
>
> Josh Klint
> CEO
> Leadwerks Software
> www.leadwerks.com
>
> -----Original Message-----
> From: Reko Tiira [mailto:[email protected]]
> Sent: Wednesday, May 18, 2011 1:35 AM
> To: [email protected]
> Subject: Re: [luabind] Getting a C++ object back from a luabind::object?
>
> I think what you want is:
>
> return luabind::touserdata<Object>(o);
>
> Regards,
> Reko Tiira
>
>
----------------------------------------------------------------------------
> --
> What Every C/C++ and Fortran developer Should Know!
> Read this article and learn how Intel has extended the reach of its
> next-generation tools to help Windows* and Linux* C/C++ and Fortran
> developers boost performance applications - including clusters.
> http://p.sf.net/sfu/intel-dev2devmay
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
>
----------------------------------------------------------------------------
--
> What Every C/C++ and Fortran developer Should Know!
> Read this article and learn how Intel has extended the reach of its
> next-generation tools to help Windows* and Linux* C/C++ and Fortran
> developers boost performance applications - including clusters.
> http://p.sf.net/sfu/intel-dev2devmay
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
----------------------------------------------------------------------------
--
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its
next-generation tools to help Windows* and Linux* C/C++ and Fortran
developers boost performance applications - including clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its
next-generation tools to help Windows* and Linux* C/C++ and Fortran
developers boost performance applications - including clusters.
http://p.sf.net/sfu/intel-dev2devmay