From 658642c644bf627d78e03dadcf63ab49b904a1d9 Mon Sep 17 00:00:00 2001 From: Sebastian Waschik Date: Thu, 14 Dec 2023 13:01:08 +0100 Subject: [PATCH 1/3] Add gitignore files for executables (also for debugging) --- .gitignore | 1 + cmd/glua/.gitignore | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 cmd/glua/.gitignore diff --git a/.gitignore b/.gitignore index 485dee64..56982736 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea +/glua diff --git a/cmd/glua/.gitignore b/cmd/glua/.gitignore new file mode 100644 index 00000000..ac06c1e4 --- /dev/null +++ b/cmd/glua/.gitignore @@ -0,0 +1,2 @@ +/__debug_bin* +/glua From 93d2a5a3165689a9aa5f8b324db4878d2d68bcb1 Mon Sep 17 00:00:00 2001 From: Sebastian Waschik Date: Thu, 14 Dec 2023 16:14:37 +0100 Subject: [PATCH 2/3] Forward function arguments for xpcall --- _glua-tests/issues.lua | 19 +++++++++++++++++++ baselib.go | 11 +++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/_glua-tests/issues.lua b/_glua-tests/issues.lua index 6d6343ab..6c2a7d48 100644 --- a/_glua-tests/issues.lua +++ b/_glua-tests/issues.lua @@ -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() diff --git a/baselib.go b/baselib.go index aa2c08a9..ee5f9104 100644 --- a/baselib.go +++ b/baselib.go @@ -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) @@ -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() } } From c1aa69d062deb635d649928e1a2c732a8f8d0420 Mon Sep 17 00:00:00 2001 From: Sebastian Waschik Date: Thu, 14 Dec 2023 16:28:50 +0100 Subject: [PATCH 3/3] Mention duplicate issue --- _glua-tests/issues.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_glua-tests/issues.lua b/_glua-tests/issues.lua index 6c2a7d48..45a24ff3 100644 --- a/_glua-tests/issues.lua +++ b/_glua-tests/issues.lua @@ -491,7 +491,7 @@ function test() end test() --- issue #464 +-- issue #454, #464 function test() local result = nil local result_err = nil