Garry's Mod Wiki

Revision Difference

debug.getregistry#560111

<function name="getregistry" parent="debug" type="libraryfunc"> <description> <deprecated></deprecated>⤶ <deprecated>⤶ This function **will** return an empty table. ⤶ If you get an error because of this see the example below for a workaround⤶ </deprecated>⤶ Returns the internal Lua registry table. The Lua registry is used by the engine and binary modules to create references to Lua values. The registry contains every global ran and used in the Lua environment. Avoid creating entries into the registry with a number as the key, as they are reserved for the reference system. <warning>Improper editing of the registry can result in unintended side effects, including crashing the game.</warning> </description> <realm>Shared and Menu</realm> <rets> <ret name="" type="table">The Lua registry</ret> </rets> </function> ⤶ <example>⤶ <description>⤶ Workaround if you used this function to get or set metatable functions. ⤶ You should switch your code to use FindMetaTable instead of using this function!⤶ </description>⤶ <code>⤶ local meta = {}⤶ function meta.__index(self, key)⤶ return FindMetaTable(key)⤶ end⤶ ⤶ debug.getregistry = function()⤶ local tbl = {}⤶ setmetatable(tbl, meta)⤶ ⤶ return tbl⤶ end⤶ </code>⤶ </example>⤶ <example> <description>Let's try to find the global table (_G) inside the registry (_R).</description> <code> local _R = debug.getregistry() MsgN(_R._LOADED._G) -- _LOADED contains most things ran in Lua, but there are all sorts of other interesting tables inside of the registry. MsgN(_R._LOADED._G == _G) </code> <output> ``` table: 0xcece1d62 true ``` </output> </example>