lua debug调试
debug 调试
相关函数
# debug.debug():调试模式
命令行进入调试模式,可调试函数、表达式等,输入cont退出debug模式
# debug.gethook(optional thread)
返回三个表示线程钩子设置的值: 当前钩子函数,当前钩子掩码,当前钩子计数
# debug.getinfo([thread,] f [, what]): 返回函数的表信息
f:函数、或者用一个数字f表示
数字f(f可为任意数字)表示运行在指定线程的调用栈对应层次上的函数:
0层表示当前函数(getinfo 自身);
1层表示调用 getinfo 的函数 (除非是尾调用,这种情况不计入栈);
如果f是一个比活动函数数量还大的数字, getinfo返回 nil
# debug.getmetatable(value):返回给定对象的元表,如果不存在返回nil
Returns the metatable of the given value
or nil if it does not have a metatable.
# debug.getregistry():返回注册表
Returns the registry table
# debug.getuservalue(u, n):获取第n个user值,还有boolean值,找到返回true,没找到返回false
Returns the n-th user value associated to the userdata u plus a boolean,
false if the userdata does not have that value.
# debug.sethook ([thread,] hook, mask [, count]):将一个函数作为钩子函数设入
字符串 mask 以及数字 count 决定了钩子将在何时调用,mask可选值:
'c': 每当 Lua 调用一个函数时,调用钩子
'r': 每当 Lua 从一个函数内返回时,调用钩子
'l': 每当 Lua 进入新的一行时,调用钩子
# debug.setlocal ([thread,] level, local, value):
将value赋给栈上第level层函数的第local个局部变量
如果没有那个变量,函数返回nil
如果level越界,抛出一个错误
# debug.setmetatable (value, table):将value的元表设为 table(可以是 nil),返回value
Sets the metatable for the given value to the given table
(which can be nil). Returns value.
# debug.setuservalue (udata, value, n):设置用户自定义变量的第n个值为value
Sets the given value as the n-th user value associated to the given udata.
udata must be a full userdata.
Returns udata, or fail if the userdata does not have that value
# debug.traceback ([thread,] [message [, level]])
如果有message,且不是字符串或nil,函数不做任何处理直接返回me