运行时检查和调试实用程序。
可用函数
getconstant
Returns one constant from a Lua function or stack level by one-based index. target must be a function or stack level number. Invalid stack levels raise “Level out of range”. Non-function and non-number targets raise a type error expecting “function or number”. C closures raise “Lua function expected”. Indexes below 1 raise “Constant index starts at 1”, and indexes past the available constants raise “Constant index out of range”. Function and table constants are returned as nil. debug.getconstant is an alias.
getconstants
Returns constants from a Lua function or stack level as a table keyed by one-based constant index. target must be a function or stack level number. Invalid stack levels raise “Level out of range”. Non-function and non-number targets raise a type error expecting “function or number”. C closures raise “Lua function expected”. Nil, function, and table constants are absent from the returned table. debug.getconstants is an alias.
getinfo
Returns a metadata table for a function or stack level. target must be a function or number. Invalid target types raise “function or number expected”, invalid stack levels raise “Level out of range”, and unavailable levels raise “invalid level”. The returned table includes func, nups, source, short_src, currentline, what, linedefined, is_vararg, numparams, and name. sizep is included only for direct Lua function targets. debug.getinfo is an alias.
getproto
Returns a nested Lua function by one-based index. target must be a Lua function or stack level number. Invalid stack levels raise “Level out of range”, non-Lua functions raise “Lua function expected”, and indexes outside the nested function range raise “index out of bounds”. When active is true, returns currently live closures for that nested function instead. debug.getproto is an alias.
getprotos
Returns all nested Lua functions from a Lua function or stack level as a one-based array table. Invalid stack levels raise “Level out of range”, and non-Lua functions raise “Lua function expected”. debug.getprotos is an alias.
getreg
Returns the current Lua registry table. The function takes no arguments and returns the registry table directly.
getstack
Reads stack slot values from a Lua stack frame. level is required and must be a number; it is converted to an integer and must be between 0 and the current call stack depth minus one. Invalid levels raise “Level out of range”. The selected frame is L->ci - level, so level 0 refers to the current frame in this function. If the selected frame is a C closure, the function raises “Lua function expected”. index is optional and is only used when the second argument is a number; it is converted to an integer and must be between 1 and the frame stack size. Without a numeric index, the function returns a one-based array table containing values from frame->base[0] with frame->base[top - 1]. With a numeric index, it returns the single value at frame->base[index - 1]. Collectable values trigger luaC_threadbarrier before being pushed. debug.getstack is exposed with the debug table alias.
getupvalue
Returns one upvalue from a Lua function or stack level by one-based index. Invalid stack levels raise “Level out of range”, non-Lua functions raise “Lua Function expected”, indexes below 1 raise “Upvalue index starts at 1”, and indexes past the available upvalues raise “Upvalue index out of range”. debug.getupvalue is an alias.
getupvalues
Returns all upvalues from a Lua function or stack level as a one-based array table. Invalid stack levels raise “Level out of range”, and non-Lua functions raise “Lua function expected”. debug.getupvalues is an alias.
isvalidlevel
检查 numeric stack level 是否位于 current call stack range 内。level 必填且必须是 number,因为 function 会调用 requires a number。value 会用 integer conversion 转换。当 level < 0 或 level >= the current call stack depth 时,function 返回 false,否则返回 true。它不会检查 frame closure,也不会对 invalid numeric levels 抛出 “Level out of range”。validlevel 是 global alias,debug.isvalidlevel 和 debug.validlevel 通过 debug table aliases 暴露。
setconstant
Replaces one constant in a Lua function or stack level by one-based index. Invalid stack levels raise “Level out of range”, non-Lua functions raise “Lua function expected”, indexes below 1 raise “Constant index starts at 1”, and indexes past the available constants raise “Constant index out of range”. debug.setconstant is an alias.
setstack
Replaces one stack slot value in a Lua stack frame. level and index are required numbers. level must satisfy 0 <= level < the current call stack depth; invalid levels raise “Level out of range”. C closure frames raise “Lua function expected”. index is one-based and must refer to an existing stack slot; invalid indexes raise “Stack index out of range”. debug.setstack is an alias.
setupvalue
Replaces one upvalue in a Lua function or stack level by one-based index. Invalid stack levels raise “Level out of range”, non-Lua functions raise “Lua function expected”, indexes below 1 raise “Upvalue index starts at 1”, and indexes past the available upvalues raise “Upvalue index is out of range”. debug.setupvalue is an alias.