org.luaj.vm2
Class Globals

java.lang.Object
  extended by org.luaj.vm2.Varargs
      extended by org.luaj.vm2.LuaValue
          extended by org.luaj.vm2.LuaTable
              extended by org.luaj.vm2.Globals

public class Globals
extends LuaTable

Global environment used by luaj.

Contains the global variables referenced by lua libraries such as stdin and stdout, the resrouce finder which is used tolook up files in a platform independent way, the installed lua compiler, the math library in use, debugging calls stack, and so on.

In a multithreded server environment, each server thread should create one Globals instance, which will be logically distance and not interfere with each other, but share certain static immutable resources such as class data and string data.

Typically, this is constructed indirectly by a call to JsePlatform.standardGlobasl() or JmePlatform.standardGlobals(), and then used to load lua scripts for execution as in the following example.

 Globals _G = JsePlatform.standardGlobals();
 _G.compiler.load( new ByteArrayInputStream("print 'hello'".getBytes()), "main.lua", _G ).call();
  

See Also:
LoadState.LuaCompiler, JsePlatform, JmePlatform, LuaValue

Field Summary
 BaseLib baselib
          The BaseLib instance loaded into this Globals
 LoadState.LuaCompiler compiler
          The installed compiler.
 DebugLib debuglib
          The DebugLib instance loaded into this Globals, or null if debugging is not enabled
 LuaValue errorfunc
          The current error handler for this Globals
 ResourceFinder FINDER
          The installed ResourceFinder for looking files by name.
 PackageLib package_
          The PackageLib instance loaded into this Globals
 LuaThread running
          The currently running thread.
 java.io.PrintStream STDERR
          The current default error stream.
 java.io.InputStream STDIN
          The current default input stream.
 java.io.PrintStream STDOUT
          The current default output stream.
 
Fields inherited from class org.luaj.vm2.LuaTable
array, hash, hashEntries, m_metatable
 
Fields inherited from class org.luaj.vm2.LuaValue
ADD, CALL, CONCAT, DIV, EMPTYSTRING, ENV, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO
 
Constructor Summary
Globals()
           
 
Method Summary
 Globals checkglobals()
          Check that this object is a Globals object, and return it, otherwise throw an error.
 LuaValue loadFile(java.lang.String filename)
          Convenience function for loading a file.
 LuaValue loadString(java.lang.String script, java.lang.String chunkname)
          Convenience function to load a string value as a script.
 Varargs yield(Varargs args)
          Function which yields the current thread.
 
Methods inherited from class org.luaj.vm2.LuaTable
arrayget, checktable, concat, defaultEntry, entry, eq_b, eq, get, get, getArrayLength, getHashLength, getmetatable, hashget, hashmod, hashpow2, hashset, hashSlot, inext, insert, isLargeKey, istable, keyCount, keys, len, length, next, opttable, presize, presize, rawget, rawget, rawlen, rawset, rawset, remove, set, set, setmetatable, sort, toLuaValue, type, typename, unpack, unpack, unpack, useWeakKeys, useWeakValues, wrap
 
Methods inherited from class org.luaj.vm2.LuaValue
add, add, add, and, arg, arg1, argerror, argerror, aritherror, aritherror, arithmt, arithmtwith, assert_, buffer, call, call, call, call, call, callmt, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checkmetatag, checknotnil, checknumber, checknumber, checkstring, checkthread, checkuserdata, checkuserdata, compareerror, compareerror, comparemt, concat, concat, concatmt, concatTo, concatTo, concatTo, div, div, div, divInto, eqmtcall, equals, error, get, gettable, gt_b, gt_b, gt_b, gt, gt, gt, gteq_b, gteq_b, gteq_b, gteq, gteq, gteq, illegal, initupvalue1, invoke, invoke, invoke, invoke, invoke, invoke, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, isboolean, isclosure, isfunction, isint, isinttype, islong, isnil, isnumber, isstring, isthread, isuserdata, isuserdata, isvalidkey, lenerror, listOf, listOf, load, lt_b, lt_b, lt_b, lt, lt, lt, lteq_b, lteq_b, lteq_b, lteq, lteq, lteq, metatableOf, metatag, method, method, method, method, method, method, mod, mod, mod, modFrom, mul, mul, mul, narg, neg, neq_b, neq, not, onInvoke, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, optthread, optuserdata, optuserdata, optvalue, or, pow, pow, pow, powWith, powWith, raweq, raweq, raweq, raweq, raweq, rawget, rawset, rawset, rawset, rawset, rawset, rawsetlist, set, set, set, set, set, settable, strcmp, strcmp, strongvalue, strvalue, sub, sub, sub, subargs, subFrom, subFrom, tableOf, tableOf, tableOf, tableOf, tableOf, tableOf, tailcallOf, testfor_b, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, tonumber, toshort, tostring, toString, touserdata, touserdata, typerror, unimplemented, userdataOf, userdataOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, varargsOf, varargsOf, varargsOf, varargsOf, varargsOf, varargsOf
 
Methods inherited from class org.luaj.vm2.Varargs
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STDIN

public java.io.InputStream STDIN
The current default input stream.


STDOUT

public java.io.PrintStream STDOUT
The current default output stream.


STDERR

public java.io.PrintStream STDERR
The current default error stream.


FINDER

public ResourceFinder FINDER
The installed ResourceFinder for looking files by name.


compiler

public LoadState.LuaCompiler compiler
The installed compiler.


running

public LuaThread running
The currently running thread. Should not be changed by non-library code.


baselib

public BaseLib baselib
The BaseLib instance loaded into this Globals


package_

public PackageLib package_
The PackageLib instance loaded into this Globals


debuglib

public DebugLib debuglib
The DebugLib instance loaded into this Globals, or null if debugging is not enabled


errorfunc

public LuaValue errorfunc
The current error handler for this Globals

Constructor Detail

Globals

public Globals()
Method Detail

checkglobals

public Globals checkglobals()
Check that this object is a Globals object, and return it, otherwise throw an error.

Overrides:
checkglobals in class LuaValue
Returns:
this if if an instance fof

loadFile

public LuaValue loadFile(java.lang.String filename)
Convenience function for loading a file.

Parameters:
filename - Name of the file to load.
Returns:
LuaValue that can be call()'ed or invoke()'ed.
Throws:
LuaError - if the file could not be loaded.

loadString

public LuaValue loadString(java.lang.String script,
                           java.lang.String chunkname)
Convenience function to load a string value as a script.

Parameters:
script - Contents of a lua script, such as "print 'hello, world.'"
chunkname - Name that will be used within the chunk as the source.
Returns:
LuaValue that may be executed via .call(), .invoke(), or .method() calls.
Throws:
LuaError - if the script could not be compiled.

yield

public Varargs yield(Varargs args)
Function which yields the current thread.

Parameters:
args - Arguments to supply as return values in the resume function of the resuming thread.
Returns:
Values supplied as arguments to the resume() call that reactivates this thread.


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