org.luaj.vm2.lib.jse
Class JsePlatform

java.lang.Object
  extended by org.luaj.vm2.lib.jse.JsePlatform

public class JsePlatform
extends java.lang.Object

The 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:

 LuaValue _G = JsePlatform.standardGlobals();
 _G.get("print").call(LuaValue.valueOf("hello, world"));
  

Once globals are created, a simple way to load and run a script is:

 LoadState.load( new FileInputStream("main.lua"), "main.lua", _G ).call();
  

although require could also be used:

 _G.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:

In addition, the LuaC 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, and that linkage is made to LuaThread.setGlobals(LuaValue).

See Also:
JmePlatform

Constructor Summary
JsePlatform()
           
 
Method Summary
static LuaTable debugGlobals()
          Create standard globals including the debug library.
static LuaTable standardGlobals()
          Create a standard set of globals for JSE including all the libraries.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsePlatform

public JsePlatform()
Method Detail

standardGlobals

public static LuaTable standardGlobals()
Create a standard set of globals for JSE including all the libraries.

Returns:
Table of globals initialized with the standard JSE libraries
See Also:
debugGlobals(), JsePlatform, JmePlatform

debugGlobals

public static LuaTable debugGlobals()
Create standard globals including the debug library.

Returns:
Table of globals initialized with the standard JSE and debug libraries
See Also:
standardGlobals(), JsePlatform, JmePlatform, DebugLib


Copyright © 2007-2008 Luaj.org. All Rights Reserved.