Lua之sethook学习

本文介绍了Lua中的debug.sethook函数,用于设置调试钩子。debug.sethook允许你在函数调用、函数返回或每行代码执行前触发指定的函数,并通过mask参数控制触发条件。当hook被调用时,它会接收到事件描述字符串以及可能的行号信息。通过结合debug.getinfo,可以获取运行时的函数详情。文章还给出了一个示例,展示如何利用sethook来定位错误发生的代码行。
摘要由CSDN通过智能技术生成

debug.sethook ([thread,] hook, mask [, count])

Sets the given function as a hook.The string mask and the number count describewhen the hook will be called.The string mask may have the following characters,with the given meaning:

  • "c": The hook is called every time Lua calls a function;  当函数被调用的时候触发,且在函数获得参数之前调用;
  • "r": The hook is called every time Lua returns from a function; 当函数返回之前触发hook,且不能在此时获得函数的返回值;
  • "l": The hook is called every time Lua enters a new line of code. 当执行到某一行代码之前触发hook

With a count different from zero,the hook is called after every count instructions.

When called without arguments,debug.sethook turns off the hook.

When the hook is called, its first parameter is a stringdescribing the event that has trigger

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值