lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Thanks Carsten I will read that thread too.

Everything here has confirmed to me that even after all strong references have gone, and before the weak reference goes away, if I do reuse the full userdata in the weak table, it will be prevented from being collected. So I should be OK.

I am using smart pointers in C++ for some objects, but not for this particular object. This one can only be owned by another of its kind, another object of another class type, or a Lua full userdata. I handle all those cases individually. So far it's working beautifully, I just need to be sure nothing will fall through the cracks. :-)


On Tue, Nov 12, 2013 at 2:23 PM, Carsten Fuchs <carsten.fuchs@cafu.de> wrote:
Hi Marc,

Am 2013-11-12 20:09, schrieb Marc Lepage:

Still, reading through that thread, it *seems* to me like I should be OK, but it's not
*obvious* to me that it's OK.

I'm not entirely sure if I understood your problem, because, as someone else in this thread already mentioned, weak table entries either are collected (and removed from the weak table) or they are not (and still there).

When you bind C++ objects to Lua, using smart pointers is a great help, as they remove concerns regarding the lifetime of the bound object that is possibly used from both C++ and Lua, and possibly done with in one but still used in the other.

As you mention the problem of having only a single Lua instance for a single C++ instance, maybe this thread has some additional info for you?
http://thread.gmane.org/gmane.comp.lang.lua.general/92550

Best regards,
Carsten



--
Dipl.-Inf. Carsten Fuchs

Carsten Fuchs Software
Industriegebiet 3, c/o Rofu, 55768 Hoppstädten-Weiersbach, Germany
Internet: http://www.cafu.de | E-Mail: info@cafu.de

Cafu - the open-source game and graphics engine for multiplayer 3D action