Package com.prineside.luaj.lib.jse
Class JseOsLib
- All Implemented Interfaces:
com.esotericsoftware.kryo.KryoSerializable
Subclass of
LibFunction
which implements the standard lua os
library.
This contains more complete implementations of the following functions using features that are specific to JSE:
execute()
remove()
rename()
tmpname()
Because the nature of the os
library is to encapsulate
os-specific features, the behavior of these functions varies considerably
from their counterparts in the C platform.
Typically, this library is included as part of a call to org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()
Globals globals = JsePlatform.standardGlobals();
System.out.println( globals.get("os").get("time").call() );
For special cases where the smallest possible footprint is desired,
a minimal set of libraries could be loaded
directly via LuaValue.load(LuaValue)
using code such as:
Globals globals = new Globals();
globals.load(new JseBaseLib());
globals.load(new PackageLib());
globals.load(new JseOsLib());
System.out.println( globals.get("os").get("time").call() );
However, other libraries such as MathLib are not loaded in this case.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.prineside.luaj.lib.OsLib
OsLib.OsLibFunc
Nested classes/interfaces inherited from class com.prineside.luaj.LuaValue
LuaValue.NillableSerializer, LuaValue.None
Nested classes/interfaces inherited from class com.prineside.luaj.Varargs
Varargs.ArrayVarargs
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
return code indicating the execute() threw an unknown exceptionstatic final int
return code indicating the execute() was interruptedstatic final int
return code indicating the execute() threw an I/O exceptionFields inherited from class com.prineside.luaj.lib.OsLib
globals, TMP_PREFIX, TMP_SUFFIX
Fields inherited from class com.prineside.luaj.lib.LibFunction
name, opcode
Fields inherited from class com.prineside.luaj.LuaFunction
s_metatable
Fields inherited from class com.prineside.luaj.LuaValue
ADD, CALL, CONCAT, DIV, EMPTYSTRING, ENV, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILLABLE_SERIALIZER, 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String
Returns the value of the process environment variable varname, or the System property value for varname, or null if the variable is not defined in either environment.protected void
Deletes the file or directory with the given name.protected void
Renames file or directory named oldname to newname.protected String
tmpname()
Returns a string with a file name that can be used for a temporary file.Methods inherited from class com.prineside.luaj.lib.OsLib
call, clock, date, difftime, execute, exit, read, setlocale, time, write
Methods inherited from class com.prineside.luaj.lib.TwoArgFunction
call, call, call, invoke
Methods inherited from class com.prineside.luaj.lib.LibFunction
bind, bind, call, newupe, newupl, newupn, tojstring
Methods inherited from class com.prineside.luaj.LuaFunction
checkfunction, classnamestub, getmetatable, isfunction, name, optfunction, strvalue, type, typename
Methods inherited from class com.prineside.luaj.LuaValue
add, add, add, and, arg, arg1, argerror, argerror, aritherror, aritherror, arithmt, arithmtwith, assert_, buffer, call, callmt, cBool, cDouble, cFloat, checkboolean, checkclosure, checkdouble, checkglobals, checkint, checkjstring, checklong, checkmetatag, checknotnil, checknumber, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, cInt, cNcDouble, cNcFloat, cNcInt, cObject, compareerror, compareerror, comparemt, concat, concat, concatmt, concatTo, concatTo, concatTo, cRegObject, cVarargs, cVarargs, cVarargs, cVarargs, cVarargs, cVarargs, cVarargs, cVarargs, div, div, div, divInto, eq, eq_b, eqmtcall, equals, error, get, get, get, gettable, gt, gt, gt, gt_b, gt_b, gt_b, gteq, gteq, gteq, gteq_b, gteq_b, gteq_b, illegal, inext, initupvalue1, invoke, invoke, invoke, invokemethod, invokemethod, invokemethod, invokemethod, isboolean, isclosure, isint, isinttype, islong, isnil, isnumber, isRegObject, isstring, istable, isthread, isuserdata, isuserdata, isvalidkey, len, lenerror, length, listOf, listOf, load, lt, lt, lt, lt_b, lt_b, lt_b, lteq, lteq, lteq, lteq_b, lteq_b, lteq_b, markAsConst, metatableOf, metatag, method, method, method, method, method, method, mod, mod, mod, modFrom, mul, mul, mul, narg, neg, neq, neq_b, next, not, onInvoke, optboolean, optclosure, optdouble, optint, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, or, pow, pow, pow, powWith, powWith, presize, raweq, raweq, raweq, raweq, raweq, rawget, rawget, rawget, rawlen, rawset, rawset, rawset, rawset, rawset, rawset, rawset, rawsetlist, set, set, set, set, set, set, set, setmetatable, settable, strcmp, strcmp, strongvalue, sub, sub, sub, subargs, subFrom, subFrom, tableOf, tableOf, tableOf, tableOf, tableOf, tableOf, tailcallOf, testfor_b, toboolean, tobyte, tochar, todouble, tofloat, toint, tolong, tonumber, toshort, tostring, toString, touserdata, touserdata, typerror, unimplemented, userdataOf, userdataOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf
Methods inherited from class com.prineside.luaj.Varargs
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, dealias, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type
-
Field Details
-
EXEC_IOEXCEPTION
public static final int EXEC_IOEXCEPTIONreturn code indicating the execute() threw an I/O exception- See Also:
-
EXEC_INTERRUPTED
public static final int EXEC_INTERRUPTEDreturn code indicating the execute() was interrupted- See Also:
-
EXEC_ERROR
public static final int EXEC_ERRORreturn code indicating the execute() threw an unknown exception- See Also:
-
-
Constructor Details
-
JseOsLib
public JseOsLib()public constructor
-
-
Method Details
-
getenv
Description copied from class:OsLib
Returns the value of the process environment variable varname, or the System property value for varname, or null if the variable is not defined in either environment. The default implementation, which is used by the JmePlatform, only queryies System.getProperty(). The JsePlatform overrides this behavior and returns the environment variable value using System.getenv() if it exists, or the System property value if it does not. A SecurityException may be thrown if access is not allowed for 'varname'. -
remove
Description copied from class:OsLib
Deletes the file or directory with the given name. Directories must be empty to be removed. If this function fails, it throws and IOException- Overrides:
remove
in classOsLib
- Throws:
IOException
- if it fails
-
rename
Description copied from class:OsLib
Renames file or directory named oldname to newname. If this function fails,it throws and IOException- Overrides:
rename
in classOsLib
- Parameters:
oldname
- old file namenewname
- new file name- Throws:
IOException
- if it fails
-
tmpname
Description copied from class:OsLib
Returns a string with a file name that can be used for a temporary file. The file must be explicitly opened before its use and explicitly removed when no longer needed. On some systems (POSIX), this function also creates a file with that name, to avoid security risks. (Someone else might create the file with wrong permissions in the time between getting the name and creating the file.) You still have to open the file to use it and to remove it (even if you do not use it).
-