lua-users home
lua-l archive

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


dormando wrote:
dormando wrote:
Hey,

I've been fighting with a nasty bug in the C API for a soon-to-be-GPL'ed project o' mine... for several hours, and I'm wholly stuck. The problem is pretty easy to illustrate:

As usual, a few hours later I'll make a dick of myself.

The issue is that I'm using a lightuserdata instead of a full userdata.

Setting up a **pointer and shoveling that inside the full userdata has completely ameliorated the weirdness.

I do have one real question however; I have the 2nd ed PiL book, the 5.1 ref man, and the online manual. All of which devote a single sentence saying that lightuserdata does not have a metatable. However, this appears to not be the case :P It has a single metatable for all types (like numbers, strings, etc). So when I set another metatable for the second lightuserdata object, it overwrote it globally.

Am I reading the docs wrong and this is intended behavior?

Thanks,
-Dormando


You made me curious so I checked the manual. Here's the entry for lua_pushlightuserdata (*emphasis* mine):

--------------------

void lua_pushlightuserdata (lua_State *L, void *p);

Pushes a light userdata onto the stack.

Userdata represent C values in Lua. A light userdata represents a pointer. It is a value (like a number): you do not create it, *it has no individual metatable*, and it is not collected (as it was never created). A light userdata is equal to "any" light userdata with the same C address.

--------------------

So this is in fact documented, though I must admit I wasn't aware of it either.

 - Peter Odding