Re: Register an allocated object

Nigel Atkinson <[email protected]> Mon, 30 Apr 2012 15:26:08 +1000
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
Hi there!

Short answer: Yes.

However it depends on who should 'own' the object and destruct it when  
the time comes. This is how I do it, however someone may have a better  
alternative.

First the easy way, where the class instance is still 'owned' by the C+ 
+ side of things:

Assuming your example code and 'MyClass' has been bound....

globals(L)["a"] = a;	// Easy huh?

It gets tricky should you want the Lua script take responsibility of  
the instance and destruct it when finished with it.  You'll need  
something like:

Lua:
function setglobal( key, value )
	_G[key] = value
end

C++:
object setglobal = globals(L)["setglobal"];

setglobal( "a", a )[adopt(_2];	// Kinda roundabout but works.

I'm not sure if there is another way to have Lua 'adopt' the value.  I  
haven't really looked very hard though ;-)

Regards,

Nigel Atkinson


On 30/04/2012, at 1:10 PM, Thales Luis Rodrigues Sabino wrote:

> Is there a way to register an existing object within lua?
>
> For instance.
>
> MyClass *a = new MyClass();
> a->myMember = 30;
>
> Is there a way to register object a so in lua use it like
>
> print(a.myMember)?
>
> Thanks
>
> -- 
> Anyday, anytime.
>
> http://www.capimlokura.com.br
>
> Thales Luis Rodrigues Sabino
> TLuisRS
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond.  
> Discussions
> will include endpoint security, mobile security and the latest in  
> malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user