C functions can be tail called, too

A tail call to a C function can have the behavior of a "real" tail
call, reusing the stack frame of the caller.
This commit is contained in:
Roberto Ierusalimschy
2021-06-14 13:28:21 -03:00
parent 901d760093
commit 04e19712a5
4 changed files with 29 additions and 29 deletions

View File

@@ -205,7 +205,7 @@ do
co = coroutine.create(function () return pcall(foo) end)
local st1, st2, err = coroutine.resume(co)
assert(st1 and not st2 and err == 43)
assert(X == 43 and Y.name == "pcall")
assert(X == 43 and Y.what == "C")
-- recovering from errors in __close metamethods
local track = {}

View File

@@ -26,7 +26,7 @@ end
local function checkmessage (prog, msg, debug)
local m = doit(prog)
if debug then print(m) end
if debug then print(m, msg) end
assert(string.find(m, msg, 1, true))
end
@@ -289,7 +289,7 @@ end]], "global 'insert'")
checkmessage([[ -- tail call
return math.sin("a")
]], "'sin'")
]], "sin")
checkmessage([[collectgarbage("nooption")]], "invalid option")