Skip to content

Commit

Permalink
Forward function arguments for xpcall
Browse files Browse the repository at this point in the history
  • Loading branch information
waschik committed Dec 14, 2023
1 parent 658642c commit 93d2a5a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
19 changes: 19 additions & 0 deletions _glua-tests/issues.lua
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,22 @@ function test()
assert(b == nil)
end
test()

-- issue #464
function test()
local result = nil
local result_err = nil
local callback = function(arg)
result = arg
end
local errfunc = function(err)
result_err = err
end
xpcall(callback, errfunc, 9)

-- check first for error because otherwise also wrong result assert
-- would be triggered
assert(result_err == nil)
assert(result == 9)
end
test()
11 changes: 5 additions & 6 deletions baselib.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,11 @@ func baseUnpack(L *LState) int {
}

func baseXPCall(L *LState) int {
fn := L.CheckFunction(1)
errfunc := L.CheckFunction(2)

L.Remove(2)
top := L.GetTop()
L.Push(fn)
if err := L.PCall(0, MultRet, errfunc); err != nil {
nargs := top - 1
if err := L.PCall(nargs, MultRet, errfunc); err != nil {
L.Push(LFalse)
if aerr, ok := err.(*ApiError); ok {
L.Push(aerr.Object)
Expand All @@ -472,8 +471,8 @@ func baseXPCall(L *LState) int {
}
return 2
} else {
L.Insert(LTrue, top+1)
return L.GetTop() - top
L.Insert(LTrue, 1)
return L.GetTop()
}
}

Expand Down

0 comments on commit 93d2a5a

Please sign in to comment.