actboy168 / lua-debug

Lua Debug Adapter for Visual Studio Code
MIT License
437 stars 95 forks source link

关于尾调用问题 #114

Closed mkckr0 closed 3 years ago

mkckr0 commented 3 years ago
local f1, f2, f3

f1 = function ()
    return f2()
end

f2 = function ()
    return f3()
end

f3 = function ()
    return 1
end

local function on_hook(event, line)
    local info = debug.getinfo(2, "nfS")
    print(info.name, event)
end

debug.sethook(on_hook, "cr")

f1()

debug.sethook()

插件的结果

sethook return
f1  call
f2  call
f3  call
f3  return
f2  return
f1  return
sethook call

直接用Lua54的结果

sethook return
f1      call
nil     tail call
nil     tail call
nil     return
sethook call

请问插件使用了什么方法关闭了尾调用优化?

actboy168 commented 3 years ago

https://github.com/actboy168/lua-debug/blob/a056e740b15edd81cea9ddd33b17a202403defd3/3rd/lua/lua54/lparser.c#L1814-L1819

mkckr0 commented 3 years ago

多谢!