lua-users home
lua-l archive

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


On 04/20/2014 10:38 PM, Eike Decker wrote:


Am 20.04.2014 13:51 schrieb "Peng Zhicheng" <pengzhicheng1986@gmail.com <mailto:pengzhicheng1986@gmail.com>>:
>.

I needed four years to learn that userdata values can have individual environment tables. So you can let the metadata table be shared while using individual environment tables, storing object related data. This helps organizing structures a lot...
I hope you know about this feature. If not, it might be useful for you.

Personally, I don't know what light userdata types are good for anymore.

Eike

yes, I knew the `uservalue' concept (formerly called `fenv' in Lua 5.1, same name but different things
for function/thread and userdata). but I'm not using it this time.

what I'm dealing with are some opaque values passed across the Lua side intactly, Lua code can't do
any operation on these values: if there were only one single (runtime) type of such values, then
lightuserdata is absolutely OK for this use. but now I have more then one types.

I could have used either metatable or uservalue,  since I need only to associate some type information
with the value itself. there were no big differences in this use case: as for Lua 5.2, uservalues are
restricted to tables. But I chose metatable than userdata simply because I use luaL_testudata in my code.