In lua, the top-level scope is an anonymous function with variable arguments. These are accessed using ... In your example, you don't need the function named something, the chunk itself can be used as an unnamed function.
Is it possible to set variables in Lua from Java? For instance:
String script = "print(a)";
InputStream is = new ByteArrayInputStream(script.getBytes());
Globals globals = JsePlatform.standardGlobals();
Prototype p = globals.compilePrototype(is, "script");
LuaClosure f = new LuaClosure(p,globals);
// set variable a here?
f.invoke();
I tried f.set("a","test");
However, got the error:
org.luaj.vm2.LuaError: index expected, got function
Thanks,
David.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hey guys
I have kind of a newbie question here, but I couldn't find an answer anywhere so far. I posted it on Stackoverflow: http://stackoverflow.com/questions/14504300/passing-arguments-to-a-lua-function-with-luaj
It would be awesome to get some help here!
Thanks!
In lua, the top-level scope is an anonymous function with variable arguments. These are accessed using ... In your example, you don't need the function named something, the chunk itself can be used as an unnamed function.
For example, this code in luaj-3.0-beta1
Produced this result for me:
You can pass in any number of arguments this way.
Is it possible to set variables in Lua from Java? For instance:
String script = "print(a)";
InputStream is = new ByteArrayInputStream(script.getBytes());
Globals globals = JsePlatform.standardGlobals();
Prototype p = globals.compilePrototype(is, "script");
LuaClosure f = new LuaClosure(p,globals);
// set variable a here?
f.invoke();
I tried f.set("a","test");
However, got the error:
org.luaj.vm2.LuaError: index expected, got function
Thanks,
David.