lua-users home
lua-l archive

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


On Wed, Mar 07, 2007 at 05:20:20PM -0300, Roberto Ierusalimschy wrote:
> > Do I have this right?
> 
> Almost. Light userdata are values, too.

Ouch, thank you!

On closer reading, it is in the refman, 2.2:

  Tables, functions, threads, and (full) userdata values are objects:
  variables do not actually contain these values, only references to
  them. Assignment, parameter passing, and function returns always
  manipulate references to such values; these operations do not imply
  any kind of copy.

I'm sure there is no end to stuff that could be jammed into the ref man,
but I think it might be worth adding to section 2.2 a note that the
distinction between value and object is significant in weak tables/
garbage collection.

Interestingly, this means that it is actually observable from lua code
whether a userdata is light or full, because they behave differently
(though the test is destructive :0). I thought that the difference could
only be seen from C code, and that they behaved the same, other than
that light couldn't have per-instance metadata.

I don't have my PILv2 handy, but I think in the section on weak tables
(where it discusses how strings are kindof like objects but that that is
an internal optimization, and they are values for the point of view of a
user) that lightuserdata isn't mentioned as one of the "value" lua
types.

Also, in section 2.10.2 "value" means two things, so a note about the
importance of the distinction between objects and "values" might be
useful. Its a bit confusing, because weak-valued table pairs are not
removed if the value is the only reference to a value. :-)


Thanks,
Sam