lua-users home
lua-l archive

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


Am 17.09.2014 um 11:10 schröbte Dirk Schippers:
Allright! (by the way, I'm using 5.2)

All the information I have read now is very interesting!
The one point that was very important for me: lightuserdata can't have
metatables.
That's strange because I created light userdata, I set a metatable to it
and my stack-debug showed that the light userdata had a metatable.
So although I had read that in the manual too, I thought the comment was
about something else.

lightuserdata can have metatables, but they can't have *individual* metatables. All lightuserdata ever created in a single Lua state will share the same metatable no matter how they were created or who created them. This can still be useful, but you have to be sure that you are the only one who uses this feature.


The concept of the user values is new to me: I have searched the lua
programming guide and haven't found it, I only saw two functions in the
reference guide (lua_setuservalue and lua_getuservalue). Is there any
more info on this?

There is not much to know: Every full userdata can have a table (or nil) as a uservalue (the default is nil). This uservalue is ignored by Lua except for the GC which traverses it (and in fact uservalue tables are sometimes used to keep other objects alive). The two API functions you already found are all you need to handle uservalues. There are two equivalent functions in Lua's debug library. Other than that Lua code can not access uservalues. There is some information about userdata environments for Lua 5.1 in the wiki[1].

Philipp


  [1]: http://lua-users.org/wiki/UserDataEnvironmentExamples