Lua 吊钩机构的性能
我有一个奇怪的行为与钩机制,我不明白,我喜欢一些帮助 这是一个非常简单的例子,因为我正在学习语言: foo函数:Lua 吊钩机构的性能,lua,hook,Lua,Hook,我有一个奇怪的行为与钩机制,我不明白,我喜欢一些帮助 这是一个非常简单的例子,因为我正在学习语言: foo函数: function foo () print ("i'm in foo") end 一些数据功能: function data () print ("This is the data : ") end 然后,我进行挂钩设置: debug.sethook(data , "c") 有线的事情是,当我调用foo时,这是我得到的输出: This is the data : This
function foo () print ("i'm in foo") end
一些数据功能:
function data () print ("This is the data : ") end
然后,我进行挂钩设置:
debug.sethook(data , "c")
有线的事情是,当我调用foo时,这是我得到的输出:
This is the data :
This is the data :
This is the data :
This is the data :
i'm in foo
这是整个程序,所以没有隐藏的东西可能导致它
我想知道为什么钩子被调用了4次而不是一次?在下面的程序中,我只看到3条消息,而不是4条。解释是,每次调用设置后都会调用调用钩子:
foo
,print
,tostring
,由print
调用
function foo () print ("i'm in foo") end
function data () print ("This is the data : ",debug.traceback()) end
debug.sethook(data , "c")
foo()