Fix links in javadoc
This commit is contained in:
@@ -28,6 +28,7 @@ import java.io.Reader;
|
||||
|
||||
import org.luaj.vm2.lib.BaseLib;
|
||||
import org.luaj.vm2.lib.DebugLib;
|
||||
import org.luaj.vm2.lib.IoLib;
|
||||
import org.luaj.vm2.lib.PackageLib;
|
||||
import org.luaj.vm2.lib.ResourceFinder;
|
||||
|
||||
@@ -37,7 +38,8 @@ import org.luaj.vm2.lib.ResourceFinder;
|
||||
*
|
||||
* <h3>Constructing and Initializing Instances</h3>
|
||||
* Typically, this is constructed indirectly by a call to
|
||||
* {@link JsePlatform.standardGlobasl()} or {@link JmePlatform.standardGlobals()},
|
||||
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or
|
||||
* {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()},
|
||||
* and then used to load lua scripts for execution as in the following example.
|
||||
* <pre> {@code
|
||||
* Globals globals = JsePlatform.standardGlobals();
|
||||
@@ -64,30 +66,30 @@ import org.luaj.vm2.lib.ResourceFinder;
|
||||
* <ul>
|
||||
* <li>find the resource using the platform's {@link ResourceFinder}
|
||||
* <li>compile lua to lua bytecode using {@link Compiler}
|
||||
* <li>load lua bytecode to a {@link LuaPrototpye} using {@link Undumper}
|
||||
* <li>load lua bytecode to a {@link Prototype} using {@link Undumper}
|
||||
* <li>construct {@link LuaClosure} from {@link Prototype} with {@link Globals} using {@link Loader}
|
||||
* </ul>
|
||||
* <p>
|
||||
* There are alternate flows when the direct lua-to-Java bytecode compiling {@link LuaJC} is used.
|
||||
* There are alternate flows when the direct lua-to-Java bytecode compiling {@link org.luaj.vm2.luajc.LuaJC} is used.
|
||||
* <ul>
|
||||
* <li>compile lua to lua bytecode using {@link Compiler} or load precompiled code using {@link Undumper}
|
||||
* <li>convert lua bytecode to equivalent Java bytecode using {@link LuaJC} that implements {@link Loader} directly
|
||||
* <li>convert lua bytecode to equivalent Java bytecode using {@link org.luaj.vm2.luajc.LuaJC} that implements {@link Loader} directly
|
||||
* </ul>
|
||||
*
|
||||
* <h3>Java Field</h3>
|
||||
* Certain public fields are provided that contain the current values of important global state:
|
||||
* <ul>
|
||||
* <li>{@link STDIN} Current value for standard input in the laaded IoLib, if any.
|
||||
* <li>{@link STDOUT} Current value for standard output in the loaded IoLib, if any.
|
||||
* <li>{@link STDERR} Current value for standard error in the loaded IoLib, if any.
|
||||
* <li>{@link finder} Current loaded {@link ResourceFinder}, if any.
|
||||
* <li>{@link compiler} Current loaded {@link Compiler}, if any.
|
||||
* <li>{@link undumper} Current loaded {@link Undumper}, if any.
|
||||
* <li>{@link loader} Current loaded {@link Loader}, if any.
|
||||
* <li>{@link #STDIN} Current value for standard input in the laaded {@link IoLib}, if any.
|
||||
* <li>{@link #STDOUT} Current value for standard output in the loaded {@link IoLib}, if any.
|
||||
* <li>{@link #STDERR} Current value for standard error in the loaded {@link IoLib}, if any.
|
||||
* <li>{@link #finder} Current loaded {@link ResourceFinder}, if any.
|
||||
* <li>{@link #compiler} Current loaded {@link Compiler}, if any.
|
||||
* <li>{@link #undumper} Current loaded {@link Undumper}, if any.
|
||||
* <li>{@link #loader} Current loaded {@link Loader}, if any.
|
||||
* </ul>
|
||||
*
|
||||
* <h3>Lua Environment Variables</h3>
|
||||
* When using {@link JsePlatform} or {@link JmePlatform},
|
||||
* When using {@link org.luaj.vm2.lib.jse.JsePlatform} or {@link org.luaj.vm2.lib.jme.JmePlatform},
|
||||
* these environment variables are created within the Globals.
|
||||
* <ul>
|
||||
* <li>"_G" Pointer to this Globals.
|
||||
@@ -107,8 +109,8 @@ import org.luaj.vm2.lib.ResourceFinder;
|
||||
* @see Loader
|
||||
* @see Undumper
|
||||
* @see ResourceFinder
|
||||
* @see LuaC
|
||||
* @see LuaJC
|
||||
* @see org.luaj.vm2.compiler.LuaC
|
||||
* @see org.luaj.vm2.luajc.LuaJC
|
||||
*/
|
||||
public class Globals extends LuaTable {
|
||||
|
||||
@@ -218,7 +220,7 @@ public class Globals extends LuaTable {
|
||||
/** Load the content form a reader as a text file. Must be lua source.
|
||||
* The source is converted to UTF-8, so any characters appearing in quoted literals
|
||||
* above the range 128 will be converted into multiple bytes.
|
||||
* @param script Contents of a lua script, such as "print 'hello, world.'"
|
||||
* @param reader Reader containing text of a lua script, such as "print 'hello, world.'"
|
||||
* @param chunkname Name that will be used within the chunk as the source.
|
||||
* @return LuaValue that may be executed via .call(), .invoke(), or .method() calls.
|
||||
* @throws LuaError if the script could not be compiled.
|
||||
@@ -231,7 +233,7 @@ public class Globals extends LuaTable {
|
||||
* Must be lua source. The source is converted to UTF-8, so any characters
|
||||
* appearing in quoted literals above the range 128 will be converted into
|
||||
* multiple bytes.
|
||||
* @param script Contents of a lua script, such as "print 'hello, world.'"
|
||||
* @param reader Reader containing text of a lua script, such as "print 'hello, world.'"
|
||||
* @param chunkname Name that will be used within the chunk as the source.
|
||||
* @param environment LuaTable to be used as the environment for the loaded function.
|
||||
* @return LuaValue that may be executed via .call(), .invoke(), or .method() calls.
|
||||
@@ -242,7 +244,7 @@ public class Globals extends LuaTable {
|
||||
}
|
||||
|
||||
/** Load the content form an input stream as a binary chunk or text file.
|
||||
* @param is Input stream containing a lua script or compiled lua"
|
||||
* @param is InputStream containing a lua script or compiled lua"
|
||||
* @param chunkname Name that will be used within the chunk as the source.
|
||||
* @param mode String containing 'b' or 't' or both to control loading as binary or text or either.
|
||||
* @param environment LuaTable to be used as the environment for the loaded function.
|
||||
|
||||
@@ -25,15 +25,14 @@ import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.luaj.vm2.compiler.DumpState;
|
||||
|
||||
|
||||
/**
|
||||
* Class to undump compiled lua bytecode into a {@link Prototype} instances.
|
||||
* <p>
|
||||
* The {@link LoadState} class implements {@link Globals#Undumper}
|
||||
* The {@link LoadState} class provides the default {@link Globals.Undumper}
|
||||
* which is used to undump a string of bytes that represent a lua binary file
|
||||
* using either the C-based lua compiler, or luaj's {@link DumpState#dump} function.
|
||||
* using either the C-based lua compiler, or luaj's
|
||||
* {@link org.luaj.vm2.compiler.LuaC} compiler.
|
||||
* <p>
|
||||
* The canonical method to load and execute code is done
|
||||
* indirectly using the Globals:
|
||||
@@ -42,24 +41,27 @@ import org.luaj.vm2.compiler.DumpState;
|
||||
* LuaValue chunk = globasl.load("print('hello, world')", "main.lua");
|
||||
* chunk.call();
|
||||
* } </pre>
|
||||
* This should work regardless of which {@link Globals.Compiler}
|
||||
* has been installed.
|
||||
* This should work regardless of which {@link Globals.Compiler} or {@link Globals.Undumper}
|
||||
* have been installed.
|
||||
* <p>
|
||||
* By default, when using {@link JsePlatform} or {@JmePlatform}
|
||||
* to construct globals, the {@link LoadState} is installed
|
||||
* as the default {@link Globals#undumper}.
|
||||
* By default, when using {@link org.luaj.vm2.lib.jse.JsePlatform} or
|
||||
* {@link org.luaj.vm2.lib.jme.JmePlatform}
|
||||
* to construct globals, the {@link LoadState} default undumper is installed
|
||||
* as the default {@link Globals.Undumper}.
|
||||
* <p>
|
||||
*
|
||||
* A lua binary file is created via {@link DumpState#dump}:
|
||||
* A lua binary file is created via the {@link org.luaj.vm2.compiler.DumpState} class
|
||||
:
|
||||
* <pre> {@code
|
||||
* Globals globals = JsePlatform.standardGlobals();
|
||||
* Prototype p = globals.compilePrototype(new StringReader("print('hello, world')"), "main.lua");
|
||||
* ByteArrayOutputStream o = new ByteArrayOutputStream();
|
||||
* DumpState.dump(p, o, false);
|
||||
* org.luaj.vm2.compiler.DumpState.dump(p, o, false);
|
||||
* byte[] lua_binary_file_bytes = o.toByteArray();
|
||||
* } </pre>
|
||||
*
|
||||
* The {@link LoadState} may be used directly to undump these bytes:
|
||||
* The {@link LoadState}'s default undumper {@link #instance}
|
||||
* may be used directly to undump these bytes:
|
||||
* <pre> {@code
|
||||
* Prototypep = LoadState.instance.undump(new ByteArrayInputStream(lua_binary_file_bytes), "main.lua");
|
||||
* LuaClosure c = new LuaClosure(p, globals);
|
||||
@@ -67,20 +69,21 @@ import org.luaj.vm2.compiler.DumpState;
|
||||
* } </pre>
|
||||
*
|
||||
*
|
||||
* More commonly, the {@link Globals#undumper} may be used to undump them:
|
||||
* More commonly, the {@link Globals.Undumper} may be used to undump them:
|
||||
* <pre> {@code
|
||||
* Prototype p = globals.loadPrototype(new ByteArrayInputStream(lua_binary_file_bytes), "main.lua", "b");
|
||||
* LuaClosure c = new LuaClosure(p, globals);
|
||||
* c.call();
|
||||
* } </pre>
|
||||
*
|
||||
* @see LuaCompiler
|
||||
* @see Globals.Compiler
|
||||
* @see Globals.Undumper
|
||||
* @see LuaClosure
|
||||
* @see LuaFunction
|
||||
* @see LoadState#compiler
|
||||
* @see LoadState#load(InputStream, String, LuaValue)
|
||||
* @see LuaC
|
||||
* @see LuaJC
|
||||
* @see org.luaj.vm2.compiler.LuaC
|
||||
* @see org.luaj.vm2.luajc.LuaJC
|
||||
* @see Globals#compiler
|
||||
* @see Globals#load(InputStream, String, LuaValue)
|
||||
*/
|
||||
public class LoadState {
|
||||
|
||||
@@ -383,7 +386,7 @@ public class LoadState {
|
||||
/**
|
||||
* Load input stream as a lua binary chunk if the first 4 bytes are the lua binary signature.
|
||||
* @param stream InputStream to read, after having read the first byte already
|
||||
* @param name Name to apply to the loaded chunk
|
||||
* @param chunkname Name to apply to the loaded chunk
|
||||
* @return {@link Prototype} that was loaded, or null if the first 4 bytes were not the lua signature.
|
||||
* @throws IOException if an IOException occurs
|
||||
*/
|
||||
|
||||
@@ -27,7 +27,7 @@ package org.luaj.vm2;
|
||||
* These instance are not instantiated directly by clients.
|
||||
* Instead, there are exactly twon instances of this class,
|
||||
* {@link LuaValue#TRUE} and {@link LuaValue#FALSE}
|
||||
* representing the lua values {@code true} and {@link false}.
|
||||
* representing the lua values {@code true} and {@code false}.
|
||||
* The function {@link LuaValue#valueOf(boolean)} will always
|
||||
* return one of these two values.
|
||||
* <p>
|
||||
|
||||
@@ -33,11 +33,12 @@ package org.luaj.vm2;
|
||||
* There are three main ways {@link LuaClosure} instances are created:
|
||||
* <ul>
|
||||
* <li>Construct an instance using {@link #LuaClosure(Prototype, LuaValue)}</li>
|
||||
* <li>Construct it indirectly by loading a chunk via {@link Globals#load(java.io.Reader, String, LuaValue)}
|
||||
* <li>Construct it indirectly by loading a chunk via {@link Globals#load(java.io.Reader, String)}
|
||||
* <li>Execute the lua bytecode {@link Lua#OP_CLOSURE} as part of bytecode processing
|
||||
* </ul>
|
||||
* <p>
|
||||
* To construct it directly, the {@link Prototype} is typically created via a compiler such as {@link LuaC}:
|
||||
* To construct it directly, the {@link Prototype} is typically created via a compiler such as
|
||||
* {@link org.luaj.vm2.compiler.LuaC}:
|
||||
* <pre> {@code
|
||||
* String script = "print( 'hello, world' )";
|
||||
* InputStream is = new ByteArrayInputStream(script.getBytes());
|
||||
@@ -47,7 +48,7 @@ package org.luaj.vm2;
|
||||
* f.call();
|
||||
* }</pre>
|
||||
* <p>
|
||||
* To construct it indirectly, the {@link Globals#load} method may be used:
|
||||
* To construct it indirectly, the {@link Globals#load(java.io.Reader, String)} method may be used:
|
||||
* <pre> {@code
|
||||
* Globals globals = JsePlatform.standardGlobals();
|
||||
* LuaFunction f = globals.load(new StringReader(script), "script");
|
||||
@@ -78,7 +79,7 @@ package org.luaj.vm2;
|
||||
* @see LuaValue#checkclosure()
|
||||
* @see LuaValue#optclosure(LuaClosure)
|
||||
* @see LoadState
|
||||
* @see LoadState#compiler
|
||||
* @see Globals#compiler
|
||||
*/
|
||||
public class LuaClosure extends LuaFunction {
|
||||
private static final UpValue[] NOUPVALUES = new UpValue[0];
|
||||
|
||||
@@ -110,8 +110,7 @@ public class LuaError extends RuntimeException {
|
||||
/**
|
||||
* Construct a LuaError with a LuaValue as the message object,
|
||||
* and level to draw line number information from.
|
||||
* @param message message to supply
|
||||
* @param level where to supply line info from in call stack
|
||||
* @param message_object message string or object to supply
|
||||
*/
|
||||
public LuaError(LuaValue message_object) {
|
||||
super( message_object.tojstring() );
|
||||
|
||||
@@ -21,16 +21,18 @@
|
||||
******************************************************************************/
|
||||
package org.luaj.vm2;
|
||||
|
||||
|
||||
/**
|
||||
* Base class for functions implemented in Java.
|
||||
* <p>
|
||||
* Direct subclass include {@link LibFunction} which is the base class for
|
||||
* Direct subclass include {@link org.luaj.vm2.lib.LibFunction}
|
||||
* which is the base class for
|
||||
* all built-in library functions coded in Java,
|
||||
* and {@link LuaClosure}, which represents a lua closure
|
||||
* whose bytecode is interpreted when the function is invoked.
|
||||
* @see LuaValue
|
||||
* @see LibFunction
|
||||
* @see LuaClosure
|
||||
* @see org.luaj.vm2.lib.LibFunction
|
||||
*/
|
||||
abstract
|
||||
public class LuaFunction extends LuaValue {
|
||||
|
||||
@@ -33,14 +33,12 @@ import java.lang.ref.WeakReference;
|
||||
* <p>
|
||||
* The threads must be initialized with the globals, so that
|
||||
* the global environment may be passed along according to rules of lua.
|
||||
* This is done via a call to {@link #setGlobals(LuaValue)}
|
||||
* at some point during globals initialization.
|
||||
* See {@link BaseLib} for additional documentation and example code.
|
||||
* This is done via the constructor arguments {@link #LuaThread(Globals)} or
|
||||
* {@link #LuaThread(Globals, LuaValue)}.
|
||||
* <p>
|
||||
* The utility classes {@link JsePlatform} and {@link JmePlatform}
|
||||
* see to it that this initialization is done properly.
|
||||
* For this reason it is highly recommended to use one of these classes
|
||||
* when initializing globals.
|
||||
* The utility classes {@link org.luaj.vm2.lib.jse.JsePlatform} and
|
||||
* {@link org.luaj.vm2.lib.jme.JmePlatform}
|
||||
* see to it that this {@link Globals} are initialized properly.
|
||||
* <p>
|
||||
* The behavior of coroutine threads matches closely the behavior
|
||||
* of C coroutine library. However, because of the use of Java threads
|
||||
@@ -50,17 +48,29 @@ import java.lang.ref.WeakReference;
|
||||
* to determine if it can ever be resumed. If not, it throws
|
||||
* {@link OrphanedThread} which is an {@link java.lang.Error}.
|
||||
* Applications should not catch {@link OrphanedThread}, because it can break
|
||||
* the thread safety of luaj.
|
||||
* the thread safety of luaj. The value controlling the polling interval
|
||||
* is {@link #thread_orphan_check_interval} and may be set by the user.
|
||||
* <p>
|
||||
* There are two main ways to abandon a coroutine. The first is to call
|
||||
* {@code yield()} from lua, or equivalently {@link Globals#yield(Varargs)},
|
||||
* and arrange to have it never resumed possibly by values passed to yield.
|
||||
* The second is to throw {@link OrphanedThread}, which should put the thread
|
||||
* in a dead state. In either case all references to the thread must be
|
||||
* dropped, and the garbage collector must run for the thread to be
|
||||
* garbage collected.
|
||||
*
|
||||
*
|
||||
* @see LuaValue
|
||||
* @see JsePlatform
|
||||
* @see JmePlatform
|
||||
* @see CoroutineLib
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see org.luaj.vm2.lib.CoroutineLib
|
||||
*/
|
||||
public class LuaThread extends LuaValue {
|
||||
|
||||
/** Shared metatable for lua threads. */
|
||||
public static LuaValue s_metatable;
|
||||
|
||||
/** The current number of coroutines. Should not be set. */
|
||||
public static int coroutine_count = 0;
|
||||
|
||||
/** Polling interval, in milliseconds, which each thread uses while waiting to
|
||||
|
||||
@@ -59,7 +59,7 @@ import org.luaj.vm2.Varargs;
|
||||
* } </pre>
|
||||
* <p>
|
||||
* To supply variable arguments or get multiple return values, use
|
||||
* {@link invoke(Varargs)} or {@link invokemethod(LuaValue, Varargs)} methods:
|
||||
* {@link #invoke(Varargs)} or {@link #invokemethod(LuaValue, Varargs)} methods:
|
||||
* <pre> {@code
|
||||
* LuaValue modf = globals.get("math").get("modf");
|
||||
* Varargs r = modf.invoke( d );
|
||||
@@ -77,7 +77,7 @@ import org.luaj.vm2.Varargs;
|
||||
* } </pre>
|
||||
* For this to work the file must be in the current directory, or in the class path,
|
||||
* dependening on the platform.
|
||||
* See {@link JsePlatform} and {@link JmePlatform} for details.
|
||||
* See {@link org.luaj.vm2.lib.jse.JsePlatform} and {@link org.luaj.vm2.lib.jme.JmePlatform} for details.
|
||||
* <p>
|
||||
* In general a {@link LuaError} may be thrown on any operation when the
|
||||
* types supplied to any operation are illegal from a lua perspective.
|
||||
@@ -92,19 +92,19 @@ import org.luaj.vm2.Varargs;
|
||||
* </ul>
|
||||
* <p>
|
||||
* Predefined constants exist for the standard lua type constants
|
||||
* {@link #TNIL}, {@link #TBOOLEAN}, {@link TLIGHTUSERDATA}, {@link #TNUMBER}, {@link #TSTRING},
|
||||
* {@link #TNIL}, {@link #TBOOLEAN}, {@link #TLIGHTUSERDATA}, {@link #TNUMBER}, {@link #TSTRING},
|
||||
* {@link #TTABLE}, {@link #TFUNCTION}, {@link #TUSERDATA}, {@link #TTHREAD},
|
||||
* and extended lua type constants
|
||||
* {@link TINT}, {@link #TNONE}, {@link TVALUE}
|
||||
* {@link #TINT}, {@link #TNONE}, {@link #TVALUE}
|
||||
* <p>
|
||||
* Predefined constants exist for all strings used as metatags:
|
||||
* {@link #INDEX}, {@link #NEWINDEX}, {@link #CALL}, {@link MODE}, {@link METATABLE},
|
||||
* {@link #INDEX}, {@link #NEWINDEX}, {@link #CALL}, {@link #MODE}, {@link #METATABLE},
|
||||
* {@link #ADD}, {@link #SUB}, {@link #DIV}, {@link #MUL}, {@link #POW},
|
||||
* {@link MOD}, {@link #UNM}, {@link #LEN}, {@link #EQ}, {@link #LT},
|
||||
* {@link #MOD}, {@link #UNM}, {@link #LEN}, {@link #EQ}, {@link #LT},
|
||||
* {@link #LE}, {@link #TOSTRING}, and {@link #CONCAT}.
|
||||
*
|
||||
* @see JsePlatform
|
||||
* @see JmePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see LoadState
|
||||
* @see Varargs
|
||||
*/
|
||||
@@ -292,7 +292,7 @@ public class LuaValue extends Varargs {
|
||||
* @see #toboolean()
|
||||
* @see #checkboolean()
|
||||
* @see #optboolean(boolean)
|
||||
* @see #TOBOLEAN
|
||||
* @see #TBOOLEAN
|
||||
*/
|
||||
public boolean isboolean() { return false; }
|
||||
|
||||
@@ -310,7 +310,7 @@ public class LuaValue extends Varargs {
|
||||
* @return true if this is a {@code function}, otherwise false
|
||||
* @see #isclosure()
|
||||
* @see #checkfunction()
|
||||
* @see #optfunciton(LuaFunction)
|
||||
* @see #optfunction(LuaFunction)
|
||||
* @see #TFUNCTION
|
||||
*/
|
||||
public boolean isfunction() { return false; }
|
||||
@@ -426,7 +426,7 @@ public class LuaValue extends Varargs {
|
||||
* @see #isuserdata()
|
||||
* @see #touserdata(Class)
|
||||
* @see #checkuserdata(Class)
|
||||
* @see #optuserdata(Object,Class)
|
||||
* @see #optuserdata(Class, Object)
|
||||
* @see #TUSERDATA
|
||||
*/
|
||||
public boolean isuserdata(Class c) { return false; }
|
||||
@@ -444,7 +444,6 @@ public class LuaValue extends Varargs {
|
||||
* @return Value cast to byte if number or string convertible to number, otherwise 0
|
||||
* @see #toint()
|
||||
* @see #todouble()
|
||||
* @see #optbyte(byte)
|
||||
* @see #checknumber()
|
||||
* @see #isnumber()
|
||||
* @see #TNUMBER
|
||||
@@ -455,7 +454,6 @@ public class LuaValue extends Varargs {
|
||||
* @return Value cast to char if number or string convertible to number, otherwise 0
|
||||
* @see #toint()
|
||||
* @see #todouble()
|
||||
* @see #optchar(char)
|
||||
* @see #checknumber()
|
||||
* @see #isnumber()
|
||||
* @see #TNUMBER
|
||||
@@ -481,7 +479,6 @@ public class LuaValue extends Varargs {
|
||||
* @return Value cast to float if number or string convertible to number, otherwise 0
|
||||
* @see #toint()
|
||||
* @see #todouble()
|
||||
* @see #optfloat(float)
|
||||
* @see #checknumber()
|
||||
* @see #isnumber()
|
||||
* @see #TNUMBER
|
||||
@@ -520,7 +517,6 @@ public class LuaValue extends Varargs {
|
||||
* @return Value cast to short if number or string convertible to number, otherwise 0
|
||||
* @see #toint()
|
||||
* @see #todouble()
|
||||
* @see #optshort(short)
|
||||
* @see #checknumber()
|
||||
* @see #isnumber()
|
||||
* @see #TNUMBER
|
||||
@@ -609,7 +605,7 @@ public class LuaValue extends Varargs {
|
||||
|
||||
/** Check that optional argument is a boolean and return its boolean value
|
||||
* @param defval boolean value to return if {@code this} is nil or none
|
||||
* @return {@code this} cast to boolean if a {@LuaBoolean},
|
||||
* @return {@code this} cast to boolean if a {@link LuaBoolean},
|
||||
* {@code defval} if nil or none,
|
||||
* throws {@link LuaError} otherwise
|
||||
* @throws LuaError if was not a boolean or nil or none.
|
||||
@@ -621,7 +617,7 @@ public class LuaValue extends Varargs {
|
||||
|
||||
/** Check that optional argument is a closure and return as {@link LuaClosure}
|
||||
* <p>
|
||||
* A {@link LuaClosure} is a {@LuaFunction} that executes lua byteccode.
|
||||
* A {@link LuaClosure} is a {@link LuaFunction} that executes lua byteccode.
|
||||
* @param defval {@link LuaClosure} to return if {@code this} is nil or none
|
||||
* @return {@code this} cast to {@link LuaClosure} if a function,
|
||||
* {@code defval} if nil or none,
|
||||
@@ -836,7 +832,7 @@ public class LuaValue extends Varargs {
|
||||
/** Check that the value is a {@link LuaClosure} ,
|
||||
* or throw {@link LuaError} if not
|
||||
* <p>
|
||||
* {@link LuaClosure} is a subclass of {@LuaFunction} that interprets lua bytecode.
|
||||
* {@link LuaClosure} is a subclass of {@link LuaFunction} that interprets lua bytecode.
|
||||
* @return {@code this} cast as {@link LuaClosure}
|
||||
* @throws LuaError if not a {@link LuaClosure}
|
||||
* @see #checkfunction()
|
||||
@@ -876,7 +872,7 @@ public class LuaValue extends Varargs {
|
||||
/** Check that the value is a Globals instance, or throw {@link LuaError} if not
|
||||
* <p>
|
||||
* {@link Globals} are a special {@link LuaTable} that establish the default global environment.
|
||||
* @return {@code this} if if an instance fof {@Globals}
|
||||
* @return {@code this} if if an instance fof {@link Globals}
|
||||
* @throws LuaError if not a {@link Globals} instance.
|
||||
*/
|
||||
public Globals checkglobals() { argerror("globals"); return null; }
|
||||
@@ -1046,8 +1042,10 @@ public class LuaValue extends Varargs {
|
||||
|
||||
/**
|
||||
* Assert a condition is true, or throw a {@link LuaError} if not
|
||||
* Returns no value when b is true, throws {@link #error(String)} with {@code msg} as argument
|
||||
* and does not return if b is false.
|
||||
* @param b condition to test
|
||||
* @return returns no value when b is true, throws error not return if b is false
|
||||
* @param msg String message to produce on failure
|
||||
* @throws LuaError if b is not true
|
||||
*/
|
||||
public static void assert_(boolean b,String msg) { if(!b) throw new LuaError(msg); }
|
||||
@@ -1320,7 +1318,7 @@ public class LuaValue extends Varargs {
|
||||
* or {@link #NIL} if there are no more.
|
||||
* @throws LuaError if {@code this} is not a table, or the supplied key is invalid.
|
||||
* @see LuaTable
|
||||
* @see #inext()
|
||||
* @see #inext(LuaValue)
|
||||
* @see #valueOf(int)
|
||||
* @see Varargs#arg1()
|
||||
* @see Varargs#arg(int)
|
||||
@@ -1345,10 +1343,10 @@ public class LuaValue extends Varargs {
|
||||
* @param index {@link LuaInteger} value identifying a key to start from,
|
||||
* or {@link #NIL} to start at the beginning
|
||||
* @return {@link Varargs} containing {@code (key,value)} for the next entry,
|
||||
* or {@link NONE} if there are no more.
|
||||
* or {@link #NONE} if there are no more.
|
||||
* @throws LuaError if {@code this} is not a table, or the supplied key is invalid.
|
||||
* @see LuaTable
|
||||
* @see #next()
|
||||
* @see #next(LuaValue)
|
||||
* @see #valueOf(int)
|
||||
* @see Varargs#arg1()
|
||||
* @see Varargs#arg(int)
|
||||
@@ -1361,7 +1359,6 @@ public class LuaValue extends Varargs {
|
||||
* and this Globals as the environment. This is normally used to iniitalize the
|
||||
* library instance and which may install itself into these globals.
|
||||
* @param library The callable {@link LuaValue} to load into {@code this}
|
||||
* @param string
|
||||
* @return {@link LuaValue} returned by the initialization call.
|
||||
*/
|
||||
public LuaValue load(LuaValue library) { return library.call(EMPTYSTRING, this); }
|
||||
@@ -1446,7 +1443,7 @@ public class LuaValue extends Varargs {
|
||||
* @see #call()
|
||||
* @see #call(LuaValue,LuaValue)
|
||||
* @see #call(LuaValue, LuaValue, LuaValue)
|
||||
* @see #invoke(LuaValue)
|
||||
* @see #invoke(Varargs)
|
||||
* @see #method(String,LuaValue)
|
||||
* @see #method(LuaValue,LuaValue)
|
||||
*/
|
||||
@@ -1480,7 +1477,7 @@ public class LuaValue extends Varargs {
|
||||
* @see #call()
|
||||
* @see #call(LuaValue)
|
||||
* @see #call(LuaValue, LuaValue, LuaValue)
|
||||
* @see #invoke(LuaValue,LuaValue)
|
||||
* @see #invoke(LuaValue, Varargs)
|
||||
* @see #method(String,LuaValue,LuaValue)
|
||||
* @see #method(LuaValue,LuaValue,LuaValue)
|
||||
*/
|
||||
@@ -1508,7 +1505,7 @@ public class LuaValue extends Varargs {
|
||||
* @see #call()
|
||||
* @see #call(LuaValue)
|
||||
* @see #call(LuaValue, LuaValue)
|
||||
* @see #invoke(LuaValue,LuaValue, LuaValue)
|
||||
* @see #invoke(LuaValue, LuaValue, Varargs)
|
||||
* @see #invokemethod(String,Varargs)
|
||||
* @see #invokemethod(LuaValue,Varargs)
|
||||
*/
|
||||
@@ -1586,9 +1583,9 @@ public class LuaValue extends Varargs {
|
||||
* or the invoked function throws a {@link LuaError}
|
||||
* or the invoked closure throw a lua {@code error}
|
||||
* @see #call(LuaValue)
|
||||
* @see #invoke(LuaValue)
|
||||
* @see #method(LuaValue,LuaValue)
|
||||
* @see #invoke(Varargs)
|
||||
* @see #method(String)
|
||||
* @see #method(LuaValue)
|
||||
* @see #method(String,LuaValue,LuaValue)
|
||||
*/
|
||||
public LuaValue method(String name, LuaValue arg) { return this.get(name).call(this,arg); }
|
||||
@@ -1613,7 +1610,7 @@ public class LuaValue extends Varargs {
|
||||
* or the invoked function throws a {@link LuaError}
|
||||
* or the invoked closure throw a lua {@code error}
|
||||
* @see #call(LuaValue)
|
||||
* @see #invoke(LuaValue)
|
||||
* @see #invoke(Varargs)
|
||||
* @see #method(String,LuaValue)
|
||||
* @see #method(LuaValue)
|
||||
* @see #method(LuaValue,LuaValue,LuaValue)
|
||||
@@ -1838,7 +1835,10 @@ public class LuaValue extends Varargs {
|
||||
* @see #invoke()
|
||||
* @see #method(String)
|
||||
* @see #invokemethod(LuaValue)
|
||||
* @see #invokemethod(String,LuaValue)
|
||||
* @see #invokemethod(String, LuaValue[])
|
||||
* @see #invokemethod(String, Varargs)
|
||||
* @see #invokemethod(LuaValue, LuaValue[])
|
||||
* @see #invokemethod(LuaValue, Varargs)
|
||||
*/
|
||||
public Varargs invokemethod(String name) { return get(name).invoke(this); }
|
||||
|
||||
@@ -1863,7 +1863,10 @@ public class LuaValue extends Varargs {
|
||||
* @see #invoke()
|
||||
* @see #method(LuaValue)
|
||||
* @see #invokemethod(String)
|
||||
* @see #invokemethod(LuaValue,LuaValue)
|
||||
* @see #invokemethod(String, LuaValue[])
|
||||
* @see #invokemethod(String, Varargs)
|
||||
* @see #invokemethod(LuaValue, LuaValue[])
|
||||
* @see #invokemethod(LuaValue, Varargs)
|
||||
*/
|
||||
public Varargs invokemethod(LuaValue name) { return get(name).invoke(this); }
|
||||
|
||||
@@ -1888,8 +1891,11 @@ public class LuaValue extends Varargs {
|
||||
* @see #call()
|
||||
* @see #invoke(Varargs)
|
||||
* @see #method(String)
|
||||
* @see #invokemethod(LuaValue,Varargs)
|
||||
* @see #invokemethod(String,LuaValue[])
|
||||
* @see #invokemethod(String)
|
||||
* @see #invokemethod(LuaValue)
|
||||
* @see #invokemethod(String, LuaValue[])
|
||||
* @see #invokemethod(LuaValue, LuaValue[])
|
||||
* @see #invokemethod(LuaValue, Varargs)
|
||||
*/
|
||||
public Varargs invokemethod(String name, Varargs args) { return get(name).invoke(varargsOf(this,args)); }
|
||||
|
||||
@@ -1914,8 +1920,11 @@ public class LuaValue extends Varargs {
|
||||
* @see #call()
|
||||
* @see #invoke(Varargs)
|
||||
* @see #method(String)
|
||||
* @see #invokemethod(String,Varargs)
|
||||
* @see #invokemethod(LuaValue,LuaValue[])
|
||||
* @see #invokemethod(String)
|
||||
* @see #invokemethod(LuaValue)
|
||||
* @see #invokemethod(String, LuaValue[])
|
||||
* @see #invokemethod(String, Varargs)
|
||||
* @see #invokemethod(LuaValue, LuaValue[])
|
||||
*/
|
||||
public Varargs invokemethod(LuaValue name, Varargs args) { return get(name).invoke(varargsOf(this,args)); }
|
||||
|
||||
@@ -1940,8 +1949,11 @@ public class LuaValue extends Varargs {
|
||||
* @see #call()
|
||||
* @see #invoke(Varargs)
|
||||
* @see #method(String)
|
||||
* @see #invokemethod(LuaValue,LuaValue[])
|
||||
* @see #invokemethod(String,Varargs)
|
||||
* @see #invokemethod(String)
|
||||
* @see #invokemethod(LuaValue)
|
||||
* @see #invokemethod(String, Varargs)
|
||||
* @see #invokemethod(LuaValue, LuaValue[])
|
||||
* @see #invokemethod(LuaValue, Varargs)
|
||||
* @see LuaValue#varargsOf(LuaValue[])
|
||||
*/
|
||||
public Varargs invokemethod(String name, LuaValue[] args) { return get(name).invoke(varargsOf(this,varargsOf(args))); }
|
||||
@@ -1967,8 +1979,11 @@ public class LuaValue extends Varargs {
|
||||
* @see #call()
|
||||
* @see #invoke(Varargs)
|
||||
* @see #method(String)
|
||||
* @see #invokemethod(String,LuaValue[])
|
||||
* @see #invokemethod(LuaValue,Varargs)
|
||||
* @see #invokemethod(String)
|
||||
* @see #invokemethod(LuaValue)
|
||||
* @see #invokemethod(String, LuaValue[])
|
||||
* @see #invokemethod(String, Varargs)
|
||||
* @see #invokemethod(LuaValue, Varargs)
|
||||
* @see LuaValue#varargsOf(LuaValue[])
|
||||
*/
|
||||
public Varargs invokemethod(LuaValue name, LuaValue[] args) { return get(name).invoke(varargsOf(this,varargsOf(args))); }
|
||||
@@ -1989,7 +2004,7 @@ public class LuaValue extends Varargs {
|
||||
|
||||
/** Unary minus: return negative value {@code (-this)} as defined by lua unary minus operator
|
||||
* @return boolean inverse as {@link LuaBoolean} if boolean or nil,
|
||||
* numeric inverse as {@LuaNumber} if numeric,
|
||||
* numeric inverse as {@link LuaNumber} if numeric,
|
||||
* or metatag processing result if {@link #UNM} metatag is defined
|
||||
* @throws LuaError if {@code this} is not a table or string, and has no {@link #UNM} metatag
|
||||
*/
|
||||
@@ -2442,7 +2457,7 @@ public class LuaValue extends Varargs {
|
||||
* @return value of {@code (this % rhs)} if both are numeric,
|
||||
* or {@link LuaValue} if metatag processing occurs
|
||||
* @throws LuaError if either operand is not a number or string convertible to number,
|
||||
* and neither has the {@link MOD} metatag defined
|
||||
* and neither has the {@link #MOD} metatag defined
|
||||
* @see #arithmt(LuaValue, LuaValue)
|
||||
*/
|
||||
public LuaValue mod( LuaValue rhs ) { return arithmt(MOD,rhs); }
|
||||
@@ -2956,7 +2971,7 @@ public class LuaValue extends Varargs {
|
||||
* Finds the supplied metatag value and invokes it,
|
||||
* or throws {@link LuaError} if none applies.
|
||||
* @param tag The metatag to look up
|
||||
* @param rhs The right-hand-side value to perform the operation with
|
||||
* @param op1 The operand with which to to perform the operation
|
||||
* @return {@link LuaValue} resulting from metatag processing
|
||||
* @throws LuaError if metatag was not defined for either operand,
|
||||
* or if the operands are not the same type,
|
||||
@@ -2983,7 +2998,7 @@ public class LuaValue extends Varargs {
|
||||
* each operand must derive from {@link LuaString}.
|
||||
*
|
||||
* @param rhs The right-hand-side value to perform the comparison with
|
||||
* @returns int < 0 for {@code (this < rhs)}, int > 0 for {@code (this > rhs)}, or 0 when same string.
|
||||
* @return int < 0 for {@code (this < rhs)}, int > 0 for {@code (this > rhs)}, or 0 when same string.
|
||||
* @throws LuaError if either operand is not a string
|
||||
*/
|
||||
public int strcmp( LuaValue rhs ) { error("attempt to compare "+typename()); return 0; }
|
||||
@@ -2996,7 +3011,7 @@ public class LuaValue extends Varargs {
|
||||
* each operand must derive from {@link LuaString}.
|
||||
*
|
||||
* @param rhs The right-hand-side value to perform the comparison with
|
||||
* @returns int < 0 for {@code (this < rhs)}, int > 0 for {@code (this > rhs)}, or 0 when same string.
|
||||
* @return int < 0 for {@code (this < rhs)}, int > 0 for {@code (this > rhs)}, or 0 when same string.
|
||||
* @throws LuaError if this is not a string
|
||||
*/
|
||||
public int strcmp( LuaString rhs ) { error("attempt to compare "+typename()); return 0; }
|
||||
@@ -3008,7 +3023,7 @@ public class LuaValue extends Varargs {
|
||||
* each operand must derive from {@link LuaString} or {@link LuaNumber}.
|
||||
*
|
||||
* @param rhs The right-hand-side value to perform the operation with
|
||||
* @returns {@link LuaValue} resulting from concatenation of {@code (this .. rhs)}
|
||||
* @return {@link LuaValue} resulting from concatenation of {@code (this .. rhs)}
|
||||
* @throws LuaError if either operand is not of an appropriate type,
|
||||
* such as nil or a table
|
||||
*/
|
||||
@@ -3023,7 +3038,7 @@ public class LuaValue extends Varargs {
|
||||
* each operand must derive from {@link LuaString} or {@link LuaNumber}.
|
||||
*
|
||||
* @param lhs The left-hand-side value onto which this will be concatenated
|
||||
* @returns {@link LuaValue} resulting from concatenation of {@code (lhs .. this)}
|
||||
* @return {@link LuaValue} resulting from concatenation of {@code (lhs .. this)}
|
||||
* @throws LuaError if either operand is not of an appropriate type,
|
||||
* such as nil or a table
|
||||
* @see #concat(LuaValue)
|
||||
@@ -3039,7 +3054,7 @@ public class LuaValue extends Varargs {
|
||||
* each operand must derive from {@link LuaString} or {@link LuaNumber}.
|
||||
*
|
||||
* @param lhs The left-hand-side value onto which this will be concatenated
|
||||
* @returns {@link LuaValue} resulting from concatenation of {@code (lhs .. this)}
|
||||
* @return {@link LuaValue} resulting from concatenation of {@code (lhs .. this)}
|
||||
* @throws LuaError if either operand is not of an appropriate type,
|
||||
* such as nil or a table
|
||||
* @see #concat(LuaValue)
|
||||
@@ -3055,7 +3070,7 @@ public class LuaValue extends Varargs {
|
||||
* each operand must derive from {@link LuaString} or {@link LuaNumber}.
|
||||
*
|
||||
* @param lhs The left-hand-side value onto which this will be concatenated
|
||||
* @returns {@link LuaValue} resulting from concatenation of {@code (lhs .. this)}
|
||||
* @return {@link LuaValue} resulting from concatenation of {@code (lhs .. this)}
|
||||
* @throws LuaError if either operand is not of an appropriate type,
|
||||
* such as nil or a table
|
||||
* @see #concat(LuaValue)
|
||||
@@ -3327,7 +3342,6 @@ public class LuaValue extends Varargs {
|
||||
* Get particular metatag, or return {@link LuaValue#NIL} if it doesn't exist
|
||||
* @param tag Metatag name to look up, typically a string such as
|
||||
* {@link LuaValue#INDEX} or {@link LuaValue#NEWINDEX}
|
||||
* @param reason Description of error when tag lookup fails.
|
||||
* @return {@link LuaValue} for tag {@code reason}, or {@link LuaValue#NIL}
|
||||
*/
|
||||
public LuaValue metatag(LuaValue tag) {
|
||||
@@ -3382,7 +3396,6 @@ public class LuaValue extends Varargs {
|
||||
/** Construct a {@link Varargs} around an array of {@link LuaValue}s.
|
||||
*
|
||||
* @param v The array of {@link LuaValue}s
|
||||
* @param more {@link Varargs} contain values to include at the end
|
||||
* @return {@link Varargs} wrapping the supplied values.
|
||||
* @see LuaValue#varargsOf(LuaValue, Varargs)
|
||||
* @see LuaValue#varargsOf(LuaValue[], int, int)
|
||||
@@ -3399,7 +3412,7 @@ public class LuaValue extends Varargs {
|
||||
/** Construct a {@link Varargs} around an array of {@link LuaValue}s.
|
||||
*
|
||||
* @param v The array of {@link LuaValue}s
|
||||
* @param more {@link Varargs} contain values to include at the end
|
||||
* @param r {@link Varargs} contain values to include at the end
|
||||
* @return {@link Varargs} wrapping the supplied values.
|
||||
* @see LuaValue#varargsOf(LuaValue[])
|
||||
* @see LuaValue#varargsOf(LuaValue[], int, int, Varargs)
|
||||
@@ -3466,8 +3479,8 @@ public class LuaValue extends Varargs {
|
||||
* This can be used to wrap exactly 2 values, or a list consisting of 1 initial value
|
||||
* followed by another variable list of remaining values.
|
||||
*
|
||||
* @param v1 First {@link LuaValue} in the {@link Varargs}
|
||||
* @param v2 {@link LuaValue} supplying the 2rd value,
|
||||
* @param v First {@link LuaValue} in the {@link Varargs}
|
||||
* @param r {@link LuaValue} supplying the 2rd value,
|
||||
* or {@link Varargs}s supplying all values beyond the first
|
||||
* @return {@link Varargs} wrapping the supplied values.
|
||||
*/
|
||||
|
||||
@@ -29,7 +29,7 @@ package org.luaj.vm2;
|
||||
* {@link LuaThread} being used as a coroutine that could not possibly be
|
||||
* resumed again because there are no more references to the LuaThread with
|
||||
* which it is associated. Rather than locking up resources forever, this error
|
||||
* is thrown, and should fall through all the way to the thread's {@link Thread.run}() method.
|
||||
* is thrown, and should fall through all the way to the thread's {@link Thread#run()} method.
|
||||
* <p>
|
||||
* Java code mixed with the luaj vm should not catch this error because it may
|
||||
* occur when the coroutine is not running, so any processing done during error
|
||||
|
||||
@@ -29,32 +29,33 @@ package org.luaj.vm2;
|
||||
* and the main data structure for execution of compiled lua bytecode.
|
||||
*
|
||||
* <p>
|
||||
* Generally, the {@link Protoytpe} is not constructed directly is an intermediate result
|
||||
* as lua code is loaded using {@link Globals.load}:
|
||||
* Generally, the {@link Prototype} is not constructed directly is an intermediate result
|
||||
* as lua code is loaded using {@link Globals#load(java.io.Reader, String)}:
|
||||
* <pre> {@code
|
||||
* Globals globals = JsePlatform.standardGlobals();
|
||||
* globals.load( new StringReader("print 'hello'"), "main.lua" ).call();
|
||||
* } </pre>
|
||||
*
|
||||
* <p>
|
||||
* To create a {@link Prototype} directly, a compiler such as {@link LuaC} may be used:
|
||||
* To create a {@link Prototype} directly, a compiler such as
|
||||
* {@link org.luaj.vm2.compiler.LuaC} may be used:
|
||||
* <pre> {@code
|
||||
* InputStream is = new ByteArrayInputStream("print('hello,world')".getBytes());
|
||||
* Prototype p = LuaC.instance.compile(is, "script");
|
||||
* }</pre>
|
||||
*
|
||||
* To simplify loading, the {@link Globals#compilePrototype} method may be used:
|
||||
* To simplify loading, the {@link Globals#compilePrototype(java.io.InputStream, String)} method may be used:
|
||||
* <pre> {@code
|
||||
* Prototype p = globals.compileProtoytpe(is, "script");
|
||||
* }</pre>
|
||||
*
|
||||
* It may also be loaded from a {@link java.io.Reader} :
|
||||
* It may also be loaded from a {@link java.io.Reader} via {@link Globals#compilePrototype(java.io.Reader, String)}:
|
||||
* <pre> {@code
|
||||
* Prototype p = globals.compileProtoytpe(new StringReader(script), "script");
|
||||
* }</pre>
|
||||
*
|
||||
* To un-dump a binary file known to be a binary lua file that has been dumped to a string,
|
||||
* the {@link Globals#Undumper} interface may be used:
|
||||
* the {@link Globals.Undumper} interface may be used:
|
||||
* <pre> {@code
|
||||
* FileInputStream lua_binary_file = new FileInputStream("foo.lc"); // Known to be compiled lua.
|
||||
* Prototype p = globals.undumper.undump(lua_binary_file, "foo.lua");
|
||||
@@ -76,8 +77,8 @@ package org.luaj.vm2;
|
||||
*
|
||||
* @see LuaClosure
|
||||
* @see Globals
|
||||
* @see Globals#Undumper
|
||||
* @see Globasl#Compiler
|
||||
* @see Globals#undumper
|
||||
* @see Globals#compiler
|
||||
* @see Print#print
|
||||
*/
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ package org.luaj.vm2;
|
||||
* details of this mechanism, as it is built into the core
|
||||
* execution framework.
|
||||
* @see Prototype
|
||||
* @see LuaJC
|
||||
* @see org.luaj.vm2.luajc.LuaJC
|
||||
*/
|
||||
public class TailcallVarargs extends Varargs {
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public final class UpValue {
|
||||
|
||||
/**
|
||||
* Set the value of the upvalue
|
||||
* @param the {@link LuaValue} to set it to
|
||||
* @param value the {@link LuaValue} to set it to
|
||||
*/
|
||||
public final void setValue( LuaValue value ) {
|
||||
array[index] = value;
|
||||
|
||||
@@ -386,11 +386,12 @@ public abstract class Varargs {
|
||||
* */
|
||||
public LuaValue checknotnil(int i) { return arg(i).checknotnil(); }
|
||||
|
||||
/** Return argument i as a LuaValue when a user-supplied assertion passes, or throw an error.
|
||||
/** Performs test on argument i as a LuaValue when a user-supplied assertion passes, or throw an error.
|
||||
* Returns normally if the value of {@code test} is {@code true}, otherwise throws and argument error with
|
||||
* the supplied message, {@code msg}.
|
||||
* @param test user supplied assertion to test against
|
||||
* @param i the index to report in any error message
|
||||
* @param msg the error message to use when the test fails
|
||||
* @return LuaValue value if the value of {@code test} is {@code true}
|
||||
* @exception LuaError if the the value of {@code test} is {@code false}
|
||||
* */
|
||||
public void argcheck(boolean test, int i, String msg) { if (!test) LuaValue.argerror(i,msg); }
|
||||
|
||||
@@ -38,18 +38,18 @@ import org.luaj.vm2.lib.BaseLib;
|
||||
*
|
||||
* <p>
|
||||
* Compiles lua source files into lua bytecode within a {@link Prototype},
|
||||
* loads lua binary files directly into a{@link Prototype},
|
||||
* loads lua binary files directly into a {@link Prototype},
|
||||
* and optionaly instantiates a {@link LuaClosure} around the result
|
||||
* using a user-supplied environment.
|
||||
*
|
||||
* <p>
|
||||
* Implements the {@link Globals.Compiler} interface for loading
|
||||
* Implements the {@link org.luaj.vm2.Globals.Compiler} interface for loading
|
||||
* initialized chunks, which is an interface common to
|
||||
* lua bytecode compiling and java bytecode compiling.
|
||||
*
|
||||
* <p>
|
||||
* The {@link LuaC} compiler is installed by default by both the
|
||||
* {@link JsePlatform} and {@link JmePlatform} classes,
|
||||
* {@link org.luaj.vm2.lib.jse.JsePlatform} and {@link org.luaj.vm2.lib.jme.JmePlatform} classes,
|
||||
* so in the following example, the default {@link LuaC} compiler
|
||||
* will be used:
|
||||
* <pre> {@code
|
||||
@@ -62,15 +62,14 @@ import org.luaj.vm2.lib.BaseLib;
|
||||
* LuaC.install(globals);
|
||||
* } </pre>
|
||||
*
|
||||
* @see LuaC#install(Globals)
|
||||
* @see Globals#Compiler
|
||||
* @see Globals#Loader
|
||||
* @see LuaJC
|
||||
* @see JsePlatform
|
||||
* @see JmePlatform
|
||||
* @see #install(Globals)
|
||||
* @see Globals#compiler
|
||||
* @see Globals#loader
|
||||
* @see org.luaj.vm2.luajc.LuaJC
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see BaseLib
|
||||
* @see LuaValue
|
||||
* @see LuaCompiler
|
||||
* @see Prototype
|
||||
*/
|
||||
public class LuaC extends Constants implements Globals.Compiler, Globals.Loader {
|
||||
|
||||
@@ -38,18 +38,18 @@ import org.luaj.vm2.Varargs;
|
||||
* <p>
|
||||
* This contains all library functions listed as "basic functions" in the lua documentation for JME.
|
||||
* The functions dofile and loadfile use the
|
||||
* {@link #finder} instance to find resource files.
|
||||
* {@link Globals#finder} instance to find resource files.
|
||||
* Since JME has no file system by default, {@link BaseLib} implements
|
||||
* {@link ResourceFinder} using {@link Class#getResource(String)},
|
||||
* which is the closest equivalent on JME.
|
||||
* The default loader chain in {@link PackageLib} will use these as well.
|
||||
* <p>
|
||||
* To use basic library functions that include a {@link ResourceFinder} based on
|
||||
* directory lookup, use {@link JseBaseLib} instead.
|
||||
* directory lookup, use {@link org.luaj.vm2.lib.jse.JseBaseLib} instead.
|
||||
* <p>
|
||||
* Typically, this library is included as part of a call to either
|
||||
* {@link JsePlatform#standardGlobals()} or
|
||||
* {@link JmePlatform#standardGlobals()}
|
||||
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or
|
||||
* {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()}
|
||||
* <pre> {@code
|
||||
* Globals globals = JsePlatform.standardGlobals();
|
||||
* globals.get("print").call(LuaValue.valueOf("hello, world"));
|
||||
@@ -67,12 +67,12 @@ import org.luaj.vm2.Varargs;
|
||||
* and loaded into the globals table.
|
||||
* <p>
|
||||
* This is a direct port of the corresponding library in C.
|
||||
* @see JseBaseLib
|
||||
* @see org.luaj.vm2.lib.jse.JseBaseLib
|
||||
* @see ResourceFinder
|
||||
* @see #finder
|
||||
* @see Globals#finder
|
||||
* @see LibFunction
|
||||
* @see JsePlatform
|
||||
* @see JmePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see <a href="http://www.lua.org/manual/5.2/manual.html#6.1">Lua 5.2 Base Lib Reference</a>
|
||||
*/
|
||||
public class BaseLib extends TwoArgFunction implements ResourceFinder {
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.luaj.vm2.Varargs;
|
||||
* Subclass of LibFunction that implements the Lua standard {@code bit32} library.
|
||||
* <p>
|
||||
* Typically, this library is included as part of a call to either
|
||||
* {@link JsePlatform#standardGlobals()} or {@link JmePlatform#standardGlobals()}
|
||||
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()}
|
||||
* <pre> {@code
|
||||
* Globals globals = JsePlatform.standardGlobals();
|
||||
* System.out.println( globals.get("bit32").get("bnot").call( LuaValue.valueOf(2) ) );
|
||||
@@ -47,8 +47,8 @@ import org.luaj.vm2.Varargs;
|
||||
* <p>
|
||||
* This has been implemented to match as closely as possible the behavior in the corresponding library in C.
|
||||
* @see LibFunction
|
||||
* @see JsePlatform
|
||||
* @see JmePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see <a href="http://www.lua.org/manual/5.2/manual.html#6.7">Lua 5.2 Bitwise Operation Lib Reference</a>
|
||||
*/
|
||||
public class Bit32Lib extends TwoArgFunction {
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.luaj.vm2.Varargs;
|
||||
* may not be collected by the garbage collector.
|
||||
* <p>
|
||||
* Typically, this library is included as part of a call to either
|
||||
* {@link JsePlatform#standardGlobals()} or {@link JmePlatform#standardGlobals()}
|
||||
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()}
|
||||
* <pre> {@code
|
||||
* Globals globals = JsePlatform.standardGlobals();
|
||||
* System.out.println( globals.get("coroutine").get("running").call() );
|
||||
@@ -56,8 +56,8 @@ import org.luaj.vm2.Varargs;
|
||||
* } </pre>
|
||||
* <p>
|
||||
* @see LibFunction
|
||||
* @see JsePlatform
|
||||
* @see JmePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see <a href="http://www.lua.org/manual/5.2/manual.html#6.2">Lua 5.2 Coroutine Lib Reference</a>
|
||||
*/
|
||||
public class CoroutineLib extends TwoArgFunction {
|
||||
|
||||
@@ -46,11 +46,12 @@ import org.luaj.vm2.Varargs;
|
||||
* To do this, it must maintain a separate stack of calls to {@link LuaClosure} and {@link LibFunction}
|
||||
* instances.
|
||||
* Especially when lua-to-java bytecode compiling is being used
|
||||
* via a {@link LuaCompiler} such as {@link LuaJC},
|
||||
* via a {@link org.luaj.vm2.Globals.Compiler} such as {@link org.luaj.vm2.luajc.LuaJC},
|
||||
* this cannot be done in all cases.
|
||||
* <p>
|
||||
* Typically, this library is included as part of a call to either
|
||||
* {@link JsePlatform#debugGlobals()} or {@link JmePlatform#debugGlobals()}
|
||||
* {@link org.luaj.vm2.lib.jse.JsePlatform#debugGlobals()} or
|
||||
* {@link org.luaj.vm2.lib.jme.JmePlatform#debugGlobals()}
|
||||
* <pre> {@code
|
||||
* Globals globals = JsePlatform.debugGlobals();
|
||||
* System.out.println( globals.get("debug").get("traceback").call() );
|
||||
@@ -71,8 +72,8 @@ import org.luaj.vm2.Varargs;
|
||||
* in a shared server environment.
|
||||
*
|
||||
* @see LibFunction
|
||||
* @see JsePlatform
|
||||
* @see JmePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see <a href="http://www.lua.org/manual/5.2/manual.html#6.10">Lua 5.2 Debug Lib Reference</a>
|
||||
*/
|
||||
public class DebugLib extends TwoArgFunction {
|
||||
|
||||
@@ -46,14 +46,14 @@ import org.luaj.vm2.Varargs;
|
||||
* which are difficult to support properly on JME.
|
||||
* <p>
|
||||
* Typically, this library is included as part of a call to either
|
||||
* {@link JsePlatform#standardGlobals()} or {@link JmePlatform#standardGlobals()}
|
||||
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()}
|
||||
* <pre> {@code
|
||||
* Globals globals = JsePlatform.standardGlobals();
|
||||
* globals.get("io").get("write").call(LuaValue.valueOf("hello, world\n"));
|
||||
* } </pre>
|
||||
* In this example the platform-specific {@link JseIoLib} library will be loaded, which will include
|
||||
* the base functionality provided by this class, whereas the {@link JsePlatform} would load the
|
||||
* {@link JseIoLib}.
|
||||
* In this example the platform-specific {@link org.luaj.vm2.lib.jse.JseIoLib} library will be loaded, which will include
|
||||
* the base functionality provided by this class, whereas the {@link org.luaj.vm2.lib.jse.JsePlatform} would load the
|
||||
* {@link org.luaj.vm2.lib.jse.JseIoLib}.
|
||||
* <p>
|
||||
* To instantiate and use it directly,
|
||||
* link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
|
||||
@@ -67,10 +67,10 @@ import org.luaj.vm2.Varargs;
|
||||
* <p>
|
||||
* This has been implemented to match as closely as possible the behavior in the corresponding library in C.
|
||||
* @see LibFunction
|
||||
* @see JsePlatform
|
||||
* @see JmePlatform
|
||||
* @see JseIoLib
|
||||
* @see JmeIoLib
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JseIoLib
|
||||
* @see org.luaj.vm2.lib.jme.JmeIoLib
|
||||
* @see <a href="http://www.lua.org/manual/5.1/manual.html#5.7">http://www.lua.org/manual/5.1/manual.html#5.7</a>
|
||||
*/
|
||||
abstract
|
||||
|
||||
@@ -51,12 +51,14 @@ import org.luaj.vm2.Varargs;
|
||||
* hand for JME, so will be slower and less accurate than when executed on the JSE platform.
|
||||
* <p>
|
||||
* Typically, this library is included as part of a call to either
|
||||
* {@link JsePlatform#standardGlobals()} or {@link JmePlatform#standardGlobals()}
|
||||
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or
|
||||
* {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()}
|
||||
* <pre> {@code
|
||||
* Globals globals = JsePlatform.standardGlobals();
|
||||
* System.out.println( globals.get("math").get("sqrt").call( LuaValue.valueOf(2) ) );
|
||||
* } </pre>
|
||||
* When using {@link JsePlaform} as in this example, the subclass {@link JseMathLib} will
|
||||
* When using {@link org.luaj.vm2.lib.jse.JsePlatform} as in this example,
|
||||
* the subclass {@link org.luaj.vm2.lib.jse.JseMathLib} will
|
||||
* be included, which also includes this base functionality.
|
||||
* <p>
|
||||
* To instantiate and use it directly,
|
||||
@@ -73,9 +75,9 @@ import org.luaj.vm2.Varargs;
|
||||
* <p>
|
||||
* This has been implemented to match as closely as possible the behavior in the corresponding library in C.
|
||||
* @see LibFunction
|
||||
* @see JsePlatform
|
||||
* @see JmePlatform
|
||||
* @see JseMathLib
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JseMathLib
|
||||
* @see <a href="http://www.lua.org/manual/5.2/manual.html#6.6">Lua 5.2 Math Lib Reference</a>
|
||||
*/
|
||||
public class MathLib extends TwoArgFunction {
|
||||
|
||||
@@ -55,12 +55,12 @@ import org.luaj.vm2.Varargs;
|
||||
* </ul>
|
||||
* <p>
|
||||
* Typically, this library is included as part of a call to either
|
||||
* {@link JsePlatform#standardGlobals()} or {@link JmePlatform#standardGlobals()}
|
||||
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()}
|
||||
* <pre> {@code
|
||||
* Globals globals = JsePlatform.standardGlobals();
|
||||
* System.out.println( globals.get("os").get("time").call() );
|
||||
* } </pre>
|
||||
* In this example the platform-specific {@link JseOsLib} library will be loaded, which will include
|
||||
* In this example the platform-specific {@link org.luaj.vm2.lib.jse.JseOsLib} library will be loaded, which will include
|
||||
* the base functionality provided by this class.
|
||||
* <p>
|
||||
* To instantiate and use it directly,
|
||||
@@ -74,9 +74,9 @@ import org.luaj.vm2.Varargs;
|
||||
* } </pre>
|
||||
* <p>
|
||||
* @see LibFunction
|
||||
* @see JseOsLib
|
||||
* @see JsePlatform
|
||||
* @see JmePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JseOsLib
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see <a href="http://www.lua.org/manual/5.1/manual.html#5.8">http://www.lua.org/manual/5.1/manual.html#5.8</a>
|
||||
*/
|
||||
public class OsLib extends TwoArgFunction {
|
||||
|
||||
@@ -51,7 +51,7 @@ import org.luaj.vm2.Varargs;
|
||||
*
|
||||
* <h3>Loading</h3>
|
||||
* Typically, this library is included as part of a call to either
|
||||
* {@link JsePlatform#standardGlobals()} or {@link JmePlatform#standardGlobals()}
|
||||
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()}
|
||||
* <pre> {@code
|
||||
* Globals globals = JsePlatform.standardGlobals();
|
||||
* System.out.println( globals.get("require").call"foo") );
|
||||
@@ -68,13 +68,13 @@ import org.luaj.vm2.Varargs;
|
||||
* <h3>Limitations</h3>
|
||||
* This library has been implemented to match as closely as possible the behavior in the corresponding library in C.
|
||||
* However, the default filesystem search semantics are different and delegated to the bas library
|
||||
* as outlined in the {@link BaseLib} and {@link JseBaseLib} documentation.
|
||||
* as outlined in the {@link BaseLib} and {@link org.luaj.vm2.lib.jse.JseBaseLib} documentation.
|
||||
* <p>
|
||||
* @see LibFunction
|
||||
* @see BaseLib
|
||||
* @see JseBaseLib
|
||||
* @see JsePlatform
|
||||
* @see JmePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JseBaseLib
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see <a href="http://www.lua.org/manual/5.2/manual.html#6.3">Lua 5.2 Package Lib Reference</a>
|
||||
*/
|
||||
public class PackageLib extends TwoArgFunction {
|
||||
@@ -105,7 +105,7 @@ public class PackageLib extends TwoArgFunction {
|
||||
/** The table for this package. */
|
||||
LuaTable package_;
|
||||
|
||||
/** Loader that loads from {@link preload} table if found there */
|
||||
/** Loader that loads from {@code preload} table if found there */
|
||||
public preload_searcher preload_searcher;
|
||||
|
||||
/** Loader that loads as a lua script using the lua path currently in {@link path} */
|
||||
|
||||
@@ -23,6 +23,8 @@ package org.luaj.vm2.lib;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.luaj.vm2.Globals;
|
||||
|
||||
/**
|
||||
* Interface for opening application resource files such as scripts sources.
|
||||
* <p>
|
||||
@@ -32,15 +34,15 @@ import java.io.InputStream;
|
||||
* <p>
|
||||
* The Jme version of base lib {@link BaseLib}
|
||||
* implements {@link Globals#finder} via {@link Class#getResourceAsStream(String)},
|
||||
* while the Jse version {@link JseBaseLib} implements it using {@link java.io.File#File(String)}.
|
||||
* while the Jse version {@link org.luaj.vm2.lib.jse.JseBaseLib} implements it using {@link java.io.File#File(String)}.
|
||||
* <p>
|
||||
* The io library does not use this API for file manipulation.
|
||||
* <p>
|
||||
* @see BaseLib
|
||||
* @see Globals#finder
|
||||
* @see JseBaseLib
|
||||
* @see JmePlatform
|
||||
* @see JsePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JseBaseLib
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
*/
|
||||
public interface ResourceFinder {
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.luaj.vm2.compiler.DumpState;
|
||||
* library.
|
||||
* <p>
|
||||
* Typically, this library is included as part of a call to either
|
||||
* {@link JsePlatform#standardGlobals()} or {@link JmePlatform#standardGlobals()}
|
||||
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()}
|
||||
* <pre> {@code
|
||||
* Globals globals = JsePlatform.standardGlobals();
|
||||
* System.out.println( globals.get("string").get("upper").call( LuaValue.valueOf("abcde") ) );
|
||||
@@ -55,8 +55,8 @@ import org.luaj.vm2.compiler.DumpState;
|
||||
* <p>
|
||||
* This is a direct port of the corresponding library in C.
|
||||
* @see LibFunction
|
||||
* @see JsePlatform
|
||||
* @see JmePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see <a href="http://www.lua.org/manual/5.2/manual.html#6.4">Lua 5.2 String Lib Reference</a>
|
||||
*/
|
||||
public class StringLib extends TwoArgFunction {
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.luaj.vm2.Varargs;
|
||||
*
|
||||
* <p>
|
||||
* Typically, this library is included as part of a call to either
|
||||
* {@link JsePlatform#standardGlobals()} or {@link JmePlatform#standardGlobals()}
|
||||
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()}
|
||||
* <pre> {@code
|
||||
* Globals globals = JsePlatform.standardGlobals();
|
||||
* System.out.println( globals.get("table").get("length").call( LuaValue.tableOf() ) );
|
||||
@@ -49,8 +49,8 @@ import org.luaj.vm2.Varargs;
|
||||
* <p>
|
||||
* This has been implemented to match as closely as possible the behavior in the corresponding library in C.
|
||||
* @see LibFunction
|
||||
* @see JsePlatform
|
||||
* @see JmePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see <a href="http://www.lua.org/manual/5.2/manual.html#6.5">Lua 5.2 Table Lib Reference</a>
|
||||
*/
|
||||
public class TableLib extends TwoArgFunction {
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.luaj.vm2.Varargs;
|
||||
* simplifying development.
|
||||
* All other uses of {@link #call(LuaValue)}, {@link #invoke()},etc,
|
||||
* are routed through this method by this class,
|
||||
* converting arguments to {@linnk Varargs} and
|
||||
* converting arguments to {@link Varargs} and
|
||||
* dropping or extending return values with {@code nil} values as required.
|
||||
* <p>
|
||||
* If between one and three arguments are required, and only one return value is returned,
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.io.OutputStream;
|
||||
import javax.microedition.io.Connector;
|
||||
import javax.microedition.io.StreamConnection;
|
||||
|
||||
import org.luaj.vm2.Globals;
|
||||
import org.luaj.vm2.LuaString;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.lib.IoLib;
|
||||
@@ -41,7 +42,7 @@ import org.luaj.vm2.lib.LibFunction;
|
||||
* However, seek is not supported.
|
||||
* <p>
|
||||
* Typically, this library is included as part of a call to
|
||||
* {@link JmePlatform#standardGlobals()}
|
||||
* {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()}
|
||||
* <pre> {@code
|
||||
* Globals globals = JmePlatform.standardGlobals();
|
||||
* globals.get("io").get("write").call(LuaValue.valueOf("hello, world\n"));
|
||||
@@ -62,9 +63,9 @@ import org.luaj.vm2.lib.LibFunction;
|
||||
* This has been implemented to match as closely as possible the behavior in the corresponding library in C.
|
||||
* @see LibFunction
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see JmePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see IoLib
|
||||
* @see JseIoLib
|
||||
* @see org.luaj.vm2.lib.jse.JseIoLib
|
||||
* @see <a href="http://www.lua.org/manual/5.2/manual.html#6.8">Lua 5.2 I/O Lib Reference</a>
|
||||
*/
|
||||
public class JmeIoLib extends IoLib {
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
******************************************************************************/
|
||||
package org.luaj.vm2.lib.jme;
|
||||
|
||||
import org.luaj.vm2.compiler.LuaC;
|
||||
import org.luaj.vm2.Globals;
|
||||
import org.luaj.vm2.LoadState;
|
||||
import org.luaj.vm2.LuaThread;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.compiler.LuaC;
|
||||
import org.luaj.vm2.lib.BaseLib;
|
||||
import org.luaj.vm2.lib.Bit32Lib;
|
||||
import org.luaj.vm2.lib.CoroutineLib;
|
||||
@@ -33,10 +33,11 @@ import org.luaj.vm2.lib.DebugLib;
|
||||
import org.luaj.vm2.lib.MathLib;
|
||||
import org.luaj.vm2.lib.OsLib;
|
||||
import org.luaj.vm2.lib.PackageLib;
|
||||
import org.luaj.vm2.lib.ResourceFinder;
|
||||
import org.luaj.vm2.lib.StringLib;
|
||||
import org.luaj.vm2.lib.TableLib;
|
||||
|
||||
/** The {@link JmePlatform} class is a convenience class to standardize
|
||||
/** The {@link org.luaj.vm2.lib.jme.JmePlatform} class is a convenience class to standardize
|
||||
* how globals tables are initialized for the JME platform.
|
||||
* <p>
|
||||
* The JME platform, being limited, cannot implement all libraries in all aspects. The main limitations are
|
||||
@@ -44,8 +45,8 @@ import org.luaj.vm2.lib.TableLib;
|
||||
* <li>Some math functions are not implemented, see {@link MathLib} for details</li>
|
||||
* <li>Scripts are loaded via Class.getResourceAsStream(), see {@link BaseLib} for details</li>
|
||||
* <li>OS functions execute(), remove(), rename(), and tmpname() vary, see {@link OsLib} for details</li>
|
||||
* <li>I/O seek is not implemented, see {@link JmeIoLib} for details</li>
|
||||
* <li>luajava is not available, see {@link LuajavaLib} for details</li>
|
||||
* <li>I/O seek is not implemented, see {@link org.luaj.vm2.lib.jme.JmeIoLib} for details</li>
|
||||
* <li>luajava is not available, see {@link org.luaj.vm2.lib.jse.LuajavaLib} for details</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* It is used to allocate either a set of standard globals using
|
||||
@@ -79,7 +80,7 @@ import org.luaj.vm2.lib.TableLib;
|
||||
* <li>{@link StringLib}</li>
|
||||
* <li>{@link CoroutineLib}</li>
|
||||
* <li>{@link MathLib}</li>
|
||||
* <li>{@link JmeIoLib}</li>
|
||||
* <li>{@link org.luaj.vm2.lib.jme.JmeIoLib}</li>
|
||||
* <li>{@link OsLib}</li>
|
||||
* </ul>
|
||||
* In addition, the {@link LuaC} compiler is installed so lua files may be loaded in their source form.
|
||||
@@ -87,10 +88,10 @@ import org.luaj.vm2.lib.TableLib;
|
||||
* The debug globals are simply the standard globals plus the {@code debug} library {@link DebugLib}.
|
||||
* <p>
|
||||
* <p>
|
||||
* The class ensures that initialization is done in the correct order,
|
||||
* and that linkage is made to {@link LuaThread#setGlobals(LuaValue)}.
|
||||
* @see JsePlatform
|
||||
* @see LoadState
|
||||
* The class ensures that initialization is done in the correct order.
|
||||
*
|
||||
* @see Globals
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
*/
|
||||
public class JmePlatform {
|
||||
|
||||
@@ -99,8 +100,8 @@ public class JmePlatform {
|
||||
*
|
||||
* @return Table of globals initialized with the standard JME libraries
|
||||
* @see #debugGlobals()
|
||||
* @see JsePlatform
|
||||
* @see JmePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
*/
|
||||
public static Globals standardGlobals() {
|
||||
Globals globals = new Globals();
|
||||
@@ -118,12 +119,12 @@ public class JmePlatform {
|
||||
return globals;
|
||||
}
|
||||
|
||||
/** Create standard globals including the {@link debug} library.
|
||||
/** Create standard globals including the {@link DebugLib} library.
|
||||
*
|
||||
* @return Table of globals initialized with the standard JSE and debug libraries
|
||||
* @see #standarsGlobals()
|
||||
* @see JsePlatform
|
||||
* @see JmePlatform
|
||||
* @see #standardGlobals()
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see DebugLib
|
||||
*/
|
||||
public static Globals debugGlobals() {
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.luaj.vm2.LuaValue;
|
||||
/**
|
||||
* Helper class to coerce values from Java to lua within the luajava library.
|
||||
* <p>
|
||||
* This class is primarily used by the {@link LuajavaLib},
|
||||
* This class is primarily used by the {@link org.luaj.vm2.lib.jse.LuajavaLib},
|
||||
* but can also be used directly when working with Java/lua bindings.
|
||||
* <p>
|
||||
* To coerce scalar types, the various, generally the {@code valueOf(type)} methods
|
||||
@@ -59,7 +59,7 @@ import org.luaj.vm2.LuaValue;
|
||||
* table, or table of tables.
|
||||
*
|
||||
* @see CoerceJavaToLua#coerce(Object)
|
||||
* @see LuajavaLib
|
||||
* @see org.luaj.vm2.lib.jse.LuajavaLib
|
||||
*/
|
||||
public class CoerceJavaToLua {
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.luaj.vm2.LuaValue;
|
||||
/**
|
||||
* Helper class to coerce values from lua to Java within the luajava library.
|
||||
* <p>
|
||||
* This class is primarily used by the {@link LuajavaLib},
|
||||
* This class is primarily used by the {@link org.luaj.vm2.lib.jse.LuajavaLib},
|
||||
* but can also be used directly when working with Java/lua bindings.
|
||||
* <p>
|
||||
* To coerce to specific Java values, generally the {@code toType()} methods
|
||||
@@ -54,7 +54,7 @@ import org.luaj.vm2.LuaValue;
|
||||
* For data in lua tables, the various methods on {@link LuaTable} can be used directly
|
||||
* to convert data to something more useful.
|
||||
*
|
||||
* @see LuajavaLib
|
||||
* @see org.luaj.vm2.lib.jse.LuajavaLib
|
||||
* @see CoerceJavaToLua
|
||||
*/
|
||||
public class CoerceLuaToJava {
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.luaj.vm2.Globals;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.lib.BaseLib;
|
||||
import org.luaj.vm2.lib.LibFunction;
|
||||
@@ -33,16 +34,16 @@ import org.luaj.vm2.lib.ResourceFinder;
|
||||
|
||||
/**
|
||||
* Subclass of {@link BaseLib} and {@link LibFunction} which implements the lua basic library functions
|
||||
* and provides a directory based {@link ResourceFinder} as the {@link #finder}.
|
||||
* and provides a directory based {@link ResourceFinder} as the {@link Globals#finder}.
|
||||
* <p>
|
||||
* Since JME has no file system by default, {@link BaseLib} implements
|
||||
* {@link ResourceFinder} using {@link Class#getResource(String)}.
|
||||
* The {@link JseBaseLib} implements {@link finder} by scanning the current directory
|
||||
* The {@link org.luaj.vm2.lib.jse.JseBaseLib} implements {@link Globals#finder} by scanning the current directory
|
||||
* first, then falling back to {@link Class#getResource(String)} if that fails.
|
||||
* Otherwise, the behavior is the same as that of {@link BaseLib}.
|
||||
* <p>
|
||||
* Typically, this library is included as part of a call to
|
||||
* {@link JsePlatform#standardGlobals()}
|
||||
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()}
|
||||
* <pre> {@code
|
||||
* Globals globals = JsePlatform.standardGlobals();
|
||||
* globals.get("print").call(LuaValue.valueOf("hello, world"));
|
||||
@@ -62,9 +63,9 @@ import org.luaj.vm2.lib.ResourceFinder;
|
||||
* @see Globals
|
||||
* @see BaseLib
|
||||
* @see ResourceFinder
|
||||
* @see {@link Globals.finder}
|
||||
* @see Globals#finder
|
||||
* @see LibFunction
|
||||
* @see JsePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see <a href="http://www.lua.org/manual/5.2/manual.html#6.1">Lua 5.2 Base Lib Reference</a>
|
||||
*/
|
||||
@@ -75,7 +76,7 @@ public class JseBaseLib extends org.luaj.vm2.lib.BaseLib {
|
||||
/** Perform one-time initialization on the library by creating a table
|
||||
* containing the library functions, adding that table to the supplied environment,
|
||||
* adding the table to package.loaded, and returning table as the return value.
|
||||
* <P>Specifically, extend the library loading to set the default value for {@link Globals.STDIN}
|
||||
* <P>Specifically, extend the library loading to set the default value for {@link Globals#STDIN}
|
||||
* @param modname the module name supplied if this is loaded via 'require'.
|
||||
* @param env the environment to load into, which must be a Globals instance.
|
||||
*/
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
import org.luaj.vm2.Globals;
|
||||
import org.luaj.vm2.LuaError;
|
||||
import org.luaj.vm2.LuaString;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
@@ -42,7 +43,7 @@ import org.luaj.vm2.lib.LibFunction;
|
||||
* It uses RandomAccessFile to implement seek on files.
|
||||
* <p>
|
||||
* Typically, this library is included as part of a call to
|
||||
* {@link JsePlatform#standardGlobals()}
|
||||
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()}
|
||||
* <pre> {@code
|
||||
* Globals globals = JsePlatform.standardGlobals();
|
||||
* globals.get("io").get("write").call(LuaValue.valueOf("hello, world\n"));
|
||||
@@ -62,10 +63,10 @@ import org.luaj.vm2.lib.LibFunction;
|
||||
* <p>
|
||||
* This has been implemented to match as closely as possible the behavior in the corresponding library in C.
|
||||
* @see LibFunction
|
||||
* @see JsePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see IoLib
|
||||
* @see JmeIoLib
|
||||
* @see org.luaj.vm2.lib.jme.JmeIoLib
|
||||
* @see <a href="http://www.lua.org/manual/5.2/manual.html#6.8">Lua 5.2 I/O Lib Reference</a>
|
||||
*/
|
||||
public class JseIoLib extends IoLib {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
******************************************************************************/
|
||||
package org.luaj.vm2.lib.jse;
|
||||
|
||||
import org.luaj.vm2.Globals;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.lib.LibFunction;
|
||||
|
||||
@@ -29,10 +30,10 @@ import org.luaj.vm2.lib.LibFunction;
|
||||
* library.
|
||||
* <p>
|
||||
* It contains all lua math functions, including those not available on the JME platform.
|
||||
* See {@link org.luaj.lib.MathLib} for the exception list.
|
||||
* See {@link org.luaj.vm2.lib.MathLib} for the exception list.
|
||||
* <p>
|
||||
* Typically, this library is included as part of a call to
|
||||
* {@link JsePlatform#standardGlobals()}
|
||||
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()}
|
||||
* <pre> {@code
|
||||
* Globals globals = JsePlatform.standardGlobals();
|
||||
* System.out.println( globals.get("math").get("sqrt").call( LuaValue.valueOf(2) ) );
|
||||
@@ -52,9 +53,9 @@ import org.luaj.vm2.lib.LibFunction;
|
||||
* <p>
|
||||
* This has been implemented to match as closely as possible the behavior in the corresponding library in C.
|
||||
* @see LibFunction
|
||||
* @see JsePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see JseMathLib
|
||||
* @see org.luaj.vm2.lib.jse.JseMathLib
|
||||
* @see <a href="http://www.lua.org/manual/5.2/manual.html#6.6">Lua 5.2 Math Lib Reference</a>
|
||||
*/
|
||||
public class JseMathLib extends org.luaj.vm2.lib.MathLib {
|
||||
|
||||
@@ -24,9 +24,11 @@ package org.luaj.vm2.lib.jse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.luaj.vm2.Globals;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.Varargs;
|
||||
import org.luaj.vm2.lib.LibFunction;
|
||||
import org.luaj.vm2.lib.OsLib;
|
||||
|
||||
/**
|
||||
* Subclass of {@link LibFunction} which implements the standard lua {@code os} library.
|
||||
@@ -45,7 +47,7 @@ import org.luaj.vm2.lib.LibFunction;
|
||||
* from their counterparts in the C platform.
|
||||
* <p>
|
||||
* Typically, this library is included as part of a call to
|
||||
* {@link JsePlatform#standardGlobals()}
|
||||
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()}
|
||||
* <pre> {@code
|
||||
* Globals globals = JsePlatform.standardGlobals();
|
||||
* System.out.println( globals.get("os").get("time").call() );
|
||||
@@ -65,7 +67,7 @@ import org.luaj.vm2.lib.LibFunction;
|
||||
* <p>
|
||||
* @see LibFunction
|
||||
* @see OsLib
|
||||
* @see JsePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see <a href="http://www.lua.org/manual/5.2/manual.html#6.9">Lua 5.2 OS Lib Reference</a>
|
||||
*/
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.luaj.vm2.lib.ResourceFinder;
|
||||
import org.luaj.vm2.lib.StringLib;
|
||||
import org.luaj.vm2.lib.TableLib;
|
||||
|
||||
/** The {@link JsePlatform} class is a convenience class to standardize
|
||||
/** The {@link org.luaj.vm2.lib.jse.JsePlatform} class is a convenience class to standardize
|
||||
* how globals tables are initialized for the JSE platform.
|
||||
* <p>
|
||||
* It is used to allocate either a set of standard globals using
|
||||
@@ -56,29 +56,30 @@ import org.luaj.vm2.lib.TableLib;
|
||||
* globals.get("require").call(LuaValue.valueOf("main"));
|
||||
* } </pre>
|
||||
* For this to succeed, the file "main.lua" must be in the current directory or a resource.
|
||||
* See {@link JseBaseLib} for details on finding scripts using {@link ResourceFinder}.
|
||||
* See {@link org.luaj.vm2.lib.jse.JseBaseLib} for details on finding scripts using {@link ResourceFinder}.
|
||||
* <p>
|
||||
* The standard globals will contain all standard libraries plus {@code luajava}:
|
||||
* <ul>
|
||||
* <li>{@link Globals}</li>
|
||||
* <li>{@link JseBaseLib}</li>
|
||||
* <li>{@link org.luaj.vm2.lib.jse.JseBaseLib}</li>
|
||||
* <li>{@link PackageLib}</li>
|
||||
* <li>{@link Bit32Lib}</li>
|
||||
* <li>{@link TableLib}</li>
|
||||
* <li>{@link StringLib}</li>
|
||||
* <li>{@link CoroutineLib}</li>
|
||||
* <li>{@link JseMathLib}</li>
|
||||
* <li>{@link JseIoLib}</li>
|
||||
* <li>{@link JseOsLib}</li>
|
||||
* <li>{@link LuajavaLib}</li>
|
||||
* <li>{@link org.luaj.vm2.lib.jse.JseMathLib}</li>
|
||||
* <li>{@link org.luaj.vm2.lib.jse.JseIoLib}</li>
|
||||
* <li>{@link org.luaj.vm2.lib.jse.JseOsLib}</li>
|
||||
* <li>{@link org.luaj.vm2.lib.jse.LuajavaLib}</li>
|
||||
* </ul>
|
||||
* In addition, the {@link LuaC} compiler is installed so lua files may be loaded in their source form.
|
||||
* <p>
|
||||
* The debug globals are simply the standard globals plus the {@code debug} library {@link DebugLib}.
|
||||
* <p>
|
||||
* The class ensures that initialization is done in the correct order,
|
||||
* and that linkage is made to {@link LuaThread#setGlobals(LuaValue)}.
|
||||
* @see JmePlatform
|
||||
* The class ensures that initialization is done in the correct order.
|
||||
*
|
||||
* @see Globals
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
*/
|
||||
public class JsePlatform {
|
||||
|
||||
@@ -87,8 +88,8 @@ public class JsePlatform {
|
||||
*
|
||||
* @return Table of globals initialized with the standard JSE libraries
|
||||
* @see #debugGlobals()
|
||||
* @see JsePlatform
|
||||
* @see JmePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
*/
|
||||
public static Globals standardGlobals() {
|
||||
Globals globals = new Globals();
|
||||
@@ -107,12 +108,12 @@ public class JsePlatform {
|
||||
return globals;
|
||||
}
|
||||
|
||||
/** Create standard globals including the {@link debug} library.
|
||||
/** Create standard globals including the {@link DebugLib} library.
|
||||
*
|
||||
* @return Table of globals initialized with the standard JSE and debug libraries
|
||||
* @see #standardGlobals()
|
||||
* @see JsePlatform
|
||||
* @see JmePlatform
|
||||
* @see org.luaj.vm2.lib.jse.JsePlatform
|
||||
* @see org.luaj.vm2.lib.jme.JmePlatform
|
||||
* @see DebugLib
|
||||
*/
|
||||
public static Globals debugGlobals() {
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
import org.luaj.vm2.Globals;
|
||||
import org.luaj.vm2.LuaError;
|
||||
import org.luaj.vm2.LuaTable;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
@@ -45,7 +46,7 @@ import org.luaj.vm2.lib.VarArgFunction;
|
||||
*
|
||||
* <p>
|
||||
* Typically, this library is included as part of a call to
|
||||
* {@link JsePlatform#standardGlobals()}
|
||||
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()}
|
||||
* <pre> {@code
|
||||
* Globals globals = JsePlatform.standardGlobals();
|
||||
* System.out.println( globals.get("luajava").get("bindClass").call( LuaValue.valueOf("java.lang.System") ).invokeMethod("currentTimeMillis") );
|
||||
@@ -65,7 +66,7 @@ import org.luaj.vm2.lib.VarArgFunction;
|
||||
* <p>
|
||||
*
|
||||
* The {@code luajava} library is available
|
||||
* on all JSE platforms via the call to {@link JsePlatform#standardGlobals()}
|
||||
* on all JSE platforms via the call to {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()}
|
||||
* and the luajava api's are simply invoked from lua.
|
||||
* Because it makes extensive use of Java's reflection API, it is not available
|
||||
* on JME, but can be used in Android applications.
|
||||
|
||||
@@ -27,18 +27,18 @@ import java.io.Reader;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import org.luaj.vm2.Globals;
|
||||
import org.luaj.vm2.LoadState;
|
||||
import org.luaj.vm2.LuaClosure;
|
||||
import org.luaj.vm2.LuaFunction;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.Prototype;
|
||||
import org.luaj.vm2.compiler.LuaC;
|
||||
import org.luaj.vm2.lib.BaseLib;
|
||||
|
||||
/**
|
||||
* Implementation of {@link LuaCompiler} which does direct
|
||||
* Implementation of {@link org.luaj.vm2.Globals.Compiler} which does direct
|
||||
* lua-to-java-bytecode compiling.
|
||||
* <p>
|
||||
* By default, when using {@link JsePlatform} or {@JmePlatform}
|
||||
* By default, when using {@link org.luaj.vm2.lib.jse.JsePlatform} or
|
||||
* {@link org.luaj.vm2.lib.jme.JmePlatform}
|
||||
* to construct globals, the plain compiler {@link LuaC} is installed and lua code
|
||||
* will only be compiled into lua bytecode and execute as {@link LuaClosure}.
|
||||
* <p>
|
||||
@@ -57,9 +57,9 @@ import org.luaj.vm2.lib.BaseLib;
|
||||
* If the library is not found, the default {@link LuaC} lua-to-lua-bytecode
|
||||
* compiler will be used.
|
||||
*
|
||||
* @see LuaCompiler
|
||||
* @see LuaC
|
||||
* @see BaseLib
|
||||
* @see Globals#compiler
|
||||
* @see #install(Globals)
|
||||
* @see org.luaj.vm2.compiler.LuaC
|
||||
* @see LuaValue
|
||||
*/
|
||||
public class LuaJC implements Globals.Loader {
|
||||
|
||||
Reference in New Issue
Block a user