|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.luaj.vm2.Varargs org.luaj.vm2.LuaValue org.luaj.vm2.LuaFunction org.luaj.vm2.lib.LibFunction org.luaj.vm2.lib.OneArgFunction org.luaj.vm2.lib.IoLib
public abstract class IoLib
Abstract base class extending 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
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 JmePlatform#standardGlobals()
To instantiate and use it directly,
link it into your globals table via LuaValue.load(LuaValue)
using code such as:
LuaTable _G = new LuaTable();
_G.load(new JseIoLib());
LuaThread.setGlobals(_G);
_G.load(new JseBaseLib());
_G.load(new PackageLib());
_G.load(new JseIoLib());
_G.get("io").get("write").call(LuaValue.valueOf("hello, world\n"));
Doing so will ensure the library is properly initialized
and loaded into the globals table.
This has been implemented to match as closely as possible the behavior in the corresponding library in C.
LibFunction
,
JsePlatform
,
JmePlatform
,
JseIoLib
,
JmeIoLib
,
http://www.lua.org/manual/5.1/manual.html#5.7Nested Class Summary | |
---|---|
protected class |
IoLib.File
|
Field Summary | |
---|---|
static java.lang.String[] |
FILE_NAMES
|
static java.lang.String[] |
IO_NAMES
|
Fields inherited from class org.luaj.vm2.lib.LibFunction |
---|
name, opcode |
Fields inherited from class org.luaj.vm2.LuaFunction |
---|
env, s_metatable |
Fields inherited from class org.luaj.vm2.LuaValue |
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, 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 | |
---|---|
IoLib()
|
Method Summary | |
---|---|
Varargs |
_file_close(LuaValue file)
|
Varargs |
_file_flush(LuaValue file)
|
Varargs |
_file_lines(LuaValue file)
|
Varargs |
_file_read(LuaValue file,
Varargs subargs)
|
Varargs |
_file_seek(LuaValue file,
java.lang.String whence,
int offset)
|
Varargs |
_file_setvbuf(LuaValue file,
java.lang.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(java.lang.String filename)
|
Varargs |
_io_open(java.lang.String filename,
java.lang.String mode)
|
Varargs |
_io_output(LuaValue filename)
|
Varargs |
_io_popen(java.lang.String prog,
java.lang.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)
|
LuaValue |
call(LuaValue arg)
Call this with 1 argument, 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)
|
static LuaValue |
freadnumber(IoLib.File f)
|
static LuaValue |
freaduntil(IoLib.File f,
boolean lineonly)
|
protected abstract IoLib.File |
openFile(java.lang.String filename,
boolean readMode,
boolean appendMode,
boolean updateMode,
boolean binaryMode)
Open a file in a particular mode. |
protected abstract IoLib.File |
openProgram(java.lang.String prog,
java.lang.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 |
wrapStdin()
Wrap the standard input. |
protected abstract IoLib.File |
wrapStdout()
Wrap the standard output. |
Methods inherited from class org.luaj.vm2.lib.OneArgFunction |
---|
call, call, call, invoke |
Methods inherited from class org.luaj.vm2.lib.LibFunction |
---|
bind, bind, newupe, newupl, newupn, tojstring |
Methods inherited from class org.luaj.vm2.LuaFunction |
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
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, subargs, 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 |
---|
public static final java.lang.String[] IO_NAMES
public static final java.lang.String[] FILE_NAMES
Constructor Detail |
---|
public IoLib()
Method Detail |
---|
protected abstract IoLib.File wrapStdin() throws java.io.IOException
java.io.IOException
protected abstract IoLib.File wrapStdout() throws java.io.IOException
java.io.IOException
protected abstract IoLib.File openFile(java.lang.String filename, boolean readMode, boolean appendMode, boolean updateMode, boolean binaryMode) throws java.io.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 mode
java.io.IOException
- if could not be openedprotected abstract IoLib.File tmpFile() throws java.io.IOException
java.io.IOException
- if could not be openedprotected abstract IoLib.File openProgram(java.lang.String prog, java.lang.String mode) throws java.io.IOException
prog
- the program to executemode
- "r" to read, "w" to write
java.io.IOException
- if an i/o exception occurspublic LuaValue call(LuaValue arg)
LuaValue
this
with 1 argument, 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 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
in class OneArgFunction
arg
- First argument to supply to the called function
(this(arg))
, or NIL
if there were none.LuaValue.call()
,
LuaValue.call(LuaValue,LuaValue)
,
LuaValue.call(LuaValue, LuaValue, LuaValue)
,
#invoke(LuaValue)
,
LuaValue.method(String,LuaValue)
,
LuaValue.method(LuaValue,LuaValue)
public Varargs _io_flush() throws java.io.IOException
java.io.IOException
public Varargs _io_tmpfile() throws java.io.IOException
java.io.IOException
public Varargs _io_close(LuaValue file) throws java.io.IOException
java.io.IOException
public Varargs _io_input(LuaValue file)
public Varargs _io_output(LuaValue filename)
public Varargs _io_type(LuaValue obj)
public Varargs _io_popen(java.lang.String prog, java.lang.String mode) throws java.io.IOException
java.io.IOException
public Varargs _io_open(java.lang.String filename, java.lang.String mode) throws java.io.IOException
java.io.IOException
public Varargs _io_lines(java.lang.String filename)
public Varargs _io_read(Varargs args) throws java.io.IOException
java.io.IOException
public Varargs _io_write(Varargs args) throws java.io.IOException
java.io.IOException
public Varargs _file_close(LuaValue file) throws java.io.IOException
java.io.IOException
public Varargs _file_flush(LuaValue file) throws java.io.IOException
java.io.IOException
public Varargs _file_setvbuf(LuaValue file, java.lang.String mode, int size)
public Varargs _file_lines(LuaValue file)
public Varargs _file_read(LuaValue file, Varargs subargs) throws java.io.IOException
java.io.IOException
public Varargs _file_seek(LuaValue file, java.lang.String whence, int offset) throws java.io.IOException
java.io.IOException
public Varargs _file_write(LuaValue file, Varargs subargs) throws java.io.IOException
java.io.IOException
public Varargs _io_index(LuaValue v)
public Varargs _lines_iter(LuaValue file) throws java.io.IOException
java.io.IOException
public static LuaValue freadbytes(IoLib.File f, int count) throws java.io.IOException
java.io.IOException
public static LuaValue freaduntil(IoLib.File f, boolean lineonly) throws java.io.IOException
java.io.IOException
public static LuaValue freadline(IoLib.File f) throws java.io.IOException
java.io.IOException
public static LuaValue freadall(IoLib.File f) throws java.io.IOException
java.io.IOException
public static LuaValue freadnumber(IoLib.File f) throws java.io.IOException
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |