diff --git a/_glua-tests/issues.lua b/_glua-tests/issues.lua index 6d6343ab..b83e6bcb 100644 --- a/_glua-tests/issues.lua +++ b/_glua-tests/issues.lua @@ -490,3 +490,14 @@ function test() assert(b == nil) end test() + +-- xpcall with a callable table as the first argument +function test() + local f = setmetatable({}, {__call = function() return 42 end}) + local ok, v = xpcall(f, function(e) return e end) + assert(ok == true and v == 42) + local g = setmetatable({}, {__call = function() error("boom", 0) end}) + local ok, v = xpcall(g, function(e) return "handled: " .. e end) + assert(ok == false and v == "handled: boom") +end +test() diff --git a/baselib.go b/baselib.go index aa2c08a9..3074dd23 100644 --- a/baselib.go +++ b/baselib.go @@ -458,7 +458,7 @@ func baseUnpack(L *LState) int { } func baseXPCall(L *LState) int { - fn := L.CheckFunction(1) + fn := L.CheckAny(1) errfunc := L.CheckFunction(2) top := L.GetTop()