I'm trying to call:
LuaState.pcall(num_args,num_returns, error_handler_index).
I need to know how to install an error handler for this function. Actually, I think it would be nice for someone to show how to call the Lua function and get a numerical result using LuaJava. This can save a lot of time and questions. I am looking for but not finding a signature for the error function, and how to put it at the right point on the LuaState stack. All Java-> Lua examples either print a value without returning, or set values ββfor a Java object passed using Lua. I would like to see how to call the Lua function directly and return the result.
Update: one solution is to pass the error handler using LuaState.pcall (1,1,0), passing zero for the error handler:
String errorStr; L.getGlobal("foo"); L.pushNumber(8.0); int retCode=L.pcall(1,1,0); if (retCode!=0){ errorStr = L.toString(-1); } double finalResult = L.toNumber(-1);
where calc.lua is loaded:
function foo(n) return n*2 end
Now is there a way to install an error handler? Thanks
source share