Re: Remove Luabind ownership on C++ pointer?
neosettlers <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
Greetings,
Just to let you know my situation, I went from VS 2008, XP 64, luabind 0.9 rc to Windows 7 64, VS 2010, luabind 0.9 and the latest boost lib ...!
Before the Pangaea, I was doing this to prevent deleting and it work like a charm:
Technique "Override"
#define LuaClassNoDelete(in_class)\
template <> struct delete_s<in_class> {static void apply(void* ptr) {}};\
template <> struct destruct_only_s<in_class> {static void apply(void* ptr){}};
LuaClassNoDelete(Object)
Unfortunately, this technique does not working anymore since those struct seem to be obsolete somehow... I have no clue why. I'm sensing one of those packages I've updated too is doing Hocus Pocus stuff.
Technique "shared_ptr"
I like this method but so far, I can’t make it work. Even when using shared_ptr its still go there on GC:
cheked_delete.hpp
template<class T> inline void checked_delete(T * x)
{
// intentionally complex - simplification causes regressions
typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
(void) sizeof(type_must_be_complete);
delete x; <<<<< CRASH here since the object has previously been deleted.
}
Any help on either one of those would be extremely valuable.
Thx again,
-----Original Message-----
From: eduard mueller [mailto:[email protected]]
Sent: Thursday, September 30, 2010 7:31 AM
To: [email protected]
Subject: Re: [luabind] Remove Luabind ownership on C++ pointer?
Hold the object in a boost::shared_ptr or some other reference counting smart_ptr in Lua:
class_<Object, boost::shared_ptr<Object> >("Object")
Then the object will be kept alive as long as another shared_ptr uses the object in C++. Aka, the instance that is created in Lua will only release the shared pointer, not destruct the object itself when garbage collected.
Best regards,
Eduard
On Thu, Sep 30, 2010 at 05:16, neosettlers <[email protected]> wrote:
> Greetings,
>
>
>
> I’m wondering how to remove Luabind ownership on C++ pointers:
>
>
>
> C++
>
> module(lua)
>
> [
>
> class_<Object>("Object")
>
> .def(constructor<>())
>
> ];
>
>
>
> .lua
>
> local object = Object();
>
>
>
> …
>
>
>
> I would like Luabind NOT to delete the object C++ pointer when
> lua_gc() is called.
>
>
>
> If anyone found an elegant solution for this, I’m definitely
> interested to hear about it.
>
>
>
> Thx,
>
>
>
>
>
> ----------------------------------------------------------------------
> -------- Start uncovering the many advantages of virtual appliances
> and start using them to simplify application deployment and accelerate
> your shift to cloud computing.
> http://p.sf.net/sfu/novell-sfdev2dev
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user