A function in Lua (and most programming languages) is a single unit of execution, and does not affect the caller except for the returned values. Using a tail call is the only way of directly jumping to another function.
It is also possible to use the error mechanism to jump outside a function:
local signal = {}
function a()
error(signal)
end
local status, err = pcall(a)
if err == signal then
--"returned" from the specific point inside a function
end
I would not recommend this however, since it defeats the purpose of functions as independent entities.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…