lua-users home
lua-l archive

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


> Furthermore what the heck do we need userdata for? Just attach a C buffer
> to a table so that you can conveniently associate C/Lua object pairs and
> you have userdata and tables all in one (they are almost the same anyway).

I think you are right on and I suggested this same thing recently (after
others suggested something extremely similar).

>I doubt most will find this sufficiently important as the current design
>works too.

Actually the current design doesn't work (or rather it has a very bad
side-effect).  It is often desirable to store Lua data on a per userdata
basis.  The userdata metatable is not a good fit as a location to store per
instance data because it is typically used for per "type" data rather than
per instance data.  A weak table can be used to add per instance data to the
metatable (or elsewhere), however a circular reference from this per
instance data back to the userdata will cause this per instance data to be
uncollectable (until the whole weak table is gc'd).