Files
luaj/examples/jse/SampleJseMain.java
2013-11-22 17:13:55 +00:00

32 lines
854 B
Java

import org.luaj.vm2.Globals;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.lib.jse.JsePlatform;
/** Simple program showing the minimal Java program to launch a script.
*
* <p> In typical usage, a Globals object must be created to hold global state,
* and it can be used to compile and load lua files into executable LuaValue
* instances.
*
* @see Globals
* @see LuaValue
*/
public class SampleJseMain {
public static void main(String[] args) throws Exception {
String script = "examples/lua/hello.lua";
// create an environment to run in
Globals globals = JsePlatform.standardGlobals();
// Use the convenience function on Globals to load a chunk.
LuaValue chunk = globals.loadfile(script);
// Use any of the "call()" or "invoke()" functions directly on the chunk.
chunk.call( LuaValue.valueOf(script) );
}
}