Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

debug.getuservalue

Philipp Janda edited this page Mar 11, 2015 · 2 revisions

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 on the other hand, userdata start with nil as the initial uservalue. You can set the uservalue to a table and back to nil.

To emulate the behavior of Lua 5.2 the compatibility implementation of debug.getuservalue returns nil whenever the userdata has an environment equal to _G or the package table, and the actual environment table otherwise. See also lua_getuservalue and debug.setuservalue.

Clone this wiki locally