public class JsePlatform extends Object
JsePlatform class is a convenience class to standardize
how globals tables are initialized for the JSE platform.
It is used to allocate either a set of standard globals using
standardGlobals() or debug globals using debugGlobals()
A simple example of initializing globals and using them from Java is:
Globals globals = JsePlatform.standardGlobals();
globals.get("print").call(LuaValue.valueOf("hello, world"));
Once globals are created, a simple way to load and run a script is:
globals.load( new FileInputStream("main.lua"), "main.lua" ).call();
although require could also be used:
globals.get("require").call(LuaValue.valueOf("main"));
For this to succeed, the file "main.lua" must be in the current directory or a resource.
See JseBaseLib for details on finding scripts using ResourceFinder.
The standard globals will contain all standard libraries plus luajava:
GlobalsJseBaseLibPackageLibBit32LibTableLibStringLibCoroutineLibJseMathLibJseIoLibJseOsLibLuajavaLibLuaC compiler is installed so lua files may be loaded in their source form.
The debug globals are simply the standard globals plus the debug library DebugLib.
The class ensures that initialization is done in the correct order.
Globals,
org.luaj.vm2.lib.jme.JmePlatform| 构造器和说明 |
|---|
JsePlatform() |
| 限定符和类型 | 方法和说明 |
|---|---|
static Globals |
debugGlobals()
Create standard globals including the
DebugLib library. |
static Varargs |
luaMain(LuaValue mainChunk,
String[] args)
Simple wrapper for invoking a lua function with command line arguments.
|
static Globals |
standardGlobals()
Create a standard set of globals for JSE including all the libraries.
|
public static Globals standardGlobals()
debugGlobals(),
JsePlatform,
org.luaj.vm2.lib.jme.JmePlatformpublic static Globals debugGlobals()
DebugLib library.standardGlobals(),
JsePlatform,
org.luaj.vm2.lib.jme.JmePlatform,
DebugLibCopyright © 2020. All rights reserved.