public abstract class IoLib extends TwoArgFunction
LibFunction which implements the
core of the lua standard io library.
It contains the implementation of the io library support that is common to
the JSE and JME platforms.
In practice on of the concrete IOLib subclasses is chosen:
JseIoLib for the JSE platform, and
org.luaj.vm2.lib.jme.JmeIoLib for the JME platform.
The JSE implementation conforms almost completely to the C-based lua library, while the JME implementation follows closely except in the area of random-access files, which are difficult to support properly on JME.
Typically, this library is included as part of a call to either
JsePlatform.standardGlobals() or org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()
Globals globals = JsePlatform.standardGlobals();
globals.get("io").get("write").call(LuaValue.valueOf("hello, world\n"));
In this example the platform-specific JseIoLib library will be loaded, which will include
the base functionality provided by this class, whereas the JsePlatform would load the
JseIoLib.
To instantiate and use it directly,
link it into your globals table via LuaValue.load(LuaValue) using code such as:
Globals globals = new Globals();
globals.load(new JseBaseLib());
globals.load(new PackageLib());
globals.load(new OsLib());
globals.get("io").get("write").call(LuaValue.valueOf("hello, world\n"));
This has been implemented to match as closely as possible the behavior in the corresponding library in C.
LibFunction,
JsePlatform,
org.luaj.vm2.lib.jme.JmePlatform,
JseIoLib,
org.luaj.vm2.lib.jme.JmeIoLib,
http://www.lua.org/manual/5.1/manual.html#5.7| 限定符和类型 | 类和说明 |
|---|---|
protected class |
IoLib.File |
| 限定符和类型 | 字段和说明 |
|---|---|
static String[] |
FILE_NAMES |
protected static int |
FTYPE_NAMED
Enumerated value representing a file type for a named file
|
protected static int |
FTYPE_STDERR
Enumerated value representing stderr
|
protected static int |
FTYPE_STDIN
Enumerated value representing stdin
|
protected static int |
FTYPE_STDOUT
Enumerated value representing stdout
|
protected Globals |
globals |
static String[] |
IO_NAMES |
name, opcodes_metatableADD, BAND, BNOT, BOR, BXOR, CALL, CONCAT, DIV, EMPTYSTRING, ENV, EQ, FALSE, IDIV, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SHL, SHR, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, uservalue, ZERO| 构造器和说明 |
|---|
IoLib() |
| 限定符和类型 | 方法和说明 |
|---|---|
Varargs |
_file_close(LuaValue file) |
Varargs |
_file_flush(LuaValue file) |
Varargs |
_file_lines(Varargs args) |
Varargs |
_file_read(LuaValue file,
Varargs subargs) |
Varargs |
_file_seek(LuaValue file,
String whence,
int offset) |
Varargs |
_file_setvbuf(LuaValue file,
String mode,
int size) |
Varargs |
_file_write(LuaValue file,
Varargs subargs) |
Varargs |
_io_close(LuaValue file) |
Varargs |
_io_flush() |
Varargs |
_io_index(LuaValue v) |
Varargs |
_io_input(LuaValue file) |
Varargs |
_io_lines(Varargs args) |
Varargs |
_io_open(String filename,
String mode) |
Varargs |
_io_output(LuaValue filename) |
Varargs |
_io_popen(String prog,
String mode) |
Varargs |
_io_read(Varargs args) |
Varargs |
_io_tmpfile() |
Varargs |
_io_type(LuaValue obj) |
Varargs |
_io_write(Varargs args) |
Varargs |
_lines_iter(LuaValue file,
boolean toclose,
Varargs args) |
LuaValue |
call(LuaValue modname,
LuaValue env)
Call
this with 2 arguments, including metatag processing,
and return only the first return value. |
static LuaValue |
freadall(IoLib.File f) |
static LuaValue |
freadbytes(IoLib.File f,
int count) |
static LuaValue |
freadline(IoLib.File f,
boolean withend) |
static LuaValue |
freadnumber(IoLib.File f) |
static LuaValue |
freaduntil(IoLib.File f,
boolean lineonly,
boolean withend) |
protected abstract IoLib.File |
openFile(String filename,
boolean readMode,
boolean appendMode,
boolean updateMode,
boolean binaryMode)
Open a file in a particular mode.
|
protected abstract IoLib.File |
openProgram(String prog,
String mode)
Start a new process and return a file for input or output
|
protected abstract IoLib.File |
tmpFile()
Open a temporary file.
|
protected abstract IoLib.File |
wrapStderr()
Wrap the standard error output.
|
protected abstract IoLib.File |
wrapStdin()
Wrap the standard input.
|
protected abstract IoLib.File |
wrapStdout()
Wrap the standard output.
|
call, call, call, invokecheckfunction, classnamestub, getfenv, getmetatable, isfunction, name, optfunction, setfenv, strvalue, type, typenameadd, add, add, and, arg, arg1, argerror, argerror, aritherror, aritherror, arithmt, arithmtwith, assert_, band, band, bnot, bor, bor, buffer, bxor, bxor, call, callmt, checkboolean, checkclosure, checkdouble, checkglobals, checkint, checkinteger, checkjstring, checklong, checkmetatag, checknotnil, checknumber, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, compareerror, compareerror, comparemt, concat, concat, concatmt, concatTo, concatTo, concatTo, div, div, div, divInto, eq_b, eq, eqmtcall, equals, error, get, get, get, gettable, getuservalue, gt_b, gt_b, gt_b, gt, gt, gt, gteq_b, gteq_b, gteq_b, gteq, gteq, gteq, idiv, idiv, illegal, inext, initupvalue1, invoke, invoke, invoke, invoke, invoke, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, isboolean, isclosure, isint, isinttype, islong, isnil, isnumber, isstring, istable, isthread, isuserdata, isuserdata, isvalidkey, jcall, jget, jset, len, lenerror, length, 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, next, not, onInvoke, optboolean, optclosure, optdouble, optint, optinteger, 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, setuservalue, shl, shl, shr, shr, 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, valueOf, varargsOf, varargsOf, varargsOf, varargsOf, varargsOf, varargsOfargcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, 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, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, typeprotected static final int FTYPE_STDIN
protected static final int FTYPE_STDOUT
protected static final int FTYPE_STDERR
protected static final int FTYPE_NAMED
public static final String[] IO_NAMES
public static final String[] FILE_NAMES
protected Globals globals
protected abstract IoLib.File wrapStdin() throws IOException
IOExceptionprotected abstract IoLib.File wrapStdout() throws IOException
IOExceptionprotected abstract IoLib.File wrapStderr() throws IOException
IOExceptionprotected abstract IoLib.File openFile(String filename, boolean readMode, boolean appendMode, boolean updateMode, boolean binaryMode) throws IOException
filename - readMode - true if opening in read modeappendMode - true if opening in append modeupdateMode - true if opening in update modebinaryMode - true if opening in binary modeIOException - if could not be openedprotected abstract IoLib.File tmpFile() throws IOException
IOException - if could not be openedprotected abstract IoLib.File openProgram(String prog, String mode) throws IOException
prog - the program to executemode - "r" to read, "w" to writeIOException - if an i/o exception occurspublic LuaValue call(LuaValue modname, LuaValue env)
LuaValuethis with 2 arguments, including metatag processing,
and return only the first return value.
If this is a LuaFunction, call it,
and return only its first return value, dropping any others.
Otherwise, look for the LuaValue.CALL metatag and call that.
If the return value is a Varargs, only the 1st value will be returned.
To get multiple values, use LuaValue.invoke() instead.
To call this as a method call, use LuaValue.method(LuaValue) instead.
call 在类中 TwoArgFunctionmodname - First argument to supply to the called functionenv - Second argument to supply to the called function(this(arg1,arg2)), or LuaValue.NIL if there were none.LuaValue.call(),
LuaValue.call(LuaValue),
LuaValue.call(LuaValue, LuaValue, LuaValue),
LuaValue.invoke(LuaValue, Varargs),
LuaValue.method(String,LuaValue,LuaValue),
LuaValue.method(LuaValue,LuaValue,LuaValue)public Varargs _io_flush() throws IOException
IOExceptionpublic Varargs _io_tmpfile() throws IOException
IOExceptionpublic Varargs _io_close(LuaValue file) throws IOException
IOExceptionpublic Varargs _io_popen(String prog, String mode) throws IOException
IOExceptionpublic Varargs _io_open(String filename, String mode) throws IOException
IOExceptionpublic Varargs _io_read(Varargs args) throws IOException
IOExceptionpublic Varargs _io_write(Varargs args) throws IOException
IOExceptionpublic Varargs _file_close(LuaValue file) throws IOException
IOExceptionpublic Varargs _file_flush(LuaValue file) throws IOException
IOExceptionpublic Varargs _file_read(LuaValue file, Varargs subargs) throws IOException
IOExceptionpublic Varargs _file_seek(LuaValue file, String whence, int offset) throws IOException
IOExceptionpublic Varargs _file_write(LuaValue file, Varargs subargs) throws IOException
IOExceptionpublic Varargs _lines_iter(LuaValue file, boolean toclose, Varargs args) throws IOException
IOExceptionpublic static LuaValue freadbytes(IoLib.File f, int count) throws IOException
IOExceptionpublic static LuaValue freaduntil(IoLib.File f, boolean lineonly, boolean withend) throws IOException
IOExceptionpublic static LuaValue freadline(IoLib.File f, boolean withend) throws IOException
IOExceptionpublic static LuaValue freadall(IoLib.File f) throws IOException
IOExceptionpublic static LuaValue freadnumber(IoLib.File f) throws IOException
IOExceptionCopyright © 2020. All rights reserved.