lua-users home
lua-l archive

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


Am 22.05.2014 08:11 schröbte Coda Highland:
On Wed, May 21, 2014 at 8:53 PM, Philipp Janda <siffiejoe@gmx.net> wrote:
Am 22.05.2014 04:57 schröbte Coda Highland:
At this point, my personal recommendation would be to use tables
containing a lightuserdata, and maintain a C-side refcount independent
of the Lua refcount.

This sounds like manual resource management to me, but I can't imagine a
situation where lightuserdata would solve an object lifetime problem anyway,
so I might be missing something here.

It's more that full userdata becomes pointless if you're not using it
to manage the object lifetime anymore, so switching to lightuserdata
lets you do equality comparisons on return values from C, including
mapping the lightuserdata back to the Lua object; you can't do this
with full userdata without attaching another key to it.

So you really were talking about manual resource management ...
Full userdata also provides type safety. There was a patch not long ago that added type tags to lightuserdata, but unless you also manage lifetime of the C object somehow, you can still get a lightuserdata with an incorrect type (freed and allocated again at the same address, the lightuserdata in Lua still refers to the old object).


/s/ Adam


Philipp