Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
/glua
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yuin I am nut sure if removing element is fine. But as fare as I understand at the end of baseXPCall all arguments are anyway removed from stack.

So removing is a bit simpler then manually duplicate all arguments. For performance there is no use because remove will be sure no improvement because remove will also copy values.

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
2 changes: 2 additions & 0 deletions cmd/glua/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/__debug_bin*
/glua