Re: Register an allocated object
Thales Luis Rodrigues Sabino <[email protected]> Mon, 30 Apr 2012 11:33:17 -0300
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <CAHvrNafGOcHOEJp81-MCDG=O9auGMGO=3PVriaRmV7vq6SsEOw@mail.gmail.com> |
Thanks, that is exactly what I'm looking. For now, I'm not interested in destroy the object within lua, just let it available for modifications so I can get a console tool for my application. On Mon, Apr 30, 2012 at 2:26 AM, Nigel Atkinson <[email protected]>wrote: > 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 > > -- 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