lua-users home
lua-l archive

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

On Wed, Feb 16, 2011 at 8:35 AM, Mike Pall <> wrote:
> There's no difference in efficiency between a 52 bit number and a
> 32 or 47 bit lightuserdata, when using them as table keys. The
> hash algorithm is the same.

glad to know :-)

>> in the FFI reference, the lightuserdata->(void *) conversion is
>> automatic; but i don't see how to do the converse.
> Well, nobody asked for it. :-)

i can haz?

>> am i missing some downside of a (void *)->lightuserdata conversion?
> Lightuserdata is generally only needed for the classic Lua/C API,
> so it would be a bit backwards to suggest its use for new stuff.

in my eyes, a lightuserdata value is a useful opaque value; just like
pointers without arithmetic.  while a number can do the same, the
implied semantics are different.

also, FFI does cast the lightuserdata back to the same pointer.  how
could i do it with a number?  i would have to store the boxed pointer
somewhere, right?  (update: i see there's a conversion between C
number and pointer, i'll play a little with the uintptr_t cast)

finally, wouldn't it be easier for the JIT optimizer to recognize that
a lightuserdata value have a lot less possible codepaths? since it can
only be passed around...