I am trying to call a simple Lua function from Java using LuaJava. calc.lua:
function foo(n) return n*2 end
That's all there is in calc.lua and subsequent command line calls.
Here is a call that always has an error:
L.getGlobal("foo"); L.pushNumber(8.0); int retCode=L.pcall(1, 1,-2); // retCode value is always 5 pcall(numArgs,numRet,errHandler) String s = L.toString(-1); // s= "Error in Error Handling Code"
I also tried L.remove (-2); L.insert (-2);
Not sure why he gives any kind of error at all or what the error is. Maybe I'm setting up an error handler incorrectly? So this is not a challenge? After loading, I tried from the console and was able to run print (foo (5)), returning 10 as expected.
UPDATE: Looks like I need to provide an error handler on the stack. What is the signature for such an error handler and how can I put it on a point on the stack. Thanks
source share