I am trying to call:
LuaState.pcall(num_args,num_returns, error_handler_index).
I need to know how to set the error handler for this function. In fact, I think it would be nice it someone showed how to invoke a Lua function and get a numerical result back using LuaJava. This might save a lot of time and questions. I am looking but not finding the signature for the error function, and how to place it at the right point on the LuaState stack. All the Java->Lua examples are either printing a value with no return or they are setting values on a Java object passed in using Lua. I would like to see how to call a Lua function directly and get the result back.
Update: one solution is to pass no error handler using LuaState.pcall(1,1,0) by 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 has been loaded:
function foo(n)
return n*2
end
Now is there a way to set an error handler as well? Thanks