Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我们知道 Lua 有一个库函数debug.sethook,当任何函数返回时, 都会通过事件“return”或“tail return”调用钩子函数,但 LuaJIT 不会钩子“tail return”。 有什么方法可以关闭LuaJIT的特化,让它钩“尾返回”?
debug.sethook
它是 LuaJIT 实现的一个“特性”,因此您不太可能将其关闭。正如 LuaJIT 的作者所建议的,您可以在挂钩中跟踪堆栈深度,但您将无法专门跟踪尾调用返回。
注意 Lua 也从尾返回转移到尾调用:“对于调用事件,事件可以是 LUA_HOOKCALL,正常值,或 LUA_HOOKTAILCALL,对于尾调用;在这种情况下,将没有相应的返回事件。”