lua-users home
lua-l archive

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


Tim Hill wrote:
> Light userdata is just Lua keeping a wrapper to a C pointer; you must
> allocate the memory, and free it when no longer needed (and make sure
> Lua has no stray pointers left).

In my opinion the term "light userdata" is a bit misleading, as I see
only a very limited value in using it for storing actual data.  You
cannot assign different metatables to each light userdata.  That means
it is later very hard to find out what was actually stored in it.  And I
don't see any way of making sure that Lua has no stray pointers left --
except by closing the entire Lua state.  So even when I need to do
memory handling in C I would store a pointer in a full userdata.

I mainly use light userdata as keys in the registry or similar tables to
map C objects back to Lua values and my light userdata values are never
seen by Lua (without using the debug interface) but just used by the C side.

Instead of "light userdata" maybe "typeless user pointer" would be a
clearer term.

Best regards,

David Kolf