自带的调试库支持设置调用钩子。
debug.sethook(hook_fun, "c")
如果第2个参数为空,则表示清除钩子。钩子中可以得到Luab函数名。
local function hook_fun()
local funcinfo = debug.getinfo(2, 'nS')
local name = funcinfo.name or 'anonymous'
local line = string.format("%d", funcinfo.linedefined or 0)
local source = funcinfo.short_src or 'C_FUNC'
local fun_name = string.format("%-30s: %s: %s", name, source, line)
skynet.error(fun_name)
end
评论 (0)