I am trying to call a simple Lua function from Java using LuaJava. calc.lua:
function foo(n) return n*2 end
Thats all there is in calc.lua and subsequent calls from command line work.
Here is the call that always has 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 have also tried
L.remove(-2);
L.insert(-2);
Not sure why its giving any error at all or what the error is. Maybe I'm not setting up error handler correctly? So it does not make the call? After load I tried from console and can run print(foo(5)) getting back 10 as expected.
UPDATE: It looks like I need to provide an error handler on the stack. What is the signature for such an error handler and how would I place it at a point on the stack. Thanks