debug.getlocal
Example
Gets all the local variables of the current thread and stores them in a table.
local name, value
local NIL = {} -- to represent nil variables
local locals = {}
local i = 1
while( true ) do
name, value = debug.getlocal( 1, i )
if ( name == nil ) then break end
locals[ name ] = value == nil and NIL or value
i = i + 1
end
for k, v in pairs( locals ) do
print( k, v )
end
Output:
locals table: 0x274a8dc0
value table: 0x274a8d98
NIL table: 0x274a8d98
name table: 0x274a8d98
i 5
Example
Prints the parameter names for hook.Add.
local print = print
local getlocal = debug.getlocal
local function PrintFunctionParameters( func )
local k = 2
local param = getlocal( func, 1 )
while param ~= nil do
print( param )
param = getlocal( func, k )
k = k + 1
end
end
PrintFunctionParameters( hook.Add )
Output:
event_name
name
func