Re: Control of luabind::objects

Nigel J Atkinson <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
Lubind::object s are not used to 'store' c++ objects.  They are used to handle or 'wrap' Lua objects when you are manipulating things from c++.  When you use the push method it pushes its 'contents', onto the Lua stack.

However I think the problem you are encountering might be object slicing.  This is where in the transition from Lua to C++ and back to Lua, the Lua part of the object is lost.

What you need to do to solve that is use luabind::wrapbase.  There is more info about object slicing in the docs, but basically it maintains a reference to the Lua part of the object so it does not get garbage collected.

Nigel


On 21/05/2011, at 9:15 AM, Josh Klint wrote:

> Is it possible to ensure luabind always uses the same Luabind::object for any given C++ object?  I am having problems because luabind is creating new luabind::objects and returning those, without the information I attached to the “real” object.
>  
> Example:
> 
> --“entity” is the luabind::object created for the C++ object
> entity.health= entity.health -1
>  
> for child in entity.kids do —“kids” is an std::list exposed to LuaBind
>                 child.health = child.health-1 –Can’t access this because luabind creates a new luabind::object and returns it, instead of returning the one I created and pushed the “health” value onto
> end
>  
> I would like to have a callback function LuaBind uses to get the actual luabind::object I created and pushed onto the stack when I added values.  Right now, any values I add to a luabind::object will get lost if a function returns an object, because a new empty luabind::object will be created.
>  
>  
> Best Regards,
>  
> Josh Klint
> CEO
> Leadwerks Software
> www.leadwerks.com
>  
> ------------------------------------------------------------------------------
> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.