Skip to content
Philipp Janda edited this page Mar 16, 2015 · 1 revision

debug.getuservalue

In Lua 5.1 all userdata have tables as environments. If you don't set an environment explicitly, one is inherited by the function that created the userdata (this is the global table _G for newproxy and the package table for userdata created in C modules loaded via require). Also, you can only replace the environment of a userdata with another table. In Lua 5.2 and 5.3 on the other hand, userdata start with nil as the initial uservalue. You can set the uservalue to a table and back to nil (Lua 5.3 also allows other values).

To emulate the behavior of Lua 5.3 the compatibility implementation of debug.getuservalue for Lua 5.1 returns nil whenever the userdata has an environment equal to _G or the package table, and the actual environment table otherwise.

You cannot use values other than tables (or nil) in Lua 5.1 or Lua 5.2.

See also debug.setuservalue.

Clone this wiki locally