Control of luabind::objects

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

Control of luabind::objects

Josh Klint

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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Control of luabind::objects

Josh Klint

I should also mention that in my example below, “health” is not a C++ class member, but just a Lua value I added to the entity.

 

 

Best Regards,

 

Josh Klint

CEO

Leadwerks Software

www.leadwerks.com

 

From: Josh Klint [mailto:[hidden email]]
Sent: Friday, May 20, 2011 4:16 PM
To: [hidden email]
Subject: [luabind] Control of luabind::objects

 

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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Control of luabind::objects

Nigel Atkinson-2
In reply to this post by Josh Klint
<base href="x-msg://8/">
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
 
------------------------------------------------------------------------------
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
[hidden email]
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user