Managed to get this working by removing some of the error handling code as noted in the luajava examples that seemed to interfere and swapping call to L.LLloadString
to L.LdoString(src);
and L.pcall
to L.call
.
public String runLuaHello(String src, String arg) throws LuaException {
//init
L = LuaStateFactory.newLuaState();
L.openLibs();
L.setTop(0);
//load the lua source code
int ok = L.LdoString(src);
if (ok == 0) {
//don't quite understand why it's getGlobal? but here you set the method name
L.getGlobal("hello");
//send the arg to lua
L.pushString(arg);
//this specifies 1 arg and 1 result
L.call(1, 1);
//get the result
String result = L.toString(-1);
//pop the result off the stack
L.pop(1);
return result;
}
throw new LuaException(errorReason(ok) + ": " + L.toString(-1));
}