标签搜索

Lua使用调试库hook函数调用

anker
2021-06-27 / 6 评论 / 429 阅读 / 正在检测是否收录...

自带的调试库支持设置调用钩子。

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

评论 (6)

取消
  1. 头像
    penspsdumt
    Windows 10 · Google Chrome
    @

    博主真是太厉害了!!!

    回复
  2. 头像
    ftopijwdkl
    Windows 10 · Google Chrome
    @

    不错不错,我喜欢看

    回复
  3. 头像
    rjsfcjdejx
    Windows 10 · Google Chrome
    @

    看的我热血沸腾啊https://www.237fa.com/

    回复
  4. 头像
    dxksdkfgrk
    Windows 10 · Google Chrome
    @

    想想你的文章写的特别好https://www.ea55.com/

    回复
  5. 头像
    eqpexfnhbk
    Windows 10 · Google Chrome
    @

    想想你的文章写的特别好www.jiwenlaw.com

    回复
  6. 头像
    xaijrsnbpi
    Windows 10 · Google Chrome
    @

    兄弟写的非常好 https://www.cscnn.com/

    回复