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

debug.setuservalue

In Lua 5.2 you can set the uservalue of a userdata to nil or to a table (Lua 5.3 also allows other values, but this is not supported by the compatibility implementation). Lua 5.1 only allows tables as environments for userdata, and the usual default values for a userdata's environment is the globals table _G, or the package table. Therefore, the compatibility implementataion of debug.getuservalue translates _G and package environments to nil uservalues. The compatibility implementation of debug.setuservalue for Lua 5.1 does the same and sets the environment of a userdata to _G if you try to set the uservalue to nil.

Clone this wiki locally