org.luaj.vm2.lib.jse
Class JseBaseLib

java.lang.Object
  extended by org.luaj.vm2.lib.BaseLib
      extended by org.luaj.vm2.lib.jse.JseBaseLib

public class JseBaseLib
extends org.luaj.vm2.lib.BaseLib

Subclass of BaseLib and LibFunction which implements the lua basic library functions and provides a directory based ResourceFinder as the #finder.

Since JME has no file system by default, BaseLib implements ResourceFinder using Class.getResource(String). The JseBaseLib implements finder by scanning the current directory first, then falling back to Class.getResource(String) if that fails. Otherwise, the behavior is the same as that of BaseLib.

Typically, this library is included as part of a call to JsePlatform.standardGlobals()

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

For special cases where the smallest possible footprint is desired, a minimal set of libraries could be loaded directly via Globals#load(LuaValue) using code such as:

 Globals globals = new Globals();
 globals.load(new JseBaseLib());
 globals.get("print").call(LuaValue.valueOf("hello, world"));
  

However, other libraries such as PackageLib are not loaded in this case.

This is a direct port of the corresponding library in C.

See Also:
Globals, BaseLib, ResourceFinder, Globals.finder}, LibFunction, JsePlatform, org.luaj.vm2.lib.jme.JmePlatform, Lua 5.2 Base Lib Reference

Constructor Summary
JseBaseLib()
           
 
Method Summary
 LuaValue call(LuaValue modname, LuaValue env)
          Extend the library loading to set the default value for Globals.STDIN
 java.io.InputStream findResource(java.lang.String filename)
          Try to open a file in the current working directory, or fall back to base opener if not found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JseBaseLib

public JseBaseLib()
Method Detail

call

public LuaValue call(LuaValue modname,
                     LuaValue env)
Extend the library loading to set the default value for Globals.STDIN


findResource

public java.io.InputStream findResource(java.lang.String filename)
Try to open a file in the current working directory, or fall back to base opener if not found. This implementation attempts to open the file using new File(filename). It falls back to the base implementation that looks it up as a resource in the class path if not found as a plain file.

Parameters:
filename -
Returns:
InputStream, or null if not found.
See Also:
org.luaj.vm2.lib.BaseLib, org.luaj.vm2.lib.ResourceFinder


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