diff --git a/src/main/java/org/itsallcode/luava/LowLevelLua.java b/src/main/java/org/itsallcode/luava/LowLevelLua.java index 6f4bafb..5b6c0b2 100644 --- a/src/main/java/org/itsallcode/luava/LowLevelLua.java +++ b/src/main/java/org/itsallcode/luava/LowLevelLua.java @@ -54,13 +54,7 @@ void pcall(final int nargs, final int nresults, final int errfunc) { void pcallk(final int nargs, final int nresults, final int msgHandler, final long ctx, final lua_KFunction.Function upcallFunction) { final MemorySegment k = upcallFunction == null ? Lua.NULL() : lua_KFunction.allocate(upcallFunction, arena); - checkStatus("lua_pcallk", () -> { - final int status = Lua.lua_pcallk(state, nargs, nresults, msgHandler, ctx, k); - if (msgHandler != 0) { - this.stack.pop(1); - } - return status; - }); + checkStatus("lua_pcallk", () -> Lua.lua_pcallk(state, nargs, nresults, msgHandler, ctx, k)); } void loadString(final String chunk) { @@ -70,8 +64,6 @@ void loadString(final String chunk) { void checkStatus(final String functionName, final Supplier nativeFunctionCall) { final int status = nativeFunctionCall.get(); if (status != Lua.LUA_OK()) { - System.out.println(stack.printStack()); - System.out.println("Getting error message.."); final String message = stack.toString(-1); stack.pop(1); throw new FunctionCallException(functionName, status, message); diff --git a/src/main/java/org/itsallcode/luava/LuaStack.java b/src/main/java/org/itsallcode/luava/LuaStack.java index 0925f93..58a4cdf 100644 --- a/src/main/java/org/itsallcode/luava/LuaStack.java +++ b/src/main/java/org/itsallcode/luava/LuaStack.java @@ -68,14 +68,11 @@ void pop(final int n) { if (n > size) { throw new IllegalStateException("Trying to pop " + n + " elements but stack has size " + size); } - System.out.println("Popping " + n + " elements from stack with size " + size); setTop(-n - 1); } void setTop(final int n) { - System.out.println(this.printStack()); Lua.lua_settop(state, n); - System.out.println(this.printStack()); } boolean toBoolean(final int idx) { diff --git a/src/test/java/org/itsallcode/luava/LuaInterpreterTest.java b/src/test/java/org/itsallcode/luava/LuaInterpreterTest.java index c05616c..ec11a13 100644 --- a/src/test/java/org/itsallcode/luava/LuaInterpreterTest.java +++ b/src/test/java/org/itsallcode/luava/LuaInterpreterTest.java @@ -114,26 +114,18 @@ void getCallGlobalFunctionFails() { @Test void getCallGlobalFunctionWithMessageHandler() { - System.out.println(lua.stack().printStack()); lua.exec("function increment(x) error('failure') end"); - System.out.println(lua.stack().printStack()); assertStackSize(0); final LuaFunction function = lua.getGlobalFunction("increment", (final LuaInterpreter l) -> { - System.out.println(l.stack().printStack()); final String msg = l.stack().toString(-1); - // l.stack().pop(1); - System.out.println("Updated error: " + msg); + l.stack().pop(1); l.stack().pushString("Updated error: " + msg); - System.out.println(l.stack().printStack()); return 1; }); - System.out.println("before add arg" + lua.stack().printStack()); function.addArgInteger(42); - System.out.println("after add arg" + lua.stack().printStack()); final FunctionCallException exception = assertThrows(FunctionCallException.class, () -> function.call(1, 1)); - System.out.println("after call" + lua.stack().printStack()); assertThat(exception.getMessage(), equalTo( - "Function 'lua_pcallk' failed with error 2: [string \"function increment(x) error('failure') end\"]:1: failure")); + "Function 'lua_pcallk' failed with error 2: Updated error: [string \"function increment(x) error('failure') end\"]:1: failure")); assertStackSize(0); }