diff --git a/README.md b/README.md index 82718b32..5ee2b427 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ Attribution XPrivacyLua uses: -* [LuaJ](https://sourceforge.net/projects/luaj/). Copyright 2007-2013 LuaJ. All rights reserved. See [license](http://luaj.sourceforge.net/license.txt). +* [LuaJ](https://github.com/luaj/luaj). Copyright 2007-2013 LuaJ. All rights reserved. See [license](http://luaj.sourceforge.net/license.txt). * [Glide](https://bumptech.github.io/glide/). Copyright 2014 Google, Inc. All rights reserved. See [license](https://raw.githubusercontent.com/bumptech/glide/master/LICENSE). * [Android Support Library](https://developer.android.com/tools/support-library/). Copyright (C) 2011 The Android Open Source Project. See [license](https://android.googlesource.com/platform/frameworks/support/+/master/LICENSE.txt). diff --git a/app/src/main/java/org/luaj/vm2/Lua.java b/app/src/main/java/org/luaj/vm2/Lua.java index 9b9b0ce1..7a57841e 100644 --- a/app/src/main/java/org/luaj/vm2/Lua.java +++ b/app/src/main/java/org/luaj/vm2/Lua.java @@ -23,14 +23,14 @@ /** - * Constants for lua limits and opcodes. + * Constants for lua limits and opcodes. *
* This is a direct translation of C lua distribution header file constants
- * for bytecode creation and processing.
+ * for bytecode creation and processing.
*/
public class Lua {
/** version is supplied by ant build task */
- public static final String _VERSION = "Luaj 0.0";
+ public static final String _VERSION = "Luaj-jse 3.0.2";
/** use return values from previous op */
public static final int LUA_MULTRET = -1;
@@ -80,7 +80,6 @@ public class Lua {
public static final int POS_Bx = POS_C;
public static final int POS_Ax = POS_A;
-
public static final int MAX_OP = ((1<
- * A {@link LuaClosure} is a combination of a {@link Prototype}
+ * A {@link LuaClosure} is a combination of a {@link Prototype}
* and a {@link LuaValue} to use as an environment for execution.
* Normally the {@link LuaValue} is a {@link Globals} in which case the environment
- * will contain standard lua libraries.
+ * will contain standard lua libraries.
*
*
* There are three main ways {@link LuaClosure} instances are created:
- *
- * To construct it directly, the {@link Prototype} is typically created via a compiler such as
+ * To construct it directly, the {@link Prototype} is typically created via a compiler such as
* {@link org.luaj.vm2.compiler.LuaC}:
*
- * To construct it indirectly, the {@link Globals#load(java.io.Reader, String)} method may be used:
+ * To construct it indirectly, the {@link Globals#load(java.io.Reader, String)} method may be used:
*
- * In this example, the "checkclosure()" may fail if direct lua-to-java-bytecode
+ * In this example, the "checkclosure()" may fail if direct lua-to-java-bytecode
* compiling using LuaJC is installed, because no LuaClosure is created in that case
* and the value returned is a {@link LuaFunction} but not a {@link LuaClosure}.
- *
- * Since a {@link LuaClosure} is a {@link LuaFunction} which is a {@link LuaValue},
+ *
+ * Since a {@link LuaClosure} is a {@link LuaFunction} which is a {@link LuaValue},
* all the value operations can be used directly such as:
*
* Establishes base implementations for all the operations on lua types.
* This allows Java clients to deal essentially with one type for all Java values, namely {@link LuaValue}.
*
- * Constructors are provided as static methods for common Java types, such as
- * {@link LuaValue#valueOf(int)} or {@link LuaValue#valueOf(String)}
- * to allow for instance pooling.
- *
- * Constants are defined for the lua values
- * {@link #NIL}, {@link #TRUE}, and {@link #FALSE}.
+ * Constructors are provided as static methods for common Java types, such as
+ * {@link LuaValue#valueOf(int)} or {@link LuaValue#valueOf(String)}
+ * to allow for instance pooling.
+ *
+ * Constants are defined for the lua values
+ * {@link #NIL}, {@link #TRUE}, and {@link #FALSE}.
* A constant {@link #NONE} is defined which is a {@link Varargs} list having no values.
- *
- * Operations are performed on values directly via their Java methods.
+ *
+ * Operations are performed on values directly via their Java methods.
* For example, the following code divides two numbers:
*
* Field access and function calls are similar, with common overloads to simplify Java usage:
*
- * To supply variable arguments or get multiple return values, use
+ * To supply variable arguments or get multiple return values, use
* {@link #invoke(Varargs)} or {@link #invokemethod(LuaValue, Varargs)} methods:
*
- * although {@code require} could also be used:
+ * although {@code require} could also be used:
*
- * In general a {@link LuaError} may be thrown on any operation when the
- * types supplied to any operation are illegal from a lua perspective.
- * Examples could be attempting to concatenate a NIL value, or attempting arithmetic
- * on values that are not number.
+ * In general a {@link LuaError} may be thrown on any operation when the
+ * types supplied to any operation are illegal from a lua perspective.
+ * Examples could be attempting to concatenate a NIL value, or attempting arithmetic
+ * on values that are not number.
*
* There are several methods for preinitializing tables, such as:
*
- * Predefined constants exist for the standard lua type constants
- * {@link #TNIL}, {@link #TBOOLEAN}, {@link #TLIGHTUSERDATA}, {@link #TNUMBER}, {@link #TSTRING},
+ *
+ * Predefined constants exist for the standard lua type constants
+ * {@link #TNIL}, {@link #TBOOLEAN}, {@link #TLIGHTUSERDATA}, {@link #TNUMBER}, {@link #TSTRING},
* {@link #TTABLE}, {@link #TFUNCTION}, {@link #TUSERDATA}, {@link #TTHREAD},
- * and extended lua type constants
+ * and extended lua type constants
* {@link #TINT}, {@link #TNONE}, {@link #TVALUE}
- *
- * Predefined constants exist for all strings used as metatags:
- * {@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},
+ *
+ * Predefined constants exist for all strings used as metatags:
+ * {@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 #LE}, {@link #TOSTRING}, and {@link #CONCAT}.
*
* @see org.luaj.vm2.lib.jse.JsePlatform
* @see org.luaj.vm2.lib.jme.JmePlatform
- * @see LoadState
+ * @see LoadState
* @see Varargs
*/
abstract
@@ -149,10 +147,10 @@ public class LuaValue extends Varargs {
/** String array constant containing names of each of the lua value types
* @see #type()
- * @see #typename()
+ * @see #typename()
*/
public static final String[] TYPE_NAMES = {
- "nil",
+ "nil",
"boolean",
"lightuserdata",
"number",
@@ -251,10 +249,10 @@ public class LuaValue extends Varargs {
/** Limit on lua stack size */
private static int MAXSTACK = 250;
- /** Array of {@link #NIL} values to optimize filling stacks using System.arraycopy().
- * Must not be modified.
+ /** Array of {@link #NIL} values to optimize filling stacks using System.arraycopy().
+ * Must not be modified.
*/
- public static final LuaValue[] NILS = new LuaValue[MAXSTACK];
+ public static final LuaValue[] NILS = new LuaValue[MAXSTACK];
static {
for ( int i=0; i
- * No attempt to convert from string will be made by this call.
- * @return true if this is a {@code LuaInteger},
+ * No attempt to convert from string will be made by this call.
+ * @return true if this is a {@code LuaInteger},
* otherwise false
* @see #isint()
* @see #isnumber()
@@ -343,12 +341,12 @@ public class LuaValue extends Varargs {
*/
public boolean isinttype() { return false; }
- /** Check if {@code this} is a {@code number} and is representable by java long
+ /** Check if {@code this} is a {@code number} and is representable by java long
* without rounding or truncation
- * @return true if this is a {@code number}
- * meaning derives from {@link LuaNumber}
+ * @return true if this is a {@code number}
+ * meaning derives from {@link LuaNumber}
* or derives from {@link LuaString} and is convertible to a number,
- * and can be represented by long,
+ * and can be represented by long,
* otherwise false
* @see #tonumber()
* @see #checklong()
@@ -370,9 +368,9 @@ public class LuaValue extends Varargs {
public boolean isnil() { return false; }
/** Check if {@code this} is a {@code number}
- * @return true if this is a {@code number},
- * meaning derives from {@link LuaNumber}
- * or derives from {@link LuaString} and is convertible to a number,
+ * @return true if this is a {@code number},
+ * meaning derives from {@link LuaNumber}
+ * or derives from {@link LuaString} and is convertible to a number,
* otherwise false
* @see #tonumber()
* @see #checknumber()
@@ -382,8 +380,8 @@ public class LuaValue extends Varargs {
public boolean isnumber() { return false; } // may convert from string
/** Check if {@code this} is a {@code string}
- * @return true if this is a {@code string},
- * meaning derives from {@link LuaString} or {@link LuaNumber},
+ * @return true if this is a {@code string},
+ * meaning derives from {@link LuaString} or {@link LuaNumber},
* otherwise false
* @see #tostring()
* @see #checkstring()
@@ -420,8 +418,8 @@ public class LuaValue extends Varargs {
/** Check if {@code this} is a {@code userdata} of type {@code c}
* @param c Class to test instance against
- * @return true if this is a {@code userdata}
- * and the instance is assignable to {@code c},
+ * @return true if this is a {@code userdata}
+ * and the instance is assignable to {@code c},
* otherwise false
* @see #isuserdata()
* @see #touserdata(Class)
@@ -434,14 +432,14 @@ public class LuaValue extends Varargs {
/** Convert to boolean false if {@link #NIL} or {@link #FALSE}, true if anything else
* @return Value cast to byte if number or string convertible to number, otherwise 0
* @see #optboolean(boolean)
- * @see #checkboolean()
+ * @see #checkboolean()
* @see #isboolean()
* @see #TBOOLEAN
*/
public boolean toboolean() { return true; }
/** Convert to byte if numeric, or 0 if not.
- * @return Value cast to byte if number or string convertible to number, otherwise 0
+ * @return Value cast to byte if number or string convertible to number, otherwise 0
* @see #toint()
* @see #todouble()
* @see #checknumber()
@@ -451,7 +449,7 @@ public class LuaValue extends Varargs {
public byte tobyte() { return 0; }
/** Convert to char if numeric, or 0 if not.
- * @return Value cast to char if number or string convertible to number, otherwise 0
+ * @return Value cast to char if number or string convertible to number, otherwise 0
* @see #toint()
* @see #todouble()
* @see #checknumber()
@@ -461,7 +459,7 @@ public class LuaValue extends Varargs {
public char tochar() { return 0; }
/** Convert to double if numeric, or 0 if not.
- * @return Value cast to double if number or string convertible to number, otherwise 0
+ * @return Value cast to double if number or string convertible to number, otherwise 0
* @see #toint()
* @see #tobyte()
* @see #tochar()
@@ -476,7 +474,7 @@ public class LuaValue extends Varargs {
public double todouble() { return 0; }
/** Convert to float if numeric, or 0 if not.
- * @return Value cast to float if number or string convertible to number, otherwise 0
+ * @return Value cast to float if number or string convertible to number, otherwise 0
* @see #toint()
* @see #todouble()
* @see #checknumber()
@@ -486,7 +484,7 @@ public class LuaValue extends Varargs {
public float tofloat() { return 0; }
/** Convert to int if numeric, or 0 if not.
- * @return Value cast to int if number or string convertible to number, otherwise 0
+ * @return Value cast to int if number or string convertible to number, otherwise 0
* @see #tobyte()
* @see #tochar()
* @see #toshort()
@@ -501,7 +499,7 @@ public class LuaValue extends Varargs {
public int toint() { return 0; }
/** Convert to long if numeric, or 0 if not.
- * @return Value cast to long if number or string convertible to number, otherwise 0
+ * @return Value cast to long if number or string convertible to number, otherwise 0
* @see #isint()
* @see #isinttype()
* @see #toint()
@@ -514,7 +512,7 @@ public class LuaValue extends Varargs {
public long tolong() { return 0; }
/** Convert to short if numeric, or 0 if not.
- * @return Value cast to short if number or string convertible to number, otherwise 0
+ * @return Value cast to short if number or string convertible to number, otherwise 0
* @see #toint()
* @see #todouble()
* @see #checknumber()
@@ -524,7 +522,7 @@ public class LuaValue extends Varargs {
public short toshort() { return 0; }
/** Convert to human readable String for any type.
- * @return String for use by human readers based on type.
+ * @return String for use by human readers based on type.
* @see #tostring()
* @see #optjstring(String)
* @see #checkjstring()
@@ -543,7 +541,7 @@ public class LuaValue extends Varargs {
public Object touserdata() { return null; }
/** Convert to userdata instance if specific type, or null.
- * @return userdata instance if is a userdata whose instance derives from {@code c},
+ * @return userdata instance if is a userdata whose instance derives from {@code c},
* or null if not {@link LuaUserdata}
* @see #optuserdata(Class,Object)
* @see #checkuserdata(Class)
@@ -552,61 +550,61 @@ public class LuaValue extends Varargs {
*/
public Object touserdata(Class c) { return null; }
- /**
+ /**
* Convert the value to a human readable string using {@link #tojstring()}
* @return String value intended to be human readible.
* @see #tostring()
* @see #tojstring()
* @see #optstring(LuaString)
* @see #checkstring()
- * @see #toString()
+ * @see #toString()
*/
public String toString() { return tojstring(); }
/** Conditionally convert to lua number without throwing errors.
- *
- * In lua all numbers are strings, but not all strings are numbers.
- * This function will return
- * the {@link LuaValue} {@code this} if it is a number
- * or a string convertible to a number,
- * and {@link #NIL} for all other cases.
+ *
+ * In lua all numbers are strings, but not all strings are numbers.
+ * This function will return
+ * the {@link LuaValue} {@code this} if it is a number
+ * or a string convertible to a number,
+ * and {@link #NIL} for all other cases.
*
* This allows values to be tested for their "numeric-ness" without
- * the penalty of throwing exceptions,
- * nor the cost of converting the type and creating storage for it.
+ * the penalty of throwing exceptions,
+ * nor the cost of converting the type and creating storage for it.
* @return {@code this} if it is a {@link LuaNumber}
- * or {@link LuaString} that can be converted to a number,
+ * or {@link LuaString} that can be converted to a number,
* otherwise {@link #NIL}
* @see #tostring()
* @see #optnumber(LuaNumber)
* @see #checknumber()
* @see #toint()
* @see #todouble()
- */
+ */
public LuaValue tonumber() { return NIL; }
/** Conditionally convert to lua string without throwing errors.
- *
- * In lua all numbers are strings, so this function will return
- * the {@link LuaValue} {@code this} if it is a string or number,
- * and {@link #NIL} for all other cases.
+ *
+ * In lua all numbers are strings, so this function will return
+ * the {@link LuaValue} {@code this} if it is a string or number,
+ * and {@link #NIL} for all other cases.
*
* This allows values to be tested for their "string-ness" without
- * the penalty of throwing exceptions.
- * @return {@code this} if it is a {@link LuaString} or {@link LuaNumber},
- * otherwise {@link #NIL}
+ * the penalty of throwing exceptions.
+ * @return {@code this} if it is a {@link LuaString} or {@link LuaNumber},
+ * otherwise {@link #NIL}
* @see #tonumber()
* @see #tojstring()
* @see #optstring(LuaString)
* @see #checkstring()
- * @see #toString()
- */
+ * @see #toString()
+ */
public LuaValue tostring() { return NIL; }
/** 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 {@link LuaBoolean},
- * {@code defval} if nil or none,
+ * @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.
* @see #checkboolean()
@@ -617,10 +615,10 @@ public class LuaValue extends Varargs {
/** Check that optional argument is a closure and return as {@link LuaClosure}
*
- * A {@link LuaClosure} is a {@link 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,
+ * @return {@code this} cast to {@link LuaClosure} if a function,
+ * {@code defval} if nil or none,
* throws {@link LuaError} otherwise
* @throws LuaError if was not a closure or nil or none.
* @see #checkclosure()
@@ -631,8 +629,8 @@ public class LuaValue extends Varargs {
/** Check that optional argument is a number or string convertible to number and return as double
* @param defval double to return if {@code this} is nil or none
- * @return {@code this} cast to double if numeric,
- * {@code defval} if nil or none,
+ * @return {@code this} cast to double if numeric,
+ * {@code defval} if nil or none,
* throws {@link LuaError} otherwise
* @throws LuaError if was not numeric or nil or none.
* @see #optint(int)
@@ -643,16 +641,16 @@ public class LuaValue extends Varargs {
* @see #isnumber()
* @see #TNUMBER
*/
- public double optdouble(double defval) { argerror("double"); return 0; }
+ public double optdouble(double defval) { argerror("number"); return 0; }
/** Check that optional argument is a function and return as {@link LuaFunction}
*
- * A {@link LuaFunction} may either be a Java function that implements
- * functionality directly in Java, or a {@link LuaClosure}
- * which is a {@link LuaFunction} that executes lua bytecode.
+ * A {@link LuaFunction} may either be a Java function that implements
+ * functionality directly in Java, or a {@link LuaClosure}
+ * which is a {@link LuaFunction} that executes lua bytecode.
* @param defval {@link LuaFunction} to return if {@code this} is nil or none
- * @return {@code this} cast to {@link LuaFunction} if a function,
- * {@code defval} if nil or none,
+ * @return {@code this} cast to {@link LuaFunction} if a function,
+ * {@code defval} if nil or none,
* throws {@link LuaError} otherwise
* @throws LuaError if was not a function or nil or none.
* @see #checkfunction()
@@ -663,8 +661,8 @@ public class LuaValue extends Varargs {
/** Check that optional argument is a number or string convertible to number and return as int
* @param defval int to return if {@code this} is nil or none
- * @return {@code this} cast to int if numeric,
- * {@code defval} if nil or none,
+ * @return {@code this} cast to int if numeric,
+ * {@code defval} if nil or none,
* throws {@link LuaError} otherwise
* @throws LuaError if was not numeric or nil or none.
* @see #optdouble(double)
@@ -680,8 +678,8 @@ public class LuaValue extends Varargs {
/** Check that optional argument is a number or string convertible to number and return as {@link LuaInteger}
* @param defval {@link LuaInteger} to return if {@code this} is nil or none
- * @return {@code this} converted and wrapped in {@link LuaInteger} if numeric,
- * {@code defval} if nil or none,
+ * @return {@code this} converted and wrapped in {@link LuaInteger} if numeric,
+ * {@code defval} if nil or none,
* throws {@link LuaError} otherwise
* @throws LuaError if was not numeric or nil or none.
* @see #optdouble(double)
@@ -696,8 +694,8 @@ public class LuaValue extends Varargs {
/** Check that optional argument is a number or string convertible to number and return as long
* @param defval long to return if {@code this} is nil or none
- * @return {@code this} cast to long if numeric,
- * {@code defval} if nil or none,
+ * @return {@code this} cast to long if numeric,
+ * {@code defval} if nil or none,
* throws {@link LuaError} otherwise
* @throws LuaError if was not numeric or nil or none.
* @see #optdouble(double)
@@ -712,8 +710,8 @@ public class LuaValue extends Varargs {
/** Check that optional argument is a number or string convertible to number and return as {@link LuaNumber}
* @param defval {@link LuaNumber} to return if {@code this} is nil or none
- * @return {@code this} cast to {@link LuaNumber} if numeric,
- * {@code defval} if nil or none,
+ * @return {@code this} cast to {@link LuaNumber} if numeric,
+ * {@code defval} if nil or none,
* throws {@link LuaError} otherwise
* @throws LuaError if was not numeric or nil or none.
* @see #optdouble(double)
@@ -729,36 +727,36 @@ public class LuaValue extends Varargs {
/** Check that optional argument is a string or number and return as Java String
* @param defval {@link LuaString} to return if {@code this} is nil or none
- * @return {@code this} converted to String if a string or number,
- * {@code defval} if nil or none,
+ * @return {@code this} converted to String if a string or number,
+ * {@code defval} if nil or none,
* throws {@link LuaError} if some other type
* @throws LuaError if was not a string or number or nil or none.
* @see #tojstring()
* @see #optstring(LuaString)
* @see #checkjstring()
- * @see #toString()
+ * @see #toString()
* @see #TSTRING
*/
public String optjstring(String defval) { argerror("String"); return null; }
/** Check that optional argument is a string or number and return as {@link LuaString}
* @param defval {@link LuaString} to return if {@code this} is nil or none
- * @return {@code this} converted to {@link LuaString} if a string or number,
- * {@code defval} if nil or none,
+ * @return {@code this} converted to {@link LuaString} if a string or number,
+ * {@code defval} if nil or none,
* throws {@link LuaError} if some other type
* @throws LuaError if was not a string or number or nil or none.
* @see #tojstring()
* @see #optjstring(String)
* @see #checkstring()
- * @see #toString()
+ * @see #toString()
* @see #TSTRING
*/
public LuaString optstring(LuaString defval) { argerror("string"); return null; }
/** Check that optional argument is a table and return as {@link LuaTable}
* @param defval {@link LuaTable} to return if {@code this} is nil or none
- * @return {@code this} cast to {@link LuaTable} if a table,
- * {@code defval} if nil or none,
+ * @return {@code this} cast to {@link LuaTable} if a table,
+ * {@code defval} if nil or none,
* throws {@link LuaError} if some other type
* @throws LuaError if was not a table or nil or none.
* @see #checktable()
@@ -769,8 +767,8 @@ public class LuaValue extends Varargs {
/** Check that optional argument is a thread and return as {@link LuaThread}
* @param defval {@link LuaThread} to return if {@code this} is nil or none
- * @return {@code this} cast to {@link LuaTable} if a thread,
- * {@code defval} if nil or none,
+ * @return {@code this} cast to {@link LuaTable} if a thread,
+ * {@code defval} if nil or none,
* throws {@link LuaError} if some other type
* @throws LuaError if was not a thread or nil or none.
* @see #checkthread()
@@ -781,8 +779,8 @@ public class LuaValue extends Varargs {
/** Check that optional argument is a userdata and return the Object instance
* @param defval Object to return if {@code this} is nil or none
- * @return Object instance of the userdata if a {@link LuaUserdata},
- * {@code defval} if nil or none,
+ * @return Object instance of the userdata if a {@link LuaUserdata},
+ * {@code defval} if nil or none,
* throws {@link LuaError} if some other type
* @throws LuaError if was not a userdata or nil or none.
* @see #checkuserdata()
@@ -796,8 +794,8 @@ public class LuaValue extends Varargs {
* and return the Object instance
* @param c Class to test userdata instance against
* @param defval Object to return if {@code this} is nil or none
- * @return Object instance of the userdata if a {@link LuaUserdata} and instance is assignable to {@code c},
- * {@code defval} if nil or none,
+ * @return Object instance of the userdata if a {@link LuaUserdata} and instance is assignable to {@code c},
+ * {@code defval} if nil or none,
* throws {@link LuaError} if some other type
* @throws LuaError if was not a userdata whose instance is assignable to {@code c} or nil or none.
* @see #checkuserdata(Class)
@@ -820,20 +818,20 @@ public class LuaValue extends Varargs {
public LuaValue optvalue(LuaValue defval) { return this; }
- /** Check that the value is a {@link LuaBoolean},
+ /** Check that the value is a {@link LuaBoolean},
* or throw {@link LuaError} if not
- * @return boolean value for {@code this} if it is a {@link LuaBoolean}
+ * @return boolean value for {@code this} if it is a {@link LuaBoolean}
* @throws LuaError if not a {@link LuaBoolean}
* @see #optboolean(boolean)
* @see #TBOOLEAN
*/
public boolean checkboolean() { argerror("boolean"); return false; }
- /** Check that the value is a {@link LuaClosure} ,
+ /** Check that the value is a {@link LuaClosure} ,
* or throw {@link LuaError} if not
*
- * {@link LuaClosure} is a subclass of {@link LuaFunction} that interprets lua bytecode.
- * @return {@code this} cast as {@link LuaClosure}
+ * {@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()
* @see #optclosure(LuaClosure)
@@ -842,11 +840,11 @@ public class LuaValue extends Varargs {
*/
public LuaClosure checkclosure() { argerror("closure"); return null; }
- /** Check that the value is numeric and return the value as a double,
+ /** Check that the value is numeric and return the value as a double,
* or throw {@link LuaError} if not numeric
*
- * Values that are {@link LuaNumber} and values that are {@link LuaString}
- * that can be converted to a number will be converted to double.
+ * Values that are {@link LuaNumber} and values that are {@link LuaString}
+ * that can be converted to a number will be converted to double.
* @return value cast to a double if numeric
* @throws LuaError if not a {@link LuaNumber} or is a {@link LuaString} that can't be converted to number
* @see #checkint()
@@ -855,32 +853,32 @@ public class LuaValue extends Varargs {
* @see #optdouble(double)
* @see #TNUMBER
*/
- public double checkdouble() { argerror("double"); return 0; }
+ public double checkdouble() { argerror("number"); return 0; }
- /** Check that the value is a function , or throw {@link LuaError} if not
+ /** Check that the value is a function , or throw {@link LuaError} if not
*
- * A {@link LuaFunction} may either be a Java function that implements
- * functionality directly in Java, or a {@link LuaClosure}
- * which is a {@link LuaFunction} that executes lua bytecode.
+ * A {@link LuaFunction} may either be a Java function that implements
+ * functionality directly in Java, or a {@link LuaClosure}
+ * which is a {@link LuaFunction} that executes lua bytecode.
* @return {@code this} if it is a lua function or closure
- * @throws LuaError if not a function
+ * @throws LuaError if not a function
* @see #checkclosure()
*/
- public LuaFunction checkfunction() { argerror("function"); return null; }
+ public LuaFunction checkfunction() { argerror("function"); return null; }
- /** Check that the value is a Globals instance, or throw {@link LuaError} if not
+ /** Check that the value is a Globals instance, or throw {@link LuaError} if not
*
- * {@link Globals} are a special {@link LuaTable} that establish the default global environment.
+ * {@link Globals} are a special {@link LuaTable} that establish the default global environment.
* @return {@code this} if if an instance fof {@link Globals}
- * @throws LuaError if not a {@link Globals} instance.
+ * @throws LuaError if not a {@link Globals} instance.
*/
public Globals checkglobals() { argerror("globals"); return null; }
- /** Check that the value is numeric, and convert and cast value to int, or throw {@link LuaError} if not numeric
+ /** Check that the value is numeric, and convert and cast value to int, or throw {@link LuaError} if not numeric
*
* Values that are {@link LuaNumber} will be cast to int and may lose precision.
- * Values that are {@link LuaString} that can be converted to a number will be converted,
+ * Values that are {@link LuaString} that can be converted to a number will be converted,
* then cast to int, so may also lose precision.
* @return value cast to a int if numeric
* @throws LuaError if not a {@link LuaNumber} or is a {@link LuaString} that can't be converted to number
@@ -892,10 +890,10 @@ public class LuaValue extends Varargs {
*/
public int checkint() { argerror("int"); return 0; }
- /** Check that the value is numeric, and convert and cast value to int, or throw {@link LuaError} if not numeric
+ /** Check that the value is numeric, and convert and cast value to int, or throw {@link LuaError} if not numeric
*
* Values that are {@link LuaNumber} will be cast to int and may lose precision.
- * Values that are {@link LuaString} that can be converted to a number will be converted,
+ * Values that are {@link LuaString} that can be converted to a number will be converted,
* then cast to int, so may also lose precision.
* @return value cast to a int and wrapped in {@link LuaInteger} if numeric
* @throws LuaError if not a {@link LuaNumber} or is a {@link LuaString} that can't be converted to number
@@ -907,10 +905,10 @@ public class LuaValue extends Varargs {
*/
public LuaInteger checkinteger() { argerror("integer"); return null; }
- /** Check that the value is numeric, and convert and cast value to long, or throw {@link LuaError} if not numeric
+ /** Check that the value is numeric, and convert and cast value to long, or throw {@link LuaError} if not numeric
*
* Values that are {@link LuaNumber} will be cast to long and may lose precision.
- * Values that are {@link LuaString} that can be converted to a number will be converted,
+ * Values that are {@link LuaString} that can be converted to a number will be converted,
* then cast to long, so may also lose precision.
* @return value cast to a long if numeric
* @throws LuaError if not a {@link LuaNumber} or is a {@link LuaString} that can't be converted to number
@@ -922,9 +920,9 @@ public class LuaValue extends Varargs {
*/
public long checklong() { argerror("long"); return 0; }
- /** Check that the value is numeric, and return as a LuaNumber if so, or throw {@link LuaError}
+ /** Check that the value is numeric, and return as a LuaNumber if so, or throw {@link LuaError}
*
- * Values that are {@link LuaString} that can be converted to a number will be converted and returned.
+ * Values that are {@link LuaString} that can be converted to a number will be converted and returned.
* @return value as a {@link LuaNumber} if numeric
* @throws LuaError if not a {@link LuaNumber} or is a {@link LuaString} that can't be converted to number
* @see #checkint()
@@ -936,9 +934,9 @@ public class LuaValue extends Varargs {
*/
public LuaNumber checknumber() { argerror("number"); return null; }
- /** Check that the value is numeric, and return as a LuaNumber if so, or throw {@link LuaError}
+ /** Check that the value is numeric, and return as a LuaNumber if so, or throw {@link LuaError}
*
- * Values that are {@link LuaString} that can be converted to a number will be converted and returned.
+ * Values that are {@link LuaString} that can be converted to a number will be converted and returned.
* @param msg String message to supply if conversion fails
* @return value as a {@link LuaNumber} if numeric
* @throws LuaError if not a {@link LuaNumber} or is a {@link LuaString} that can't be converted to number
@@ -953,9 +951,9 @@ public class LuaValue extends Varargs {
/** Convert this value to a Java String.
*
- * The string representations here will roughly match what is produced by the
- * C lua distribution, however hash codes have no relationship,
- * and there may be differences in number formatting.
+ * The string representations here will roughly match what is produced by the
+ * C lua distribution, however hash codes have no relationship,
+ * and there may be differences in number formatting.
* @return String representation of the value
* @see #checkstring()
* @see #optjstring(String)
@@ -967,9 +965,9 @@ public class LuaValue extends Varargs {
/** Check that this is a lua string, or throw {@link LuaError} if it is not.
*
- * In lua all numbers are strings, so this will succeed for
- * anything that derives from {@link LuaString} or {@link LuaNumber}.
- * Numbers will be converted to {@link LuaString}.
+ * In lua all numbers are strings, so this will succeed for
+ * anything that derives from {@link LuaString} or {@link LuaNumber}.
+ * Numbers will be converted to {@link LuaString}.
*
* @return {@link LuaString} representation of the value if it is a {@link LuaString} or {@link LuaNumber}
* @throws LuaError if {@code this} is not a {@link LuaTable}
@@ -988,7 +986,7 @@ public class LuaValue extends Varargs {
* @see #opttable(LuaTable)
* @see #TTABLE
*/
- public LuaTable checktable() { argerror("table"); return null; }
+ public LuaTable checktable() { argerror("table"); return null; }
/** Check that this is a {@link LuaThread}, or throw {@link LuaError} if it is not
* @return {@code this} if it is a {@link LuaThread}
@@ -1033,14 +1031,14 @@ public class LuaValue extends Varargs {
*/
public boolean isvalidkey() { return true; }
- /**
+ /**
* Throw a {@link LuaError} with a particular message
* @param message String providing message details
* @throws LuaError in all cases
*/
public static LuaValue error(String message) { throw new LuaError(message); }
- /**
+ /**
* 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.
@@ -1050,14 +1048,14 @@ public class LuaValue extends Varargs {
*/
public static void assert_(boolean b,String msg) { if(!b) throw new LuaError(msg); }
- /**
+ /**
* Throw a {@link LuaError} indicating an invalid argument was supplied to a function
* @param expected String naming the type that was expected
* @throws LuaError in all cases
*/
- protected LuaValue argerror(String expected) { throw new LuaError("bad argument: "+expected+" expected, got "+typename()+" value="+this.tostring()); }
+ protected LuaValue argerror(String expected) { throw new LuaError("bad argument: "+expected+" expected, got "+typename()); }
- /**
+ /**
* Throw a {@link LuaError} indicating an invalid argument was supplied to a function
* @param iarg index of the argument that was invalid, first index is 1
* @param msg String providing information about the invalid argument
@@ -1065,41 +1063,41 @@ public class LuaValue extends Varargs {
*/
public static LuaValue argerror(int iarg,String msg) { throw new LuaError("bad argument #"+iarg+": "+msg); }
- /**
+ /**
* Throw a {@link LuaError} indicating an invalid type was supplied to a function
* @param expected String naming the type that was expected
* @throws LuaError in all cases
*/
- protected LuaValue typerror(String expected) { throw new LuaError(expected+" expected, got "+typename()+" value="+this.tostring()); }
+ protected LuaValue typerror(String expected) { throw new LuaError(expected+" expected, got "+typename()); }
- /**
- * Throw a {@link LuaError} indicating an operation is not implemented
+ /**
+ * Throw a {@link LuaError} indicating an operation is not implemented
* @throws LuaError in all cases
*/
protected LuaValue unimplemented(String fun) { throw new LuaError("'"+fun+"' not implemented for "+typename()); }
- /**
- * Throw a {@link LuaError} indicating an illegal operation occurred,
+ /**
+ * Throw a {@link LuaError} indicating an illegal operation occurred,
* typically involved in managing weak references
* @throws LuaError in all cases
*/
protected LuaValue illegal(String op,String typename) { throw new LuaError("illegal operation '"+op+"' for "+typename); }
- /**
- * Throw a {@link LuaError} based on the len operator,
+ /**
+ * Throw a {@link LuaError} based on the len operator,
* typically due to an invalid operand type
* @throws LuaError in all cases
*/
protected LuaValue lenerror() { throw new LuaError("attempt to get length of "+typename()); }
- /**
- * Throw a {@link LuaError} based on an arithmetic error such as add, or pow,
+ /**
+ * Throw a {@link LuaError} based on an arithmetic error such as add, or pow,
* typically due to an invalid operand type
* @throws LuaError in all cases
*/
protected LuaValue aritherror() { throw new LuaError("attempt to perform arithmetic on "+typename()); }
- /**
+ /**
* Throw a {@link LuaError} based on an arithmetic error such as add, or pow,
* typically due to an invalid operand type
* @param fun String description of the function that was attempted
@@ -1107,7 +1105,7 @@ public class LuaValue extends Varargs {
*/
protected LuaValue aritherror(String fun) { throw new LuaError("attempt to perform arithmetic '"+fun+"' on "+typename()); }
- /**
+ /**
* Throw a {@link LuaError} based on a comparison error such as greater-than or less-than,
* typically due to an invalid operand type
* @param rhs String description of what was on the right-hand-side of the comparison that resulted in the error.
@@ -1115,7 +1113,7 @@ public class LuaValue extends Varargs {
*/
protected LuaValue compareerror(String rhs) { throw new LuaError("attempt to compare "+typename()+" with "+rhs); }
- /**
+ /**
* Throw a {@link LuaError} based on a comparison error such as greater-than or less-than,
* typically due to an invalid operand type
* @param rhs Right-hand-side of the comparison that resulted in the error.
@@ -1127,8 +1125,8 @@ public class LuaValue extends Varargs {
* @param key the key to look up, must not be {@link #NIL} or null
* @return {@link LuaValue} for that key, or {@link #NIL} if not found and no metatag
* @throws LuaError if {@code this} is not a table,
- * or there is no {@link #INDEX} metatag,
- * or key is {@link #NIL}
+ * or there is no {@link #INDEX} metatag,
+ * or key is {@link #NIL}
* @see #get(int)
* @see #get(String)
* @see #rawget(LuaValue)
@@ -1139,7 +1137,7 @@ public class LuaValue extends Varargs {
* @param key the key to look up
* @return {@link LuaValue} for that key, or {@link #NIL} if not found
* @throws LuaError if {@code this} is not a table,
- * or there is no {@link #INDEX} metatag
+ * or there is no {@link #INDEX} metatag
* @see #get(LuaValue)
* @see #rawget(int)
*/
@@ -1149,7 +1147,7 @@ public class LuaValue extends Varargs {
* @param key the key to look up, must not be null
* @return {@link LuaValue} for that key, or {@link #NIL} if not found
* @throws LuaError if {@code this} is not a table,
- * or there is no {@link #INDEX} metatag
+ * or there is no {@link #INDEX} metatag
* @see #get(LuaValue)
* @see #rawget(String)
*/
@@ -1158,57 +1156,57 @@ public class LuaValue extends Varargs {
/** Set a value in a table without metatag processing using {@link #NEWINDEX}.
* @param key the key to use, must not be {@link #NIL} or null
* @param value the value to use, can be {@link #NIL}, must not be null
- * @throws LuaError if {@code this} is not a table,
+ * @throws LuaError if {@code this} is not a table,
* or key is {@link #NIL},
- * or there is no {@link #NEWINDEX} metatag
+ * or there is no {@link #NEWINDEX} metatag
*/
public void set( LuaValue key, LuaValue value ) { settable(this, key, value); }
/** Set a value in a table without metatag processing using {@link #NEWINDEX}.
* @param key the key to use
* @param value the value to use, can be {@link #NIL}, must not be null
- * @throws LuaError if {@code this} is not a table,
- * or there is no {@link #NEWINDEX} metatag
+ * @throws LuaError if {@code this} is not a table,
+ * or there is no {@link #NEWINDEX} metatag
*/
public void set( int key, LuaValue value ) { set(LuaInteger.valueOf(key), value ); }
/** Set a value in a table without metatag processing using {@link #NEWINDEX}.
* @param key the key to use
* @param value the value to use, must not be null
- * @throws LuaError if {@code this} is not a table,
- * or there is no {@link #NEWINDEX} metatag
+ * @throws LuaError if {@code this} is not a table,
+ * or there is no {@link #NEWINDEX} metatag
*/
public void set( int key, String value ) { set(key, valueOf(value) ); }
/** Set a value in a table without metatag processing using {@link #NEWINDEX}.
* @param key the key to use, must not be {@link #NIL} or null
* @param value the value to use, can be {@link #NIL}, must not be null
- * @throws LuaError if {@code this} is not a table,
- * or there is no {@link #NEWINDEX} metatag
+ * @throws LuaError if {@code this} is not a table,
+ * or there is no {@link #NEWINDEX} metatag
*/
public void set( String key, LuaValue value ) { set(valueOf(key), value ); }
/** Set a value in a table without metatag processing using {@link #NEWINDEX}.
* @param key the key to use, must not be null
* @param value the value to use
- * @throws LuaError if {@code this} is not a table,
- * or there is no {@link #NEWINDEX} metatag
+ * @throws LuaError if {@code this} is not a table,
+ * or there is no {@link #NEWINDEX} metatag
*/
public void set( String key, double value ) { set(valueOf(key), valueOf(value) ); }
/** Set a value in a table without metatag processing using {@link #NEWINDEX}.
* @param key the key to use, must not be null
* @param value the value to use
- * @throws LuaError if {@code this} is not a table,
- * or there is no {@link #NEWINDEX} metatag
+ * @throws LuaError if {@code this} is not a table,
+ * or there is no {@link #NEWINDEX} metatag
*/
public void set( String key, int value ) { set(valueOf(key), valueOf(value) ); }
/** Set a value in a table without metatag processing using {@link #NEWINDEX}.
* @param key the key to use, must not be null
* @param value the value to use, must not be null
- * @throws LuaError if {@code this} is not a table,
- * or there is no {@link #NEWINDEX} metatag
+ * @throws LuaError if {@code this} is not a table,
+ * or there is no {@link #NEWINDEX} metatag
*/
public void set( String key, String value ) { set(valueOf(key), valueOf(value) ); }
@@ -1282,24 +1280,24 @@ public class LuaValue extends Varargs {
*/
public void rawset( String key, String value ) { rawset(valueOf(key),valueOf(value)); }
- /** Set list values in a table without invoking metatag processing
+ /** Set list values in a table without invoking metatag processing
*
- * Primarily used internally in response to a SETLIST bytecode.
+ * Primarily used internally in response to a SETLIST bytecode.
* @param key0 the first key to set in the table
* @param values the list of values to set
- * @throws LuaError if this is not a table.
+ * @throws LuaError if this is not a table.
*/
public void rawsetlist( int key0, Varargs values ) { for ( int i=0, n=values.narg(); i
* To iterate over all key-value pairs in a table you can use
@@ -1312,9 +1310,9 @@ public class LuaValue extends Varargs {
* LuaValue v = n.arg(2)
* process( k, v )
* }}
- * @param index {@link LuaInteger} value identifying a key to start from,
+ * @param index {@link LuaInteger} value identifying a key to start from,
* or {@link #NIL} to start at the beginning
- * @return {@link Varargs} containing {key,value} for the next entry,
+ * @return {@link Varargs} containing {key,value} for the next entry,
* 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
@@ -1326,7 +1324,7 @@ public class LuaValue extends Varargs {
*/
public Varargs next(LuaValue index) { return typerror("table"); }
- /** Find the next integer-key,value pair if {@code this} is a table,
+ /** Find the next integer-key,value pair if {@code this} is a table,
* return {@link #NIL} if there are no more, or throw a {@link LuaError} if not a table.
*
* To iterate over integer keys in a table you can use
@@ -1340,9 +1338,9 @@ public class LuaValue extends Varargs {
* process( k, v )
* }
* }
- * @param index {@link LuaInteger} value identifying a key to start from,
+ * @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,
+ * @return {@link Varargs} containing {@code (key,value)} for the next entry,
* 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
@@ -1354,10 +1352,10 @@ public class LuaValue extends Varargs {
*/
public Varargs inext(LuaValue index) { return typerror("table"); }
- /**
- * Load a library instance by calling it with and empty string as the modname,
- * and this Globals as the environment. This is normally used to iniitalize the
- * library instance and which may install itself into these globals.
+ /**
+ * Load a library instance by calling it with and empty string as the modname,
+ * 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}
* @return {@link LuaValue} returned by the initialization call.
*/
@@ -1368,12 +1366,12 @@ public class LuaValue extends Varargs {
public int narg() { return 1; };
public LuaValue arg1() { return this; }
- /**
+ /**
* Get the metatable for this {@link LuaValue}
*
- * For {@link LuaTable} and {@link LuaUserdata} instances,
- * the metatable returned is this instance metatable.
- * For all other types, the class metatable value will be returned.
+ * For {@link LuaTable} and {@link LuaUserdata} instances,
+ * the metatable returned is this instance metatable.
+ * For all other types, the class metatable value will be returned.
* @return metatable, or null if it there is none
* @see LuaBoolean#s_metatable
* @see LuaNumber#s_metatable
@@ -1383,11 +1381,11 @@ public class LuaValue extends Varargs {
*/
public LuaValue getmetatable() { return null; }
- /**
+ /**
* Set the metatable for this {@link LuaValue}
*
- * For {@link LuaTable} and {@link LuaUserdata} instances, the metatable is per instance.
- * For all other types, there is one metatable per type that can be set directly from java
+ * For {@link LuaTable} and {@link LuaUserdata} instances, the metatable is per instance.
+ * For all other types, there is one metatable per type that can be set directly from java
* @param metatable {@link LuaValue} instance to serve as the metatable, or null to reset it.
* @return {@code this} to allow chaining of Java function calls
* @see LuaBoolean#s_metatable
@@ -1398,21 +1396,21 @@ public class LuaValue extends Varargs {
*/
public LuaValue setmetatable(LuaValue metatable) { return argerror("table"); }
- /** Call {@code this} with 0 arguments, including metatag processing,
+ /** Call {@code this} with 0 arguments, including metatag processing,
* and return only the first return value.
*
- * If {@code this} is a {@link LuaFunction}, call it,
- * and return only its first return value, dropping any others.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * If {@code this} is a {@link LuaFunction}, call it,
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * If the return value is a {@link Varargs}, only the 1st value will be returned.
- * To get multiple values, use {@link #invoke()} instead.
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
*
* To call {@code this} as a method call, use {@link #method(LuaValue)} instead.
- *
+ *
* @return First return value {@code (this())}, or {@link #NIL} if there were none.
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #call(LuaValue)
* @see #call(LuaValue,LuaValue)
@@ -1423,22 +1421,22 @@ public class LuaValue extends Varargs {
*/
public LuaValue call() { return callmt().call(this); }
- /** Call {@code this} with 1 argument, including metatag processing,
+ /** Call {@code this} with 1 argument, including metatag processing,
* and return only the first return value.
*
- * If {@code this} is a {@link LuaFunction}, call it,
- * and return only its first return value, dropping any others.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * If {@code this} is a {@link LuaFunction}, call it,
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * If the return value is a {@link Varargs}, only the 1st value will be returned.
- * To get multiple values, use {@link #invoke()} instead.
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
*
* To call {@code this} as a method call, use {@link #method(LuaValue)} instead.
- *
+ *
* @param arg First argument to supply to the called function
* @return First return value {@code (this(arg))}, or {@link #NIL} if there were none.
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #call()
* @see #call(LuaValue,LuaValue)
@@ -1449,30 +1447,30 @@ public class LuaValue extends Varargs {
*/
public LuaValue call(LuaValue arg) { return callmt().call(this,arg); }
- /** Convenience function which calls a luavalue with a single, string argument.
+ /** Convenience function which calls a luavalue with a single, string argument.
* @param arg String argument to the function. This will be converted to a LuaString.
- * @return return value of the invocation.
+ * @return return value of the invocation.
* @see #call(LuaValue)
*/
public LuaValue call(String arg) { return call(valueOf(arg)); }
- /** Call {@code this} with 2 arguments, including metatag processing,
+ /** Call {@code this} with 2 arguments, including metatag processing,
* and return only the first return value.
*
- * If {@code this} is a {@link LuaFunction}, call it,
- * and return only its first return value, dropping any others.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * If {@code this} is a {@link LuaFunction}, call it,
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * If the return value is a {@link Varargs}, only the 1st value will be returned.
- * To get multiple values, use {@link #invoke()} instead.
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
*
* To call {@code this} as a method call, use {@link #method(LuaValue)} instead.
- *
+ *
* @param arg1 First argument to supply to the called function
* @param arg2 Second argument to supply to the called function
* @return First return value {@code (this(arg1,arg2))}, or {@link #NIL} if there were none.
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #call()
* @see #call(LuaValue)
@@ -1483,24 +1481,24 @@ public class LuaValue extends Varargs {
*/
public LuaValue call(LuaValue arg1, LuaValue arg2) { return callmt().call(this,arg1,arg2); }
- /** Call {@code this} with 3 arguments, including metatag processing,
+ /** Call {@code this} with 3 arguments, including metatag processing,
* and return only the first return value.
*
- * If {@code this} is a {@link LuaFunction}, call it,
- * and return only its first return value, dropping any others.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * If {@code this} is a {@link LuaFunction}, call it,
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * If the return value is a {@link Varargs}, only the 1st value will be returned.
- * To get multiple values, use {@link #invoke()} instead.
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
*
* To call {@code this} as a method call, use {@link #method(LuaValue)} instead.
- *
+ *
* @param arg1 First argument to supply to the called function
* @param arg2 Second argument to supply to the called function
* @param arg3 Second argument to supply to the called function
* @return First return value {@code (this(arg1,arg2,arg3))}, or {@link #NIL} if there were none.
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #call()
* @see #call(LuaValue)
@@ -1511,23 +1509,23 @@ public class LuaValue extends Varargs {
*/
public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) { return callmt().invoke(new LuaValue[]{this,arg1,arg2,arg3}).arg1(); }
- /** Call named method on {@code this} with 0 arguments, including metatag processing,
+ /** Call named method on {@code this} with 0 arguments, including metatag processing,
* and return only the first return value.
*
- * Look up {@code this[name]} and if it is a {@link LuaFunction},
- * call it inserting {@code this} as an additional first argument.
- * and return only its first return value, dropping any others.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@code this} as an additional first argument.
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * If the return value is a {@link Varargs}, only the 1st value will be returned.
- * To get multiple values, use {@link #invoke()} instead.
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
*
* To call {@code this} as a plain call, use {@link #call()} instead.
- *
+ *
* @param name Name of the method to look up for invocation
* @return All values returned from {@code this:name()} as a {@link Varargs} instance
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #call()
* @see #invoke()
@@ -1537,23 +1535,23 @@ public class LuaValue extends Varargs {
*/
public LuaValue method(String name) { return this.get(name).call(this); }
- /** Call named method on {@code this} with 0 arguments, including metatag processing,
+ /** Call named method on {@code this} with 0 arguments, including metatag processing,
* and return only the first return value.
*
- * Look up {@code this[name]} and if it is a {@link LuaFunction},
- * call it inserting {@code this} as an additional first argument,
- * and return only its first return value, dropping any others.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@code this} as an additional first argument,
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * If the return value is a {@link Varargs}, only the 1st value will be returned.
- * To get multiple values, use {@link #invoke()} instead.
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
*
* To call {@code this} as a plain call, use {@link #call()} instead.
- *
+ *
* @param name Name of the method to look up for invocation
* @return All values returned from {@code this:name()} as a {@link Varargs} instance
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #call()
* @see #invoke()
@@ -1563,24 +1561,24 @@ public class LuaValue extends Varargs {
*/
public LuaValue method(LuaValue name) { return this.get(name).call(this); }
- /** Call named method on {@code this} with 1 argument, including metatag processing,
+ /** Call named method on {@code this} with 1 argument, including metatag processing,
* and return only the first return value.
*
- * Look up {@code this[name]} and if it is a {@link LuaFunction},
- * call it inserting {@code this} as an additional first argument,
- * and return only its first return value, dropping any others.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@code this} as an additional first argument,
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * If the return value is a {@link Varargs}, only the 1st value will be returned.
- * To get multiple values, use {@link #invoke()} instead.
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
*
* To call {@code this} as a plain call, use {@link #call(LuaValue)} instead.
- *
+ *
* @param name Name of the method to look up for invocation
* @param arg Argument to supply to the method
* @return All values returned from {@code this:name(arg)} as a {@link Varargs} instance
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #call(LuaValue)
* @see #invoke(Varargs)
@@ -1590,24 +1588,24 @@ public class LuaValue extends Varargs {
*/
public LuaValue method(String name, LuaValue arg) { return this.get(name).call(this,arg); }
- /** Call named method on {@code this} with 1 argument, including metatag processing,
+ /** Call named method on {@code this} with 1 argument, including metatag processing,
* and return only the first return value.
*
- * Look up {@code this[name]} and if it is a {@link LuaFunction},
- * call it inserting {@code this} as an additional first argument,
- * and return only its first return value, dropping any others.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@code this} as an additional first argument,
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * If the return value is a {@link Varargs}, only the 1st value will be returned.
- * To get multiple values, use {@link #invoke()} instead.
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
*
* To call {@code this} as a plain call, use {@link #call(LuaValue)} instead.
- *
+ *
* @param name Name of the method to look up for invocation
* @param arg Argument to supply to the method
* @return All values returned from {@code this:name(arg)} as a {@link Varargs} instance
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #call(LuaValue)
* @see #invoke(Varargs)
@@ -1617,25 +1615,25 @@ public class LuaValue extends Varargs {
*/
public LuaValue method(LuaValue name, LuaValue arg) { return this.get(name).call(this,arg); }
- /** Call named method on {@code this} with 2 arguments, including metatag processing,
+ /** Call named method on {@code this} with 2 arguments, including metatag processing,
* and return only the first return value.
*
- * Look up {@code this[name]} and if it is a {@link LuaFunction},
- * call it inserting {@code this} as an additional first argument,
- * and return only its first return value, dropping any others.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@code this} as an additional first argument,
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * If the return value is a {@link Varargs}, only the 1st value will be returned.
- * To get multiple values, use {@link #invoke()} instead.
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
*
* To call {@code this} as a plain call, use {@link #call(LuaValue,LuaValue)} instead.
- *
+ *
* @param name Name of the method to look up for invocation
* @param arg1 First argument to supply to the method
* @param arg2 Second argument to supply to the method
* @return All values returned from {@code this:name(arg1,arg2)} as a {@link Varargs} instance
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #call(LuaValue,LuaValue)
* @see #invoke(LuaValue,Varargs)
@@ -1644,25 +1642,25 @@ public class LuaValue extends Varargs {
*/
public LuaValue method(String name, LuaValue arg1, LuaValue arg2) { return this.get(name).call(this,arg1,arg2); }
- /** Call named method on {@code this} with 2 arguments, including metatag processing,
+ /** Call named method on {@code this} with 2 arguments, including metatag processing,
* and return only the first return value.
*
- * Look up {@code this[name]} and if it is a {@link LuaFunction},
- * call it inserting {@code this} as an additional first argument,
- * and return only its first return value, dropping any others.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@code this} as an additional first argument,
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * If the return value is a {@link Varargs}, only the 1st value will be returned.
- * To get multiple values, use {@link #invoke()} instead.
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
*
* To call {@code this} as a plain call, use {@link #call(LuaValue,LuaValue)} instead.
- *
+ *
* @param name Name of the method to look up for invocation
* @param arg1 First argument to supply to the method
* @param arg2 Second argument to supply to the method
* @return All values returned from {@code this:name(arg1,arg2)} as a {@link Varargs} instance
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #call(LuaValue,LuaValue)
* @see #invoke(LuaValue,Varargs)
@@ -1671,19 +1669,19 @@ public class LuaValue extends Varargs {
*/
public LuaValue method(LuaValue name, LuaValue arg1, LuaValue arg2) { return this.get(name).call(this,arg1,arg2); }
- /** Call {@code this} with 0 arguments, including metatag processing,
+ /** Call {@code this} with 0 arguments, including metatag processing,
* and retain all return values in a {@link Varargs}.
*
- * If {@code this} is a {@link LuaFunction}, call it, and return all values.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * If {@code this} is a {@link LuaFunction}, call it, and return all values.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * To get a particular return value, us {@link Varargs#arg(int)}
+ * To get a particular return value, us {@link Varargs#arg(int)}
*
* To call {@code this} as a method call, use {@link #invokemethod(LuaValue)} instead.
- *
+ *
* @return All return values as a {@link Varargs} instance.
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #call()
* @see #invoke(Varargs)
@@ -1692,20 +1690,20 @@ public class LuaValue extends Varargs {
*/
public Varargs invoke() { return invoke(NONE); }
- /** Call {@code this} with variable arguments, including metatag processing,
+ /** Call {@code this} with variable arguments, including metatag processing,
* and retain all return values in a {@link Varargs}.
*
- * If {@code this} is a {@link LuaFunction}, call it, and return all values.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * If {@code this} is a {@link LuaFunction}, call it, and return all values.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * To get a particular return value, us {@link Varargs#arg(int)}
+ * To get a particular return value, us {@link Varargs#arg(int)}
*
* To call {@code this} as a method call, use {@link #invokemethod(LuaValue)} instead.
- *
+ *
* @param args Varargs containing the arguments to supply to the called function
* @return All return values as a {@link Varargs} instance.
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #varargsOf(LuaValue[])
* @see #call(LuaValue)
@@ -1716,21 +1714,21 @@ public class LuaValue extends Varargs {
*/
public Varargs invoke(Varargs args) { return callmt().invoke(this,args); }
- /** Call {@code this} with variable arguments, including metatag processing,
+ /** Call {@code this} with variable arguments, including metatag processing,
* and retain all return values in a {@link Varargs}.
*
- * If {@code this} is a {@link LuaFunction}, call it, and return all values.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * If {@code this} is a {@link LuaFunction}, call it, and return all values.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * To get a particular return value, us {@link Varargs#arg(int)}
+ * To get a particular return value, us {@link Varargs#arg(int)}
*
* To call {@code this} as a method call, use {@link #invokemethod(LuaValue,Varargs)} instead.
- *
+ *
* @param arg The first argument to supply to the called function
* @param varargs Varargs containing the remaining arguments to supply to the called function
* @return All return values as a {@link Varargs} instance.
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #varargsOf(LuaValue[])
* @see #call(LuaValue,LuaValue)
@@ -1740,22 +1738,22 @@ public class LuaValue extends Varargs {
*/
public Varargs invoke(LuaValue arg,Varargs varargs) { return invoke(varargsOf(arg,varargs)); }
- /** Call {@code this} with variable arguments, including metatag processing,
+ /** Call {@code this} with variable arguments, including metatag processing,
* and retain all return values in a {@link Varargs}.
*
- * If {@code this} is a {@link LuaFunction}, call it, and return all values.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * If {@code this} is a {@link LuaFunction}, call it, and return all values.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * To get a particular return value, us {@link Varargs#arg(int)}
+ * To get a particular return value, us {@link Varargs#arg(int)}
*
* To call {@code this} as a method call, use {@link #invokemethod(LuaValue,Varargs)} instead.
- *
+ *
* @param arg1 The first argument to supply to the called function
* @param arg2 The second argument to supply to the called function
* @param varargs Varargs containing the remaining arguments to supply to the called function
* @return All return values as a {@link Varargs} instance.
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #varargsOf(LuaValue[])
* @see #call(LuaValue,LuaValue,LuaValue)
@@ -1765,20 +1763,20 @@ public class LuaValue extends Varargs {
*/
public Varargs invoke(LuaValue arg1,LuaValue arg2,Varargs varargs) { return invoke(varargsOf(arg1,arg2,varargs)); }
- /** Call {@code this} with variable arguments, including metatag processing,
+ /** Call {@code this} with variable arguments, including metatag processing,
* and retain all return values in a {@link Varargs}.
*
- * If {@code this} is a {@link LuaFunction}, call it, and return all values.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * If {@code this} is a {@link LuaFunction}, call it, and return all values.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * To get a particular return value, us {@link Varargs#arg(int)}
+ * To get a particular return value, us {@link Varargs#arg(int)}
*
* To call {@code this} as a method call, use {@link #invokemethod(LuaValue,Varargs)} instead.
- *
+ *
* @param args Array of arguments to supply to the called function
* @return All return values as a {@link Varargs} instance.
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #varargsOf(LuaValue[])
* @see #call(LuaValue,LuaValue,LuaValue)
@@ -1788,21 +1786,21 @@ public class LuaValue extends Varargs {
*/
public Varargs invoke(LuaValue[] args) { return invoke(varargsOf(args)); }
- /** Call {@code this} with variable arguments, including metatag processing,
+ /** Call {@code this} with variable arguments, including metatag processing,
* and retain all return values in a {@link Varargs}.
*
- * If {@code this} is a {@link LuaFunction}, call it, and return all values.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * If {@code this} is a {@link LuaFunction}, call it, and return all values.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * To get a particular return value, us {@link Varargs#arg(int)}
+ * To get a particular return value, us {@link Varargs#arg(int)}
*
* To call {@code this} as a method call, use {@link #invokemethod(LuaValue,Varargs)} instead.
- *
+ *
* @param args Array of arguments to supply to the called function
* @param varargs Varargs containing additional arguments to supply to the called function
* @return All return values as a {@link Varargs} instance.
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #varargsOf(LuaValue[])
* @see #call(LuaValue,LuaValue,LuaValue)
@@ -1814,22 +1812,22 @@ public class LuaValue extends Varargs {
*/
public Varargs invoke(LuaValue[] args,Varargs varargs) { return invoke(varargsOf(args,varargs)); }
- /** Call named method on {@code this} with 0 arguments, including metatag processing,
+ /** Call named method on {@code this} with 0 arguments, including metatag processing,
* and retain all return values in a {@link Varargs}.
*
- * Look up {@code this[name]} and if it is a {@link LuaFunction},
- * call it inserting {@code this} as an additional first argument,
- * and return all return values as a {@link Varargs} instance.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@code this} as an additional first argument,
+ * and return all return values as a {@link Varargs} instance.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * To get a particular return value, us {@link Varargs#arg(int)}
+ * To get a particular return value, us {@link Varargs#arg(int)}
*
* To call {@code this} as a plain call, use {@link #invoke()} instead.
- *
+ *
* @param name Name of the method to look up for invocation
* @return All values returned from {@code this:name()} as a {@link Varargs} instance
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #call()
* @see #invoke()
@@ -1842,22 +1840,22 @@ public class LuaValue extends Varargs {
*/
public Varargs invokemethod(String name) { return get(name).invoke(this); }
- /** Call named method on {@code this} with 0 arguments, including metatag processing,
+ /** Call named method on {@code this} with 0 arguments, including metatag processing,
* and retain all return values in a {@link Varargs}.
*
- * Look up {@code this[name]} and if it is a {@link LuaFunction},
- * call it inserting {@code this} as an additional first argument,
- * and return all return values as a {@link Varargs} instance.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@code this} as an additional first argument,
+ * and return all return values as a {@link Varargs} instance.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * To get a particular return value, us {@link Varargs#arg(int)}
+ * To get a particular return value, us {@link Varargs#arg(int)}
*
* To call {@code this} as a plain call, use {@link #invoke()} instead.
- *
+ *
* @param name Name of the method to look up for invocation
* @return All values returned from {@code this:name()} as a {@link Varargs} instance
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #call()
* @see #invoke()
@@ -1870,23 +1868,23 @@ public class LuaValue extends Varargs {
*/
public Varargs invokemethod(LuaValue name) { return get(name).invoke(this); }
- /** Call named method on {@code this} with 1 argument, including metatag processing,
+ /** Call named method on {@code this} with 1 argument, including metatag processing,
* and retain all return values in a {@link Varargs}.
*
- * Look up {@code this[name]} and if it is a {@link LuaFunction},
- * call it inserting {@code this} as an additional first argument,
- * and return all return values as a {@link Varargs} instance.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@code this} as an additional first argument,
+ * and return all return values as a {@link Varargs} instance.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * To get a particular return value, us {@link Varargs#arg(int)}
+ * To get a particular return value, us {@link Varargs#arg(int)}
*
* To call {@code this} as a plain call, use {@link #invoke(Varargs)} instead.
- *
+ *
* @param name Name of the method to look up for invocation
- * @param args {@link Varargs} containing arguments to supply to the called function after {@code this}
+ * @param args {@link Varargs} containing arguments to supply to the called function after {@code this}
* @return All values returned from {@code this:name(args)} as a {@link Varargs} instance
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #call()
* @see #invoke(Varargs)
@@ -1899,23 +1897,23 @@ public class LuaValue extends Varargs {
*/
public Varargs invokemethod(String name, Varargs args) { return get(name).invoke(varargsOf(this,args)); }
- /** Call named method on {@code this} with variable arguments, including metatag processing,
+ /** Call named method on {@code this} with variable arguments, including metatag processing,
* and retain all return values in a {@link Varargs}.
*
- * Look up {@code this[name]} and if it is a {@link LuaFunction},
- * call it inserting {@code this} as an additional first argument,
- * and return all return values as a {@link Varargs} instance.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@code this} as an additional first argument,
+ * and return all return values as a {@link Varargs} instance.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * To get a particular return value, us {@link Varargs#arg(int)}
+ * To get a particular return value, us {@link Varargs#arg(int)}
*
* To call {@code this} as a plain call, use {@link #invoke(Varargs)} instead.
- *
+ *
* @param name Name of the method to look up for invocation
- * @param args {@link Varargs} containing arguments to supply to the called function after {@code this}
+ * @param args {@link Varargs} containing arguments to supply to the called function after {@code this}
* @return All values returned from {@code this:name(args)} as a {@link Varargs} instance
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #call()
* @see #invoke(Varargs)
@@ -1928,23 +1926,23 @@ public class LuaValue extends Varargs {
*/
public Varargs invokemethod(LuaValue name, Varargs args) { return get(name).invoke(varargsOf(this,args)); }
- /** Call named method on {@code this} with 1 argument, including metatag processing,
+ /** Call named method on {@code this} with 1 argument, including metatag processing,
* and retain all return values in a {@link Varargs}.
*
- * Look up {@code this[name]} and if it is a {@link LuaFunction},
- * call it inserting {@code this} as an additional first argument,
- * and return all return values as a {@link Varargs} instance.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@code this} as an additional first argument,
+ * and return all return values as a {@link Varargs} instance.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * To get a particular return value, us {@link Varargs#arg(int)}
+ * To get a particular return value, us {@link Varargs#arg(int)}
*
* To call {@code this} as a plain call, use {@link #invoke(Varargs)} instead.
- *
+ *
* @param name Name of the method to look up for invocation
- * @param args Array of {@link LuaValue} containing arguments to supply to the called function after {@code this}
+ * @param args Array of {@link LuaValue} containing arguments to supply to the called function after {@code this}
* @return All values returned from {@code this:name(args)} as a {@link Varargs} instance
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #call()
* @see #invoke(Varargs)
@@ -1958,23 +1956,23 @@ public class LuaValue extends Varargs {
*/
public Varargs invokemethod(String name, LuaValue[] args) { return get(name).invoke(varargsOf(this,varargsOf(args))); }
- /** Call named method on {@code this} with variable arguments, including metatag processing,
+ /** Call named method on {@code this} with variable arguments, including metatag processing,
* and retain all return values in a {@link Varargs}.
*
- * Look up {@code this[name]} and if it is a {@link LuaFunction},
- * call it inserting {@code this} as an additional first argument,
- * and return all return values as a {@link Varargs} instance.
- * Otherwise, look for the {@link #CALL} metatag and call that.
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@code this} as an additional first argument,
+ * and return all return values as a {@link Varargs} instance.
+ * Otherwise, look for the {@link #CALL} metatag and call that.
*
- * To get a particular return value, us {@link Varargs#arg(int)}
+ * To get a particular return value, us {@link Varargs#arg(int)}
*
* To call {@code this} as a plain call, use {@link #invoke(Varargs)} instead.
- *
+ *
* @param name Name of the method to look up for invocation
- * @param args Array of {@link LuaValue} containing arguments to supply to the called function after {@code this}
+ * @param args Array of {@link LuaValue} containing arguments to supply to the called function after {@code this}
* @return All values returned from {@code this:name(args)} as a {@link Varargs} instance
- * @throws LuaError if not a function and {@link #CALL} is not defined,
- * or the invoked function throws a {@link LuaError}
+ * @throws LuaError if not a function and {@link #CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
* or the invoked closure throw a lua {@code error}
* @see #call()
* @see #invoke(Varargs)
@@ -1991,33 +1989,33 @@ public class LuaValue extends Varargs {
/**
* Get the metatag value for the {@link #CALL} metatag, if it exists.
* @return {@link LuaValue} value if metatag is defined
- * @throws LuaError if {@link #CALL} metatag is not defined.
+ * @throws LuaError if {@link #CALL} metatag is not defined.
*/
protected LuaValue callmt() {
return checkmetatag(CALL, "attempt to call ");
}
- /** Unary not: return inverse boolean value {@code (~this)} as defined by lua not operator
- * @return {@link #TRUE} if {@link #NIL} or {@link #FALSE}, otherwise {@link #FALSE}
+ /** Unary not: return inverse boolean value {@code (~this)} as defined by lua not operator
+ * @return {@link #TRUE} if {@link #NIL} or {@link #FALSE}, otherwise {@link #FALSE}
*/
public LuaValue not() { return FALSE; }
- /** 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 {@link LuaNumber} if numeric,
+ /** 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 {@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
*/
public LuaValue neg() { return checkmetatag(UNM, "attempt to perform arithmetic on ").call(this); }
- /** Length operator: return lua length of object {@code (#this)} including metatag processing as java int
+ /** Length operator: return lua length of object {@code (#this)} including metatag processing as java int
* @return length as defined by the lua # operator
* or metatag processing result
* @throws LuaError if {@code this} is not a table or string, and has no {@link #LEN} metatag
*/
public LuaValue len() { return checkmetatag(LEN, "attempt to get length of ").call(this); }
- /** Length operator: return lua length of object {@code (#this)} including metatag processing as java int
+ /** Length operator: return lua length of object {@code (#this)} including metatag processing as java int
* @return length as defined by the lua # operator
* or metatag processing result converted to java int using {@link #toint()}
* @throws LuaError if {@code this} is not a table or string, and has no {@link #LEN} metatag
@@ -2031,43 +2029,43 @@ protected LuaValue callmt() {
public int rawlen() { typerror("table or string"); return 0; }
// object equality, used for key comparison
- public boolean equals(Object obj) { return this == obj; }
+ public boolean equals(Object obj) { return this == obj; }
- /** Equals: Perform equality comparison with another value
+ /** Equals: Perform equality comparison with another value
* including metatag processing using {@link #EQ}.
* @param val The value to compare with.
- * @return {@link #TRUE} if values are comparable and {@code (this == rhs)},
- * {@link #FALSE} if comparable but not equal,
- * {@link LuaValue} if metatag processing occurs.
+ * @return {@link #TRUE} if values are comparable and {@code (this == rhs)},
+ * {@link #FALSE} if comparable but not equal,
+ * {@link LuaValue} if metatag processing occurs.
* @see #eq_b(LuaValue)
* @see #raweq(LuaValue)
* @see #neq(LuaValue)
* @see #eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
* @see #EQ
*/
- public LuaValue eq( LuaValue val ) { return this == val? TRUE: FALSE; }
+ public LuaValue eq( LuaValue val ) { return eq_b(val)? TRUE: FALSE; }
- /** Equals: Perform equality comparison with another value
- * including metatag processing using {@link #EQ},
+ /** Equals: Perform equality comparison with another value
+ * including metatag processing using {@link #EQ},
* and return java boolean
* @param val The value to compare with.
- * @return true if values are comparable and {@code (this == rhs)},
- * false if comparable but not equal,
- * result converted to java boolean if metatag processing occurs.
+ * @return true if values are comparable and {@code (this == rhs)},
+ * false if comparable but not equal,
+ * result converted to java boolean if metatag processing occurs.
* @see #eq(LuaValue)
* @see #raweq(LuaValue)
* @see #neq_b(LuaValue)
* @see #eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
* @see #EQ
*/
- public boolean eq_b( LuaValue val ) { return this == val; }
+ public boolean eq_b( LuaValue val ) { return this == val; }
- /** Notquals: Perform inequality comparison with another value
+ /** Notquals: Perform inequality comparison with another value
* including metatag processing using {@link #EQ}.
* @param val The value to compare with.
- * @return {@link #TRUE} if values are comparable and {@code (this != rhs)},
- * {@link #FALSE} if comparable but equal,
- * inverse of {@link LuaValue} converted to {@link LuaBoolean} if metatag processing occurs.
+ * @return {@link #TRUE} if values are comparable and {@code (this != rhs)},
+ * {@link #FALSE} if comparable but equal,
+ * inverse of {@link LuaValue} converted to {@link LuaBoolean} if metatag processing occurs.
* @see #eq(LuaValue)
* @see #raweq(LuaValue)
* @see #eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
@@ -2075,12 +2073,12 @@ protected LuaValue callmt() {
*/
public LuaValue neq( LuaValue val ) { return eq_b(val)? FALSE: TRUE; }
- /** Notquals: Perform inequality comparison with another value
+ /** Notquals: Perform inequality comparison with another value
* including metatag processing using {@link #EQ}.
* @param val The value to compare with.
- * @return true if values are comparable and {@code (this != rhs)},
- * false if comparable but equal,
- * inverse of result converted to boolean if metatag processing occurs.
+ * @return true if values are comparable and {@code (this != rhs)},
+ * false if comparable but equal,
+ * inverse of result converted to boolean if metatag processing occurs.
* @see #eq_b(LuaValue)
* @see #raweq(LuaValue)
* @see #eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
@@ -2088,10 +2086,10 @@ protected LuaValue callmt() {
*/
public boolean neq_b( LuaValue val ) { return !eq_b(val); }
- /** Equals: Perform direct equality comparison with another value
+ /** Equals: Perform direct equality comparison with another value
* without metatag processing.
* @param val The value to compare with.
- * @return true if {@code (this == rhs)}, false otherwise
+ * @return true if {@code (this == rhs)}, false otherwise
* @see #eq(LuaValue)
* @see #raweq(LuaUserdata)
* @see #raweq(LuaString)
@@ -2101,52 +2099,52 @@ protected LuaValue callmt() {
*/
public boolean raweq( LuaValue val ) { return this == val; }
- /** Equals: Perform direct equality comparison with a {@link LuaUserdata} value
+ /** Equals: Perform direct equality comparison with a {@link LuaUserdata} value
* without metatag processing.
* @param val The {@link LuaUserdata} to compare with.
- * @return true if {@code this} is userdata
- * and their metatables are the same using ==
+ * @return true if {@code this} is userdata
+ * and their metatables are the same using ==
* and their instances are equal using {@link #equals(Object)},
- * otherwise false
+ * otherwise false
* @see #eq(LuaValue)
* @see #raweq(LuaValue)
*/
public boolean raweq( LuaUserdata val ) { return false; }
- /** Equals: Perform direct equality comparison with a {@link LuaString} value
+ /** Equals: Perform direct equality comparison with a {@link LuaString} value
* without metatag processing.
* @param val The {@link LuaString} to compare with.
- * @return true if {@code this} is a {@link LuaString}
+ * @return true if {@code this} is a {@link LuaString}
* and their byte sequences match,
- * otherwise false
+ * otherwise false
*/
public boolean raweq( LuaString val ) { return false; }
- /** Equals: Perform direct equality comparison with a double value
+ /** Equals: Perform direct equality comparison with a double value
* without metatag processing.
* @param val The double value to compare with.
- * @return true if {@code this} is a {@link LuaNumber}
+ * @return true if {@code this} is a {@link LuaNumber}
* whose value equals val,
- * otherwise false
+ * otherwise false
*/
public boolean raweq( double val ) { return false; }
- /** Equals: Perform direct equality comparison with a int value
+ /** Equals: Perform direct equality comparison with a int value
* without metatag processing.
* @param val The double value to compare with.
- * @return true if {@code this} is a {@link LuaNumber}
+ * @return true if {@code this} is a {@link LuaNumber}
* whose value equals val,
- * otherwise false
+ * otherwise false
*/
public boolean raweq( int val ) { return false; }
- /** Perform equality testing metatag processing
+ /** Perform equality testing metatag processing
* @param lhs left-hand-side of equality expression
* @param lhsmt metatag value for left-hand-side
- * @param rhs right-hand-side of equality expression
+ * @param rhs right-hand-side of equality expression
* @param rhsmt metatag value for right-hand-side
* @return true if metatag processing result is not {@link #NIL} or {@link #FALSE}
- * @throws LuaError if metatag was not defined for either operand
+ * @throws LuaError if metatag was not defined for either operand
* @see #equals(Object)
* @see #eq(LuaValue)
* @see #raweq(LuaValue)
@@ -2157,105 +2155,105 @@ public static final boolean eqmtcall(LuaValue lhs, LuaValue lhsmt, LuaValue rhs,
return h.isnil() || h!=rhsmt.rawget(EQ)? false: h.call(lhs,rhs).toboolean();
}
- /** Add: Perform numeric add operation with another value
+ /** Add: Perform numeric add operation with another value
* including metatag processing.
*
* Each operand must derive from {@link LuaNumber}
* or derive from {@link LuaString} and be convertible to a number
*
* @param rhs The right-hand-side value to perform the add with
- * @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 #ADD} metatag defined
+ * @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 #ADD} metatag defined
* @see #arithmt(LuaValue, LuaValue)
*/
public LuaValue add( LuaValue rhs ) { return arithmt(ADD,rhs); }
- /** Add: Perform numeric add operation with another value
+ /** Add: Perform numeric add operation with another value
* of double type with metatag processing
*
* {@code this} must derive from {@link LuaNumber}
* or derive from {@link LuaString} and be convertible to a number
*
* @param rhs The right-hand-side value to perform the add with
- * @return value of {@code (this + rhs)} if this is numeric
- * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @return value of {@code (this + rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
* @see #add(LuaValue)
*/
public LuaValue add(double rhs) { return arithmtwith(ADD,rhs); }
- /** Add: Perform numeric add operation with another value
+ /** Add: Perform numeric add operation with another value
* of int type with metatag processing
*
* {@code this} must derive from {@link LuaNumber}
* or derive from {@link LuaString} and be convertible to a number
*
* @param rhs The right-hand-side value to perform the add with
- * @return value of {@code (this + rhs)} if this is numeric
- * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @return value of {@code (this + rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
* @see #add(LuaValue)
*/
public LuaValue add(int rhs) { return add((double)rhs); }
- /** Subtract: Perform numeric subtract operation with another value
- * of unknown type,
+ /** Subtract: Perform numeric subtract operation with another value
+ * of unknown type,
* including metatag processing.
*
* Each operand must derive from {@link LuaNumber}
* or derive from {@link LuaString} and be convertible to a number
*
* @param rhs The right-hand-side value to perform the subtract with
- * @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 #SUB} metatag defined
+ * @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 #SUB} metatag defined
* @see #arithmt(LuaValue, LuaValue)
*/
public LuaValue sub( LuaValue rhs ) { return arithmt(SUB,rhs); }
- /** Subtract: Perform numeric subtract operation with another value
+ /** Subtract: Perform numeric subtract operation with another value
* of double type with metatag processing
*
* {@code this} must derive from {@link LuaNumber}
* or derive from {@link LuaString} and be convertible to a number
*
* @param rhs The right-hand-side value to perform the subtract with
- * @return value of {@code (this - rhs)} if this is numeric
- * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @return value of {@code (this - rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
* @see #sub(LuaValue)
*/
public LuaValue sub( double rhs ) { return aritherror("sub"); }
- /** Subtract: Perform numeric subtract operation with another value
+ /** Subtract: Perform numeric subtract operation with another value
* of int type with metatag processing
*
* {@code this} must derive from {@link LuaNumber}
* or derive from {@link LuaString} and be convertible to a number
*
* @param rhs The right-hand-side value to perform the subtract with
- * @return value of {@code (this - rhs)} if this is numeric
- * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @return value of {@code (this - rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
* @see #sub(LuaValue)
*/
public LuaValue sub( int rhs ) { return aritherror("sub"); }
- /** Reverse-subtract: Perform numeric subtract operation from an int value
+ /** Reverse-subtract: Perform numeric subtract operation from an int value
* with metatag processing
*
* {@code this} must derive from {@link LuaNumber}
* or derive from {@link LuaString} and be convertible to a number
*
* @param lhs The left-hand-side value from which to perform the subtraction
- * @return value of {@code (lhs - this)} if this is numeric
- * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @return value of {@code (lhs - this)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
* @see #sub(LuaValue)
* @see #sub(double)
* @see #sub(int)
*/
public LuaValue subFrom(double lhs) { return arithmtwith(SUB,lhs); }
- /** Reverse-subtract: Perform numeric subtract operation from a double value
+ /** Reverse-subtract: Perform numeric subtract operation from a double value
* without metatag processing
*
* {@code this} must derive from {@link LuaNumber}
@@ -2264,144 +2262,144 @@ public static final boolean eqmtcall(LuaValue lhs, LuaValue lhsmt, LuaValue rhs,
* For metatag processing {@link #sub(LuaValue)} must be used
*
* @param lhs The left-hand-side value from which to perform the subtraction
- * @return value of {@code (lhs - this)} if this is numeric
- * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @return value of {@code (lhs - this)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
* @see #sub(LuaValue)
* @see #sub(double)
* @see #sub(int)
*/
public LuaValue subFrom(int lhs) { return subFrom((double)lhs); }
- /** Multiply: Perform numeric multiply operation with another value
- * of unknown type,
+ /** Multiply: Perform numeric multiply operation with another value
+ * of unknown type,
* including metatag processing.
*
* Each operand must derive from {@link LuaNumber}
* or derive from {@link LuaString} and be convertible to a number
*
* @param rhs The right-hand-side value to perform the multiply with
- * @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 #MUL} metatag defined
+ * @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 #MUL} metatag defined
* @see #arithmt(LuaValue, LuaValue)
*/
public LuaValue mul( LuaValue rhs ) { return arithmt(MUL,rhs); }
- /** Multiply: Perform numeric multiply operation with another value
+ /** Multiply: Perform numeric multiply operation with another value
* of double type with metatag processing
*
* {@code this} must derive from {@link LuaNumber}
* or derive from {@link LuaString} and be convertible to a number
*
* @param rhs The right-hand-side value to perform the multiply with
- * @return value of {@code (this * rhs)} if this is numeric
- * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @return value of {@code (this * rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
* @see #mul(LuaValue)
*/
public LuaValue mul(double rhs) { return arithmtwith(MUL,rhs); }
- /** Multiply: Perform numeric multiply operation with another value
+ /** Multiply: Perform numeric multiply operation with another value
* of int type with metatag processing
*
* {@code this} must derive from {@link LuaNumber}
* or derive from {@link LuaString} and be convertible to a number
*
* @param rhs The right-hand-side value to perform the multiply with
- * @return value of {@code (this * rhs)} if this is numeric
- * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @return value of {@code (this * rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
* @see #mul(LuaValue)
*/
public LuaValue mul(int rhs) { return mul((double)rhs); }
- /** Raise to power: Raise this value to a power
+ /** Raise to power: Raise this value to a power
* including metatag processing.
*
* Each operand must derive from {@link LuaNumber}
* or derive from {@link LuaString} and be convertible to a number
*
* @param rhs The power to raise this value to
- * @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 #POW} metatag defined
+ * @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 #POW} metatag defined
* @see #arithmt(LuaValue, LuaValue)
*/
public LuaValue pow( LuaValue rhs ) { return arithmt(POW,rhs); }
- /** Raise to power: Raise this value to a power
+ /** Raise to power: Raise this value to a power
* of double type with metatag processing
*
* {@code this} must derive from {@link LuaNumber}
* or derive from {@link LuaString} and be convertible to a number
*
* @param rhs The power to raise this value to
- * @return value of {@code (this ^ rhs)} if this is numeric
- * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @return value of {@code (this ^ rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
* @see #pow(LuaValue)
*/
public LuaValue pow( double rhs ) { return aritherror("pow"); }
- /** Raise to power: Raise this value to a power
+ /** Raise to power: Raise this value to a power
* of int type with metatag processing
*
* {@code this} must derive from {@link LuaNumber}
* or derive from {@link LuaString} and be convertible to a number
*
* @param rhs The power to raise this value to
- * @return value of {@code (this ^ rhs)} if this is numeric
- * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @return value of {@code (this ^ rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
* @see #pow(LuaValue)
*/
public LuaValue pow( int rhs ) { return aritherror("pow"); }
- /** Reverse-raise to power: Raise another value of double type to this power
+ /** Reverse-raise to power: Raise another value of double type to this power
* with metatag processing
*
* {@code this} must derive from {@link LuaNumber}
* or derive from {@link LuaString} and be convertible to a number
*
* @param lhs The left-hand-side value which will be raised to this power
- * @return value of {@code (lhs ^ this)} if this is numeric
- * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @return value of {@code (lhs ^ this)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
* @see #pow(LuaValue)
* @see #pow(double)
* @see #pow(int)
*/
public LuaValue powWith(double lhs) { return arithmtwith(POW,lhs); }
- /** Reverse-raise to power: Raise another value of double type to this power
+ /** Reverse-raise to power: Raise another value of double type to this power
* with metatag processing
*
* {@code this} must derive from {@link LuaNumber}
* or derive from {@link LuaString} and be convertible to a number
*
* @param lhs The left-hand-side value which will be raised to this power
- * @return value of {@code (lhs ^ this)} if this is numeric
- * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @return value of {@code (lhs ^ this)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
* @see #pow(LuaValue)
* @see #pow(double)
* @see #pow(int)
*/
public LuaValue powWith(int lhs) { return powWith((double)lhs); }
- /** Divide: Perform numeric divide operation by another value
- * of unknown type,
+ /** Divide: Perform numeric divide operation by another value
+ * of unknown type,
* including metatag processing.
*
* Each operand must derive from {@link LuaNumber}
* or derive from {@link LuaString} and be convertible to a number
*
* @param rhs The right-hand-side value to perform the divulo with
- * @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 #DIV} metatag defined
+ * @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 #DIV} metatag defined
* @see #arithmt(LuaValue, LuaValue)
*/
public LuaValue div( LuaValue rhs ) { return arithmt(DIV,rhs); }
- /** Divide: Perform numeric divide operation by another value
+ /** Divide: Perform numeric divide operation by another value
* of double type without metatag processing
*
* {@code this} must derive from {@link LuaNumber}
@@ -2410,13 +2408,13 @@ public static final boolean eqmtcall(LuaValue lhs, LuaValue lhsmt, LuaValue rhs,
* For metatag processing {@link #div(LuaValue)} must be used
*
* @param rhs The right-hand-side value to perform the divulo with
- * @return value of {@code (this / rhs)} if this is numeric
- * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @return value of {@code (this / rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
* @see #div(LuaValue)
*/
public LuaValue div( double rhs ) { return aritherror("div"); }
- /** Divide: Perform numeric divide operation by another value
+ /** Divide: Perform numeric divide operation by another value
* of int type without metatag processing
*
* {@code this} must derive from {@link LuaNumber}
@@ -2425,44 +2423,44 @@ public static final boolean eqmtcall(LuaValue lhs, LuaValue lhsmt, LuaValue rhs,
* For metatag processing {@link #div(LuaValue)} must be used
*
* @param rhs The right-hand-side value to perform the divulo with
- * @return value of {@code (this / rhs)} if this is numeric
- * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @return value of {@code (this / rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
* @see #div(LuaValue)
*/
public LuaValue div( int rhs ) { return aritherror("div"); }
- /** Reverse-divide: Perform numeric divide operation into another value
+ /** Reverse-divide: Perform numeric divide operation into another value
* with metatag processing
*
* {@code this} must derive from {@link LuaNumber}
* or derive from {@link LuaString} and be convertible to a number
*
* @param lhs The left-hand-side value which will be divided by this
- * @return value of {@code (lhs / this)} if this is numeric
- * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @return value of {@code (lhs / this)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
* @see #div(LuaValue)
* @see #div(double)
* @see #div(int)
*/
public LuaValue divInto(double lhs) { return arithmtwith(DIV,lhs); }
- /** Modulo: Perform numeric modulo operation with another value
- * of unknown type,
+ /** Modulo: Perform numeric modulo operation with another value
+ * of unknown type,
* including metatag processing.
*
* Each operand must derive from {@link LuaNumber}
* or derive from {@link LuaString} and be convertible to a number
*
* @param rhs The right-hand-side value to perform the modulo with
- * @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
+ * @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
* @see #arithmt(LuaValue, LuaValue)
*/
public LuaValue mod( LuaValue rhs ) { return arithmt(MOD,rhs); }
- /** Modulo: Perform numeric modulo operation with another value
+ /** Modulo: Perform numeric modulo operation with another value
* of double type without metatag processing
*
* {@code this} must derive from {@link LuaNumber}
@@ -2471,13 +2469,13 @@ public static final boolean eqmtcall(LuaValue lhs, LuaValue lhsmt, LuaValue rhs,
* For metatag processing {@link #mod(LuaValue)} must be used
*
* @param rhs The right-hand-side value to perform the modulo with
- * @return value of {@code (this % rhs)} if this is numeric
- * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @return value of {@code (this % rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
* @see #mod(LuaValue)
*/
public LuaValue mod( double rhs ) { return aritherror("mod"); }
- /** Modulo: Perform numeric modulo operation with another value
+ /** Modulo: Perform numeric modulo operation with another value
* of int type without metatag processing
*
* {@code this} must derive from {@link LuaNumber}
@@ -2486,35 +2484,35 @@ public static final boolean eqmtcall(LuaValue lhs, LuaValue lhsmt, LuaValue rhs,
* For metatag processing {@link #mod(LuaValue)} must be used
*
* @param rhs The right-hand-side value to perform the modulo with
- * @return value of {@code (this % rhs)} if this is numeric
- * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @return value of {@code (this % rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
* @see #mod(LuaValue)
*/
public LuaValue mod( int rhs ) { return aritherror("mod"); }
- /** Reverse-modulo: Perform numeric modulo operation from another value
+ /** Reverse-modulo: Perform numeric modulo operation from another value
* with metatag processing
*
* {@code this} must derive from {@link LuaNumber}
* or derive from {@link LuaString} and be convertible to a number
*
* @param lhs The left-hand-side value which will be modulo'ed by this
- * @return value of {@code (lhs % this)} if this is numeric
- * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @return value of {@code (lhs % this)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
* @see #mod(LuaValue)
* @see #mod(double)
* @see #mod(int)
*/
public LuaValue modFrom(double lhs) { return arithmtwith(MOD,lhs); }
- /** Perform metatag processing for arithmetic operations.
+ /** Perform metatag processing for arithmetic operations.
*
- * Finds the supplied metatag value for {@code this} or {@code op2} and invokes it,
- * or throws {@link LuaError} if neither is defined.
+ * Finds the supplied metatag value for {@code this} or {@code op2} and invokes it,
+ * or throws {@link LuaError} if neither is defined.
* @param tag The metatag to look up
* @param op2 The other operand value to perform the operation with
* @return {@link LuaValue} resulting from metatag processing
- * @throws LuaError if metatag was not defined for either operand
+ * @throws LuaError if metatag was not defined for either operand
* @see #add(LuaValue)
* @see #sub(LuaValue)
* @see #mul(LuaValue)
@@ -2538,14 +2536,14 @@ protected LuaValue arithmt(LuaValue tag, LuaValue op2) {
return h.call( this, op2 );
}
- /** Perform metatag processing for arithmetic operations when the left-hand-side is a number.
+ /** Perform metatag processing for arithmetic operations when the left-hand-side is a number.
*
- * Finds the supplied metatag value for {@code this} and invokes it,
- * or throws {@link LuaError} if neither is defined.
+ * Finds the supplied metatag value for {@code this} and invokes it,
+ * or throws {@link LuaError} if neither is defined.
* @param tag The metatag to look up
* @param op1 The value of the left-hand-side to perform the operation with
* @return {@link LuaValue} resulting from metatag processing
- * @throws LuaError if metatag was not defined for either operand
+ * @throws LuaError if metatag was not defined for either operand
* @see #add(LuaValue)
* @see #sub(LuaValue)
* @see #mul(LuaValue)
@@ -2566,16 +2564,16 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
return h.call( LuaValue.valueOf(op1), this );
}
- /** Less than: Perform numeric or string comparison with another value
- * of unknown type,
+ /** Less than: Perform numeric or string comparison with another value
+ * of unknown type,
* including metatag processing, and returning {@link LuaValue}.
*
* To be comparable, both operands must derive from {@link LuaString}
- * or both must derive from {@link LuaNumber}.
+ * or both must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return {@link #TRUE} if {@code (this < rhs)}, {@link #FALSE} if not,
- * or {@link LuaValue} if metatag processing occurs
+ * @return {@link #TRUE} if {@code (this < rhs)}, {@link #FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
* @throws LuaError if either both operands are not a strings or both are not numbers
* and no {@link #LT} metatag is defined.
* @see #gteq_b(LuaValue)
@@ -2583,15 +2581,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public LuaValue lt( LuaValue rhs ) { return comparemt(LT,rhs); }
- /** Less than: Perform numeric comparison with another value
- * of double type,
+ /** Less than: Perform numeric comparison with another value
+ * of double type,
* including metatag processing, and returning {@link LuaValue}.
*
- * To be comparable, this must derive from {@link LuaNumber}.
+ * To be comparable, this must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return {@link #TRUE} if {@code (this < rhs)}, {@link #FALSE} if not,
- * or {@link LuaValue} if metatag processing occurs
+ * @return {@link #TRUE} if {@code (this < rhs)}, {@link #FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
* @throws LuaError if this is not a number
* and no {@link #LT} metatag is defined.
* @see #gteq_b(double)
@@ -2599,15 +2597,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public LuaValue lt( double rhs ) { return compareerror("number"); }
- /** Less than: Perform numeric comparison with another value
- * of int type,
+ /** Less than: Perform numeric comparison with another value
+ * of int type,
* including metatag processing, and returning {@link LuaValue}.
*
- * To be comparable, this must derive from {@link LuaNumber}.
+ * To be comparable, this must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return {@link #TRUE} if {@code (this < rhs)}, {@link #FALSE} if not,
- * or {@link LuaValue} if metatag processing occurs
+ * @return {@link #TRUE} if {@code (this < rhs)}, {@link #FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
* @throws LuaError if this is not a number
* and no {@link #LT} metatag is defined.
* @see #gteq_b(int)
@@ -2615,15 +2613,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public LuaValue lt( int rhs ) { return compareerror("number"); }
- /** Less than: Perform numeric or string comparison with another value
- * of unknown type, including metatag processing,
+ /** Less than: Perform numeric or string comparison with another value
+ * of unknown type, including metatag processing,
* and returning java boolean.
*
* To be comparable, both operands must derive from {@link LuaString}
- * or both must derive from {@link LuaNumber}.
+ * or both must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return true if {@code (this < rhs)}, false if not,
+ * @return true if {@code (this < rhs)}, false if not,
* and boolean interpreation of result if metatag processing occurs.
* @throws LuaError if either both operands are not a strings or both are not numbers
* and no {@link #LT} metatag is defined.
@@ -2632,15 +2630,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public boolean lt_b( LuaValue rhs ) { return comparemt(LT,rhs).toboolean(); }
- /** Less than: Perform numeric comparison with another value
- * of int type,
- * including metatag processing,
+ /** Less than: Perform numeric comparison with another value
+ * of int type,
+ * including metatag processing,
* and returning java boolean.
*
- * To be comparable, this must derive from {@link LuaNumber}.
+ * To be comparable, this must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return true if {@code (this < rhs)}, false if not,
+ * @return true if {@code (this < rhs)}, false if not,
* and boolean interpreation of result if metatag processing occurs.
* @throws LuaError if this is not a number
* and no {@link #LT} metatag is defined.
@@ -2649,15 +2647,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public boolean lt_b( int rhs ) { compareerror("number"); return false; }
- /** Less than: Perform numeric or string comparison with another value
- * of unknown type, including metatag processing,
+ /** Less than: Perform numeric or string comparison with another value
+ * of unknown type, including metatag processing,
* and returning java boolean.
*
* To be comparable, both operands must derive from {@link LuaString}
- * or both must derive from {@link LuaNumber}.
+ * or both must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return true if {@code (this < rhs)}, false if not,
+ * @return true if {@code (this < rhs)}, false if not,
* and boolean interpreation of result if metatag processing occurs.
* @throws LuaError if either both operands are not a strings or both are not numbers
* and no {@link #LT} metatag is defined.
@@ -2666,16 +2664,16 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public boolean lt_b( double rhs ) { compareerror("number"); return false; }
- /** Less than or equals: Perform numeric or string comparison with another value
- * of unknown type,
+ /** Less than or equals: Perform numeric or string comparison with another value
+ * of unknown type,
* including metatag processing, and returning {@link LuaValue}.
*
* To be comparable, both operands must derive from {@link LuaString}
- * or both must derive from {@link LuaNumber}.
+ * or both must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return {@link #TRUE} if {@code (this <= rhs)}, {@link #FALSE} if not,
- * or {@link LuaValue} if metatag processing occurs
+ * @return {@link #TRUE} if {@code (this <= rhs)}, {@link #FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
* @throws LuaError if either both operands are not a strings or both are not numbers
* and no {@link #LE} metatag is defined.
* @see #gteq_b(LuaValue)
@@ -2683,15 +2681,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public LuaValue lteq( LuaValue rhs ) { return comparemt(LE,rhs); }
- /** Less than or equals: Perform numeric comparison with another value
- * of double type,
+ /** Less than or equals: Perform numeric comparison with another value
+ * of double type,
* including metatag processing, and returning {@link LuaValue}.
*
- * To be comparable, this must derive from {@link LuaNumber}.
+ * To be comparable, this must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return {@link #TRUE} if {@code (this <= rhs)}, {@link #FALSE} if not,
- * or {@link LuaValue} if metatag processing occurs
+ * @return {@link #TRUE} if {@code (this <= rhs)}, {@link #FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
* @throws LuaError if this is not a number
* and no {@link #LE} metatag is defined.
* @see #gteq_b(double)
@@ -2699,15 +2697,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public LuaValue lteq( double rhs ) { return compareerror("number"); }
- /** Less than or equals: Perform numeric comparison with another value
- * of int type,
+ /** Less than or equals: Perform numeric comparison with another value
+ * of int type,
* including metatag processing, and returning {@link LuaValue}.
*
- * To be comparable, this must derive from {@link LuaNumber}.
+ * To be comparable, this must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return {@link #TRUE} if {@code (this <= rhs)}, {@link #FALSE} if not,
- * or {@link LuaValue} if metatag processing occurs
+ * @return {@link #TRUE} if {@code (this <= rhs)}, {@link #FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
* @throws LuaError if this is not a number
* and no {@link #LE} metatag is defined.
* @see #gteq_b(int)
@@ -2715,15 +2713,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public LuaValue lteq( int rhs ) { return compareerror("number"); }
- /** Less than or equals: Perform numeric or string comparison with another value
- * of unknown type, including metatag processing,
+ /** Less than or equals: Perform numeric or string comparison with another value
+ * of unknown type, including metatag processing,
* and returning java boolean.
*
* To be comparable, both operands must derive from {@link LuaString}
- * or both must derive from {@link LuaNumber}.
+ * or both must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return true if {@code (this <= rhs)}, false if not,
+ * @return true if {@code (this <= rhs)}, false if not,
* and boolean interpreation of result if metatag processing occurs.
* @throws LuaError if either both operands are not a strings or both are not numbers
* and no {@link #LE} metatag is defined.
@@ -2732,15 +2730,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public boolean lteq_b( LuaValue rhs ) { return comparemt(LE,rhs).toboolean(); }
- /** Less than or equals: Perform numeric comparison with another value
- * of int type,
- * including metatag processing,
+ /** Less than or equals: Perform numeric comparison with another value
+ * of int type,
+ * including metatag processing,
* and returning java boolean.
*
- * To be comparable, this must derive from {@link LuaNumber}.
+ * To be comparable, this must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return true if {@code (this <= rhs)}, false if not,
+ * @return true if {@code (this <= rhs)}, false if not,
* and boolean interpreation of result if metatag processing occurs.
* @throws LuaError if this is not a number
* and no {@link #LE} metatag is defined.
@@ -2749,15 +2747,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public boolean lteq_b( int rhs ) { compareerror("number"); return false; }
- /** Less than or equals: Perform numeric comparison with another value
- * of double type,
- * including metatag processing,
+ /** Less than or equals: Perform numeric comparison with another value
+ * of double type,
+ * including metatag processing,
* and returning java boolean.
*
- * To be comparable, this must derive from {@link LuaNumber}.
+ * To be comparable, this must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return true if {@code (this <= rhs)}, false if not,
+ * @return true if {@code (this <= rhs)}, false if not,
* and boolean interpreation of result if metatag processing occurs.
* @throws LuaError if this is not a number
* and no {@link #LE} metatag is defined.
@@ -2766,16 +2764,16 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public boolean lteq_b( double rhs ) { compareerror("number"); return false; }
- /** Greater than: Perform numeric or string comparison with another value
- * of unknown type,
+ /** Greater than: Perform numeric or string comparison with another value
+ * of unknown type,
* including metatag processing, and returning {@link LuaValue}.
*
* To be comparable, both operands must derive from {@link LuaString}
- * or both must derive from {@link LuaNumber}.
+ * or both must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return {@link #TRUE} if {@code (this > rhs)}, {@link #FALSE} if not,
- * or {@link LuaValue} if metatag processing occurs
+ * @return {@link #TRUE} if {@code (this > rhs)}, {@link #FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
* @throws LuaError if either both operands are not a strings or both are not numbers
* and no {@link #LE} metatag is defined.
* @see #gteq_b(LuaValue)
@@ -2783,15 +2781,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public LuaValue gt( LuaValue rhs ) { return rhs.comparemt(LE,this); }
- /** Greater than: Perform numeric comparison with another value
- * of double type,
+ /** Greater than: Perform numeric comparison with another value
+ * of double type,
* including metatag processing, and returning {@link LuaValue}.
*
- * To be comparable, this must derive from {@link LuaNumber}.
+ * To be comparable, this must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return {@link #TRUE} if {@code (this > rhs)}, {@link #FALSE} if not,
- * or {@link LuaValue} if metatag processing occurs
+ * @return {@link #TRUE} if {@code (this > rhs)}, {@link #FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
* @throws LuaError if this is not a number
* and no {@link #LE} metatag is defined.
* @see #gteq_b(double)
@@ -2799,15 +2797,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public LuaValue gt( double rhs ) { return compareerror("number"); }
- /** Greater than: Perform numeric comparison with another value
- * of int type,
+ /** Greater than: Perform numeric comparison with another value
+ * of int type,
* including metatag processing, and returning {@link LuaValue}.
*
- * To be comparable, this must derive from {@link LuaNumber}.
+ * To be comparable, this must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return {@link #TRUE} if {@code (this > rhs)}, {@link #FALSE} if not,
- * or {@link LuaValue} if metatag processing occurs
+ * @return {@link #TRUE} if {@code (this > rhs)}, {@link #FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
* @throws LuaError if this is not a number
* and no {@link #LE} metatag is defined.
* @see #gteq_b(int)
@@ -2815,15 +2813,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public LuaValue gt( int rhs ) { return compareerror("number"); }
- /** Greater than: Perform numeric or string comparison with another value
- * of unknown type, including metatag processing,
+ /** Greater than: Perform numeric or string comparison with another value
+ * of unknown type, including metatag processing,
* and returning java boolean.
*
* To be comparable, both operands must derive from {@link LuaString}
- * or both must derive from {@link LuaNumber}.
+ * or both must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return true if {@code (this > rhs)}, false if not,
+ * @return true if {@code (this > rhs)}, false if not,
* and boolean interpreation of result if metatag processing occurs.
* @throws LuaError if either both operands are not a strings or both are not numbers
* and no {@link #LE} metatag is defined.
@@ -2832,15 +2830,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public boolean gt_b( LuaValue rhs ) { return rhs.comparemt(LE,this).toboolean(); }
- /** Greater than: Perform numeric comparison with another value
- * of int type,
- * including metatag processing,
+ /** Greater than: Perform numeric comparison with another value
+ * of int type,
+ * including metatag processing,
* and returning java boolean.
*
- * To be comparable, this must derive from {@link LuaNumber}.
+ * To be comparable, this must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return true if {@code (this > rhs)}, false if not,
+ * @return true if {@code (this > rhs)}, false if not,
* and boolean interpreation of result if metatag processing occurs.
* @throws LuaError if this is not a number
* and no {@link #LE} metatag is defined.
@@ -2849,15 +2847,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public boolean gt_b( int rhs ) { compareerror("number"); return false; }
- /** Greater than: Perform numeric or string comparison with another value
- * of unknown type, including metatag processing,
+ /** Greater than: Perform numeric or string comparison with another value
+ * of unknown type, including metatag processing,
* and returning java boolean.
*
* To be comparable, both operands must derive from {@link LuaString}
- * or both must derive from {@link LuaNumber}.
+ * or both must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return true if {@code (this > rhs)}, false if not,
+ * @return true if {@code (this > rhs)}, false if not,
* and boolean interpreation of result if metatag processing occurs.
* @throws LuaError if either both operands are not a strings or both are not numbers
* and no {@link #LE} metatag is defined.
@@ -2866,16 +2864,16 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public boolean gt_b( double rhs ) { compareerror("number"); return false; }
- /** Greater than or equals: Perform numeric or string comparison with another value
- * of unknown type,
+ /** Greater than or equals: Perform numeric or string comparison with another value
+ * of unknown type,
* including metatag processing, and returning {@link LuaValue}.
*
* To be comparable, both operands must derive from {@link LuaString}
- * or both must derive from {@link LuaNumber}.
+ * or both must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return {@link #TRUE} if {@code (this >= rhs)}, {@link #FALSE} if not,
- * or {@link LuaValue} if metatag processing occurs
+ * @return {@link #TRUE} if {@code (this >= rhs)}, {@link #FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
* @throws LuaError if either both operands are not a strings or both are not numbers
* and no {@link #LT} metatag is defined.
* @see #gteq_b(LuaValue)
@@ -2883,15 +2881,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public LuaValue gteq( LuaValue rhs ) { return rhs.comparemt(LT,this); }
- /** Greater than or equals: Perform numeric comparison with another value
- * of double type,
+ /** Greater than or equals: Perform numeric comparison with another value
+ * of double type,
* including metatag processing, and returning {@link LuaValue}.
*
- * To be comparable, this must derive from {@link LuaNumber}.
+ * To be comparable, this must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return {@link #TRUE} if {@code (this >= rhs)}, {@link #FALSE} if not,
- * or {@link LuaValue} if metatag processing occurs
+ * @return {@link #TRUE} if {@code (this >= rhs)}, {@link #FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
* @throws LuaError if this is not a number
* and no {@link #LT} metatag is defined.
* @see #gteq_b(double)
@@ -2899,15 +2897,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public LuaValue gteq( double rhs ) { return compareerror("number"); }
- /** Greater than or equals: Perform numeric comparison with another value
- * of int type,
+ /** Greater than or equals: Perform numeric comparison with another value
+ * of int type,
* including metatag processing, and returning {@link LuaValue}.
*
- * To be comparable, this must derive from {@link LuaNumber}.
+ * To be comparable, this must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return {@link #TRUE} if {@code (this >= rhs)}, {@link #FALSE} if not,
- * or {@link LuaValue} if metatag processing occurs
+ * @return {@link #TRUE} if {@code (this >= rhs)}, {@link #FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
* @throws LuaError if this is not a number
* and no {@link #LT} metatag is defined.
* @see #gteq_b(int)
@@ -2915,15 +2913,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public LuaValue gteq( int rhs ) { return valueOf(todouble() >= rhs); }
- /** Greater than or equals: Perform numeric or string comparison with another value
- * of unknown type, including metatag processing,
+ /** Greater than or equals: Perform numeric or string comparison with another value
+ * of unknown type, including metatag processing,
* and returning java boolean.
*
* To be comparable, both operands must derive from {@link LuaString}
- * or both must derive from {@link LuaNumber}.
+ * or both must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return true if {@code (this >= rhs)}, false if not,
+ * @return true if {@code (this >= rhs)}, false if not,
* and boolean interpreation of result if metatag processing occurs.
* @throws LuaError if either both operands are not a strings or both are not numbers
* and no {@link #LT} metatag is defined.
@@ -2932,15 +2930,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public boolean gteq_b( LuaValue rhs ) { return rhs.comparemt(LT,this).toboolean(); }
- /** Greater than or equals: Perform numeric comparison with another value
- * of int type,
- * including metatag processing,
+ /** Greater than or equals: Perform numeric comparison with another value
+ * of int type,
+ * including metatag processing,
* and returning java boolean.
*
- * To be comparable, this must derive from {@link LuaNumber}.
+ * To be comparable, this must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return true if {@code (this >= rhs)}, false if not,
+ * @return true if {@code (this >= rhs)}, false if not,
* and boolean interpreation of result if metatag processing occurs.
* @throws LuaError if this is not a number
* and no {@link #LT} metatag is defined.
@@ -2949,15 +2947,15 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public boolean gteq_b( int rhs ) { compareerror("number"); return false; }
- /** Greater than or equals: Perform numeric comparison with another value
- * of double type,
- * including metatag processing,
+ /** Greater than or equals: Perform numeric comparison with another value
+ * of double type,
+ * including metatag processing,
* and returning java boolean.
*
- * To be comparable, this must derive from {@link LuaNumber}.
+ * To be comparable, this must derive from {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return true if {@code (this >= rhs)}, false if not,
+ * @return true if {@code (this >= rhs)}, false if not,
* and boolean interpreation of result if metatag processing occurs.
* @throws LuaError if this is not a number
* and no {@link #LT} metatag is defined.
@@ -2966,22 +2964,22 @@ protected LuaValue arithmtwith(LuaValue tag, double op1) {
*/
public boolean gteq_b( double rhs ) { compareerror("number"); return false; }
- /** Perform metatag processing for comparison operations.
+ /** Perform metatag processing for comparison operations.
*
- * Finds the supplied metatag value and invokes it,
- * or throws {@link LuaError} if none applies.
+ * Finds the supplied metatag value and invokes it,
+ * or throws {@link LuaError} if none applies.
* @param tag The metatag to look up
* @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,
- * or the metatag values for the two operands are different.
+ * @throws LuaError if metatag was not defined for either operand,
+ * or if the operands are not the same type,
+ * or the metatag values for the two operands are different.
* @see #gt(LuaValue)
* @see #gteq(LuaValue)
* @see #lt(LuaValue)
* @see #lteq(LuaValue)
*/
- public LuaValue comparemt( LuaValue tag, LuaValue op1 ) {
+ public LuaValue comparemt( LuaValue tag, LuaValue op1 ) {
LuaValue h;
if (!(h = metatag(tag)).isnil() || !(h = op1.metatag(tag)).isnil())
return h.call(this, op1);
@@ -2990,116 +2988,116 @@ public LuaValue comparemt( LuaValue tag, LuaValue op1 ) {
return error("attempt to compare "+tag+" on "+typename()+" and "+op1.typename());
}
- /** Perform string comparison with another value
- * of any type
+ /** Perform string comparison with another value
+ * of any type
* using string comparison based on byte values.
*
- * Only strings can be compared, meaning
- * each operand must derive from {@link LuaString}.
+ * Only strings can be compared, meaning
+ * each operand must derive from {@link LuaString}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return 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; }
- /** Perform string comparison with another value
- * known to be a {@link LuaString}
+ /** Perform string comparison with another value
+ * known to be a {@link LuaString}
* using string comparison based on byte values.
*
- * Only strings can be compared, meaning
- * each operand must derive from {@link LuaString}.
+ * Only strings can be compared, meaning
+ * each operand must derive from {@link LuaString}.
*
* @param rhs The right-hand-side value to perform the comparison with
- * @return 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; }
- /** Concatenate another value onto this value and return the result
+ /** Concatenate another value onto this value and return the result
* using rules of lua string concatenation including metatag processing.
*
- * Only strings and numbers as represented can be concatenated, meaning
- * each operand must derive from {@link LuaString} or {@link LuaNumber}.
+ * Only strings and numbers as represented can be concatenated, meaning
+ * each operand must derive from {@link LuaString} or {@link LuaNumber}.
*
* @param rhs The right-hand-side value to perform the operation with
* @return {@link LuaValue} resulting from concatenation of {@code (this .. rhs)}
- * @throws LuaError if either operand is not of an appropriate type,
+ * @throws LuaError if either operand is not of an appropriate type,
* such as nil or a table
*/
public LuaValue concat(LuaValue rhs) { return this.concatmt(rhs); }
- /** Reverse-concatenation: concatenate this value onto another value
- * whose type is unknwon
- * and return the result using rules of lua string concatenation including
- * metatag processing.
+ /** Reverse-concatenation: concatenate this value onto another value
+ * whose type is unknwon
+ * and return the result using rules of lua string concatenation including
+ * metatag processing.
*
- * Only strings and numbers as represented can be concatenated, meaning
- * each operand must derive from {@link LuaString} or {@link LuaNumber}.
+ * Only strings and numbers as represented can be concatenated, meaning
+ * each operand must derive from {@link LuaString} or {@link LuaNumber}.
*
* @param lhs The left-hand-side value onto which this will be concatenated
* @return {@link LuaValue} resulting from concatenation of {@code (lhs .. this)}
- * @throws LuaError if either operand is not of an appropriate type,
+ * @throws LuaError if either operand is not of an appropriate type,
* such as nil or a table
* @see #concat(LuaValue)
*/
public LuaValue concatTo(LuaValue lhs) { return lhs.concatmt(this); }
- /** Reverse-concatenation: concatenate this value onto another value
- * known to be a {@link LuaNumber}
- * and return the result using rules of lua string concatenation including
- * metatag processing.
+ /** Reverse-concatenation: concatenate this value onto another value
+ * known to be a {@link LuaNumber}
+ * and return the result using rules of lua string concatenation including
+ * metatag processing.
*
- * Only strings and numbers as represented can be concatenated, meaning
- * each operand must derive from {@link LuaString} or {@link LuaNumber}.
+ * Only strings and numbers as represented can be concatenated, meaning
+ * each operand must derive from {@link LuaString} or {@link LuaNumber}.
*
* @param lhs The left-hand-side value onto which this will be concatenated
* @return {@link LuaValue} resulting from concatenation of {@code (lhs .. this)}
- * @throws LuaError if either operand is not of an appropriate type,
+ * @throws LuaError if either operand is not of an appropriate type,
* such as nil or a table
* @see #concat(LuaValue)
*/
public LuaValue concatTo(LuaNumber lhs) { return lhs.concatmt(this); }
- /** Reverse-concatenation: concatenate this value onto another value
- * known to be a {@link LuaString}
- * and return the result using rules of lua string concatenation including
- * metatag processing.
+ /** Reverse-concatenation: concatenate this value onto another value
+ * known to be a {@link LuaString}
+ * and return the result using rules of lua string concatenation including
+ * metatag processing.
*
- * Only strings and numbers as represented can be concatenated, meaning
- * each operand must derive from {@link LuaString} or {@link LuaNumber}.
+ * Only strings and numbers as represented can be concatenated, meaning
+ * each operand must derive from {@link LuaString} or {@link LuaNumber}.
*
* @param lhs The left-hand-side value onto which this will be concatenated
* @return {@link LuaValue} resulting from concatenation of {@code (lhs .. this)}
- * @throws LuaError if either operand is not of an appropriate type,
+ * @throws LuaError if either operand is not of an appropriate type,
* such as nil or a table
* @see #concat(LuaValue)
*/
public LuaValue concatTo(LuaString lhs) { return lhs.concatmt(this); }
- /** Convert the value to a {@link Buffer} for more efficient concatenation of
- * multiple strings.
+ /** Convert the value to a {@link Buffer} for more efficient concatenation of
+ * multiple strings.
* @return Buffer instance containing the string or number
*/
public Buffer buffer() { return new Buffer(this); }
- /** Concatenate a {@link Buffer} onto this value and return the result
+ /** Concatenate a {@link Buffer} onto this value and return the result
* using rules of lua string concatenation including metatag processing.
*
- * Only strings and numbers as represented can be concatenated, meaning
- * each operand must derive from {@link LuaString} or {@link LuaNumber}.
+ * Only strings and numbers as represented can be concatenated, meaning
+ * each operand must derive from {@link LuaString} or {@link LuaNumber}.
*
* @param rhs The right-hand-side {@link Buffer} to perform the operation with
* @return LuaString resulting from concatenation of {@code (this .. rhs)}
- * @throws LuaError if either operand is not of an appropriate type,
+ * @throws LuaError if either operand is not of an appropriate type,
* such as nil or a table
*/
public Buffer concat(Buffer rhs) { return rhs.concatTo(this); }
- /** Perform metatag processing for concatenation operations.
+ /** Perform metatag processing for concatenation operations.
*
- * Finds the {@link #CONCAT} metatag value and invokes it,
- * or throws {@link LuaError} if it doesn't exist.
+ * Finds the {@link #CONCAT} metatag value and invokes it,
+ * or throws {@link LuaError} if it doesn't exist.
* @param rhs The right-hand-side value to perform the operation with
* @return {@link LuaValue} resulting from metatag processing for {@link #CONCAT} metatag.
* @throws LuaError if metatag was not defined for either operand
@@ -3123,27 +3121,27 @@ public LuaValue concatmt(LuaValue rhs) {
* This returns either {@code this} or {@code rhs} depending on the boolean value for {@code this}.
*
* @param rhs The right-hand-side value to perform the operation with
- * @return {@code this} if {@code this.toboolean()} is true, {@code rhs} otherwise.
+ * @return {@code this} if {@code this.toboolean()} is true, {@code rhs} otherwise.
*/
public LuaValue or( LuaValue rhs ) { return this.toboolean()? this: rhs; }
- /** Perform end-condition test in for-loop processing.
+ /** Perform end-condition test in for-loop processing.
*
* Used in lua-bytecode to Java-bytecode conversion.
*
* @param limit the numerical limit to complete the for loop
- * @param step the numberical step size to use.
+ * @param step the numberical step size to use.
* @return true if limit has not been reached, false otherwise.
*/
public boolean testfor_b(LuaValue limit, LuaValue step) { return step.gt_b(0)? lteq_b(limit): gteq_b(limit); }
/**
- * Convert this value to a string if it is a {@link LuaString} or {@link LuaNumber},
+ * Convert this value to a string if it is a {@link LuaString} or {@link LuaNumber},
* or throw a {@link LuaError} if it is not
* @return {@link LuaString} corresponding to the value if a string or number
* @throws LuaError if not a string or number
*/
- public LuaString strvalue() { typerror("strValue"); return null; }
+ public LuaString strvalue() { typerror("string or number"); return null; }
/** Return this value as a strong reference, or null if it was weak and is no longer referenced.
* @return {@link LuaValue} referred to, or null if it was weak and is no longer referenced.
@@ -3165,9 +3163,9 @@ public LuaValue concatmt(LuaValue rhs) {
*/
public static LuaInteger valueOf(int i) { return LuaInteger.valueOf(i); }
- /** Convert java double to a {@link LuaValue}.
- * This may return a {@link LuaInteger} or {@link LuaDouble} depending
- * on the value supplied.
+ /** Convert java double to a {@link LuaValue}.
+ * This may return a {@link LuaInteger} or {@link LuaDouble} depending
+ * on the value supplied.
*
* @param d double value to convert
* @return {@link LuaNumber} instance, possibly pooled, whose value is d
@@ -3186,7 +3184,7 @@ public LuaValue concatmt(LuaValue rhs) {
* @param bytes byte array to convert
* @return {@link LuaString} instance, possibly pooled, whose bytes are those in the supplied array
*/
- //public static LuaString valueOf(byte[] bytes) { return LuaString.valueOf(bytes); }
+ public static LuaString valueOf(byte[] bytes) { return LuaString.valueOf(bytes); }
/** Convert bytes in an array to a {@link LuaValue}.
*
@@ -3195,86 +3193,86 @@ public LuaValue concatmt(LuaValue rhs) {
* @param len number of bytes to include in the {@link LuaString}
* @return {@link LuaString} instance, possibly pooled, whose bytes are those in the supplied array
*/
- //public static LuaString valueOf(byte[] bytes, int off, int len) {
- // return LuaString.valueOf(bytes,off,len);
- //}
+ public static LuaString valueOf(byte[] bytes, int off, int len) {
+ return LuaString.valueOf(bytes,off,len);
+ }
- /** Construct an empty {@link LuaTable}.
- * @return new {@link LuaTable} instance with no values and no metatable.
+ /** Construct an empty {@link LuaTable}.
+ * @return new {@link LuaTable} instance with no values and no metatable.
*/
public static LuaTable tableOf() { return new LuaTable(); }
- /** Construct a {@link LuaTable} initialized with supplied array values.
+ /** Construct a {@link LuaTable} initialized with supplied array values.
* @param varargs {@link Varargs} containing the values to use in initialization
* @param firstarg the index of the first argument to use from the varargs, 1 being the first.
- * @return new {@link LuaTable} instance with sequential elements coming from the varargs.
+ * @return new {@link LuaTable} instance with sequential elements coming from the varargs.
*/
public static LuaTable tableOf(Varargs varargs, int firstarg) { return new LuaTable(varargs,firstarg); }
- /** Construct an empty {@link LuaTable} preallocated to hold array and hashed elements
+ /** Construct an empty {@link LuaTable} preallocated to hold array and hashed elements
* @param narray Number of array elements to preallocate
* @param nhash Number of hash elements to preallocate
* @return new {@link LuaTable} instance with no values and no metatable, but preallocated for array and hashed elements.
*/
- public static LuaTable tableOf(int narray, int nhash) { return new LuaTable(narray, nhash); }
+ public static LuaTable tableOf(int narray, int nhash) { return new LuaTable(narray, nhash); }
- /** Construct a {@link LuaTable} initialized with supplied array values.
+ /** Construct a {@link LuaTable} initialized with supplied array values.
* @param unnamedValues array of {@link LuaValue} containing the values to use in initialization
- * @return new {@link LuaTable} instance with sequential elements coming from the array.
+ * @return new {@link LuaTable} instance with sequential elements coming from the array.
*/
public static LuaTable listOf(LuaValue[] unnamedValues) { return new LuaTable(null,unnamedValues,null); }
- /** Construct a {@link LuaTable} initialized with supplied array values.
+ /** Construct a {@link LuaTable} initialized with supplied array values.
* @param unnamedValues array of {@link LuaValue} containing the first values to use in initialization
* @param lastarg {@link Varargs} containing additional values to use in initialization
* to be put after the last unnamedValues element
- * @return new {@link LuaTable} instance with sequential elements coming from the array and varargs.
+ * @return new {@link LuaTable} instance with sequential elements coming from the array and varargs.
*/
public static LuaTable listOf(LuaValue[] unnamedValues,Varargs lastarg) { return new LuaTable(null,unnamedValues,lastarg); }
- /** Construct a {@link LuaTable} initialized with supplied named values.
+ /** Construct a {@link LuaTable} initialized with supplied named values.
* @param namedValues array of {@link LuaValue} containing the keys and values to use in initialization
* in order {@code {key-a, value-a, key-b, value-b, ...} }
- * @return new {@link LuaTable} instance with non-sequential keys coming from the supplied array.
+ * @return new {@link LuaTable} instance with non-sequential keys coming from the supplied array.
*/
- public static LuaTable tableOf(LuaValue[] namedValues) { return new LuaTable(namedValues,null,null); }
+ public static LuaTable tableOf(LuaValue[] namedValues) { return new LuaTable(namedValues,null,null); }
/** Construct a {@link LuaTable} initialized with supplied named values and sequential elements.
* The named values will be assigned first, and the sequential elements will be assigned later,
- * possibly overwriting named values at the same slot if there are conflicts.
+ * possibly overwriting named values at the same slot if there are conflicts.
* @param namedValues array of {@link LuaValue} containing the keys and values to use in initialization
* in order {@code {key-a, value-a, key-b, value-b, ...} }
* @param unnamedValues array of {@link LuaValue} containing the sequenctial elements to use in initialization
* in order {@code {value-1, value-2, ...} }, or null if there are none
- * @return new {@link LuaTable} instance with named and sequential values supplied.
+ * @return new {@link LuaTable} instance with named and sequential values supplied.
*/
- public static LuaTable tableOf(LuaValue[] namedValues, LuaValue[] unnamedValues) {return new LuaTable(namedValues,unnamedValues,null); }
+ public static LuaTable tableOf(LuaValue[] namedValues, LuaValue[] unnamedValues) {return new LuaTable(namedValues,unnamedValues,null); }
/** Construct a {@link LuaTable} initialized with supplied named values and sequential elements in an array part and as varargs.
* The named values will be assigned first, and the sequential elements will be assigned later,
- * possibly overwriting named values at the same slot if there are conflicts.
+ * possibly overwriting named values at the same slot if there are conflicts.
* @param namedValues array of {@link LuaValue} containing the keys and values to use in initialization
* in order {@code {key-a, value-a, key-b, value-b, ...} }
* @param unnamedValues array of {@link LuaValue} containing the first sequenctial elements to use in initialization
* in order {@code {value-1, value-2, ...} }, or null if there are none
- * @param lastarg {@link Varargs} containing additional values to use in the sequential part of the initialization,
+ * @param lastarg {@link Varargs} containing additional values to use in the sequential part of the initialization,
* to be put after the last unnamedValues element
- * @return new {@link LuaTable} instance with named and sequential values supplied.
+ * @return new {@link LuaTable} instance with named and sequential values supplied.
*/
- public static LuaTable tableOf(LuaValue[] namedValues, LuaValue[] unnamedValues, Varargs lastarg) {return new LuaTable(namedValues,unnamedValues,lastarg); }
+ public static LuaTable tableOf(LuaValue[] namedValues, LuaValue[] unnamedValues, Varargs lastarg) {return new LuaTable(namedValues,unnamedValues,lastarg); }
- /** Construct a LuaUserdata for an object.
+ /** Construct a LuaUserdata for an object.
*
* @param o The java instance to be wrapped as userdata
- * @return {@link LuaUserdata} value wrapping the java instance.
+ * @return {@link LuaUserdata} value wrapping the java instance.
*/
public static LuaUserdata userdataOf(Object o) { return new LuaUserdata(o); }
- /** Construct a LuaUserdata for an object with a user supplied metatable.
+ /** Construct a LuaUserdata for an object with a user supplied metatable.
*
* @param o The java instance to be wrapped as userdata
- * @param metatable The metatble to associate with the userdata instance.
- * @return {@link LuaUserdata} value wrapping the java instance.
+ * @param metatable The metatble to associate with the userdata instance.
+ * @return {@link LuaUserdata} value wrapping the java instance.
*/
public static LuaUserdata userdataOf(Object o,LuaValue metatable) { return new LuaUserdata(o,metatable); }
@@ -3292,13 +3290,13 @@ public LuaValue concatmt(LuaValue rhs) {
protected static LuaValue gettable(LuaValue t, LuaValue key) {
LuaValue tm;
int loop = 0;
- do {
+ do {
if (t.istable()) {
LuaValue res = t.rawget(key);
if ((!res.isnil()) || (tm = t.metatag(INDEX)).isnil())
return res;
} else if ((tm = t.metatag(INDEX)).isnil())
- t.indexerror();
+ t.indexerror(key.tojstring());
if (tm.isfunction())
return tm.call(t, key);
t = tm;
@@ -3312,21 +3310,21 @@ protected static LuaValue gettable(LuaValue t, LuaValue key) {
* Perform field assignment including metatag processing.
* @param t {@link LuaValue} on which value is being set, typically a table or something with the metatag {@link LuaValue#NEWINDEX} defined
* @param key {@link LuaValue} naming the field to assign
- * @param value {@link LuaValue} the new value to assign to {@code key}
+ * @param value {@link LuaValue} the new value to assign to {@code key}
* @throws LuaError if there is a loop in metatag processing
- * @return true if assignment or metatag processing succeeded, false otherwise
+ * @return true if assignment or metatag processing succeeded, false otherwise
*/
protected static boolean settable(LuaValue t, LuaValue key, LuaValue value) {
LuaValue tm;
int loop = 0;
- do {
+ do {
if (t.istable()) {
if ((!t.rawget(key).isnil()) || (tm = t.metatag(NEWINDEX)).isnil()) {
t.rawset(key, value);
return true;
}
} else if ((tm = t.metatag(NEWINDEX)).isnil())
- t.typerror("index");
+ throw new LuaError("table expected for set index ('" + key + "') value, got " + t.typename());
if (tm.isfunction()) {
tm.call(t, key, value);
return true;
@@ -3339,9 +3337,9 @@ protected static boolean settable(LuaValue t, LuaValue key, LuaValue value) {
}
/**
- * 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}
+ * 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}
* @return {@link LuaValue} for tag {@code reason}, or {@link LuaValue#NIL}
*/
public LuaValue metatag(LuaValue tag) {
@@ -3352,9 +3350,9 @@ public LuaValue metatag(LuaValue tag) {
}
/**
- * Get particular metatag, or throw {@link LuaError} if it doesn't exist
- * @param tag Metatag name to look up, typically a string such as
- * {@link LuaValue#INDEX} or {@link LuaValue#NEWINDEX}
+ * Get particular metatag, or throw {@link LuaError} 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} that can be called
* @throws LuaError when the lookup fails.
@@ -3362,7 +3360,7 @@ public LuaValue metatag(LuaValue tag) {
protected LuaValue checkmetatag(LuaValue tag, String reason) {
LuaValue h = this.metatag(tag);
if ( h.isnil() )
- throw new LuaError(reason+typename());
+ throw new LuaError(reason + "a " + typename() + " value");
return h;
}
@@ -3386,17 +3384,17 @@ protected static Metatable metatableOf(LuaValue mt) {
}
}
- /** Throw {@link LuaError} indicating index was attempted on illegal type
- * @throws LuaError when called.
+ /** Throw {@link LuaError} indicating index was attempted on illegal type
+ * @throws LuaError when called.
*/
- private void indexerror() {
- error( "attempt to index ? (a "+typename()+" value)" );
+ private void indexerror(String key) {
+ error( "attempt to index ? (a "+typename()+" value) with key '" + key + "'" );
}
/** Construct a {@link Varargs} around an array of {@link LuaValue}s.
*
* @param v The array of {@link LuaValue}s
- * @return {@link Varargs} wrapping the supplied values.
+ * @return {@link Varargs} wrapping the supplied values.
* @see LuaValue#varargsOf(LuaValue, Varargs)
* @see LuaValue#varargsOf(LuaValue[], int, int)
*/
@@ -3404,7 +3402,7 @@ public static Varargs varargsOf(final LuaValue[] v) {
switch ( v.length ) {
case 0: return NONE;
case 1: return v[0];
- case 2: return new Varargs.PairVarargs(v[0],v[1]);
+ case 2: return new Varargs.PairVarargs(v[0],v[1]);
default: return new Varargs.ArrayVarargs(v,NONE);
}
}
@@ -3415,16 +3413,16 @@ public static Varargs varargsOf(final LuaValue[] v) {
* @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)
+ * @see LuaValue#varargsOf(LuaValue[], int, int, Varargs)
*/
- public static Varargs varargsOf(final LuaValue[] v,Varargs r) {
+ public static Varargs varargsOf(final LuaValue[] v,Varargs r) {
switch ( v.length ) {
case 0: return r;
- case 1: return r.narg()>0?
- (Varargs) new Varargs.PairVarargs(v[0],r):
+ case 1: return r.narg()>0?
+ (Varargs) new Varargs.PairVarargs(v[0],r):
(Varargs) v[0];
- case 2: return r.narg()>0?
- (Varargs) new Varargs.ArrayVarargs(v,r):
+ case 2: return r.narg()>0?
+ (Varargs) new Varargs.ArrayVarargs(v,r):
(Varargs) new Varargs.PairVarargs(v[0],v[1]);
default: return new Varargs.ArrayVarargs(v,r);
}
@@ -3451,24 +3449,24 @@ public static Varargs varargsOf(final LuaValue[] v, final int offset, final int
/** Construct a {@link Varargs} around an array of {@link LuaValue}s.
*
* Caller must ensure that array contents are not mutated after this call
- * or undefined behavior will result.
+ * or undefined behavior will result.
*
* @param v The array of {@link LuaValue}s
* @param offset number of initial values to skip in the array
* @param length number of values to include from the array
* @param more {@link Varargs} contain values to include at the end
- * @return {@link Varargs} wrapping the supplied values.
+ * @return {@link Varargs} wrapping the supplied values.
* @see LuaValue#varargsOf(LuaValue[], Varargs)
* @see LuaValue#varargsOf(LuaValue[], int, int)
*/
public static Varargs varargsOf(final LuaValue[] v, final int offset, final int length, Varargs more) {
switch ( length ) {
case 0: return more;
- case 1: return more.narg()>0?
- (Varargs) new Varargs.PairVarargs(v[offset],more):
+ case 1: return more.narg()>0?
+ (Varargs) new Varargs.PairVarargs(v[offset],more):
(Varargs) v[offset];
- case 2: return more.narg()>0?
- (Varargs) new Varargs.ArrayPartVarargs(v,offset,length,more):
+ case 2: return more.narg()>0?
+ (Varargs) new Varargs.ArrayPartVarargs(v,offset,length,more):
(Varargs) new Varargs.PairVarargs(v[offset],v[offset+1]);
default: return new Varargs.ArrayPartVarargs(v,offset,length,more);
}
@@ -3477,12 +3475,12 @@ public static Varargs varargsOf(final LuaValue[] v, final int offset, final int
/** Construct a {@link Varargs} around a set of 2 or more {@link LuaValue}s.
*
* 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.
+ * followed by another variable list of remaining values.
*
* @param v First {@link LuaValue} in the {@link Varargs}
- * @param r {@link LuaValue} supplying the 2rd value,
+ * @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.
+ * @return {@link Varargs} wrapping the supplied values.
*/
public static Varargs varargsOf(LuaValue v, Varargs r) {
switch ( r.narg() ) {
@@ -3494,18 +3492,18 @@ public static Varargs varargsOf(LuaValue v, Varargs r) {
/** Construct a {@link Varargs} around a set of 3 or more {@link LuaValue}s.
*
* This can be used to wrap exactly 3 values, or a list consisting of 2 initial values
- * followed by another variable list of remaining values.
+ * followed by another variable list of remaining values.
*
* @param v1 First {@link LuaValue} in the {@link Varargs}
* @param v2 Second {@link LuaValue} in the {@link Varargs}
- * @param v3 {@link LuaValue} supplying the 3rd value,
+ * @param v3 {@link LuaValue} supplying the 3rd value,
* or {@link Varargs}s supplying all values beyond the second
- * @return {@link Varargs} wrapping the supplied values.
+ * @return {@link Varargs} wrapping the supplied values.
*/
- public static Varargs varargsOf(LuaValue v1,LuaValue v2,Varargs v3) {
+ public static Varargs varargsOf(LuaValue v1,LuaValue v2,Varargs v3) {
switch ( v3.narg() ) {
case 0: return new Varargs.PairVarargs(v1,v2);
- default: return new Varargs.ArrayPartVarargs(new LuaValue[]{v1,v2}, 0, 2, v3);
+ default: return new Varargs.ArrayPartVarargs(new LuaValue[]{v1,v2}, 0, 2, v3);
}
}
@@ -3513,9 +3511,9 @@ public static Varargs varargsOf(LuaValue v1,LuaValue v2,Varargs v3) {
*
* The tail call is not yet called or processing until the client invokes
* {@link TailcallVarargs#eval()} which performs the tail call processing.
- *
- * This method is typically not used directly by client code.
- * Instead use one of the function invocation methods.
+ *
+ * This method is typically not used directly by client code.
+ * Instead use one of the function invocation methods.
*
* @param func {@link LuaValue} to be called as a tail call
* @param args {@link Varargs} containing the arguments to the call
@@ -3525,14 +3523,14 @@ public static Varargs varargsOf(LuaValue v1,LuaValue v2,Varargs v3) {
* @see LuaValue#method(LuaValue)
* @see LuaValue#invokemethod(LuaValue)
*/
- public static Varargs tailcallOf(LuaValue func, Varargs args) {
+ public static Varargs tailcallOf(LuaValue func, Varargs args) {
return new TailcallVarargs(func, args);
}
/**
* Callback used during tail call processing to invoke the function once.
*
- * This may return a {@link TailcallVarargs} to be evaluated by the client.
+ * This may return a {@link TailcallVarargs} to be evaluated by the client.
*
* This should not be called directly, instead use one of the call invocation functions.
*
@@ -3547,18 +3545,18 @@ public Varargs onInvoke(Varargs args) {
return invoke(args);
}
- /** Hook for implementations such as LuaJC to load the environment of the main chunk
- * into the first upvalue location. If the function has no upvalues or is not a main chunk,
+ /** Hook for implementations such as LuaJC to load the environment of the main chunk
+ * into the first upvalue location. If the function has no upvalues or is not a main chunk,
* calling this will be no effect.
* @param env The environment to load into the first upvalue, if there is one.
*/
public void initupvalue1(LuaValue env) {}
- /** Varargs implemenation with no values.
+ /** Varargs implemenation with no values.
*
* This is an internal class not intended to be used directly.
- * Instead use the predefined constant {@link LuaValue#NONE}
- *
+ * Instead use the predefined constant {@link LuaValue#NONE}
+ *
* @see LuaValue#NONE
*/
private static final class None extends LuaNil {
diff --git a/app/src/main/java/org/luaj/vm2/Print.java b/app/src/main/java/org/luaj/vm2/Print.java
index 5c8b55dd..8b0bd572 100644
--- a/app/src/main/java/org/luaj/vm2/Print.java
+++ b/app/src/main/java/org/luaj/vm2/Print.java
@@ -128,6 +128,10 @@ static void printString(PrintStream ps, final LuaString s) {
}
static void printValue( PrintStream ps, LuaValue v ) {
+ if (v == null) {
+ ps.print("null");
+ return;
+ }
switch ( v.type() ) {
case LuaValue.TSTRING: printString( ps, (LuaString) v ); break;
default: ps.print( v.tojstring() );
@@ -136,7 +140,7 @@ static void printValue( PrintStream ps, LuaValue v ) {
}
static void printConstant(PrintStream ps, Prototype f, int i) {
- printValue( ps, f.k[i] );
+ printValue( ps, i < f.k.length ? f.k[i] : LuaValue.valueOf("UNKNOWN_CONST_" + i) );
}
static void printUpvalue(PrintStream ps, Upvaldesc u) {
@@ -152,7 +156,7 @@ public static void printCode(Prototype f) {
int[] code = f.code;
int pc, n = code.length;
for (pc = 0; pc < n; pc++) {
- printOpCode(f, pc);
+ pc = printOpCode(f, pc);
ps.println();
}
}
@@ -161,9 +165,10 @@ public static void printCode(Prototype f) {
* Print an opcode in a prototype
* @param f the {@link Prototype}
* @param pc the program counter to look up and print
+ * @return pc same as above or changed
*/
- public static void printOpCode(Prototype f, int pc) {
- printOpCode(ps,f,pc);
+ public static int printOpCode(Prototype f, int pc) {
+ return printOpCode(ps,f,pc);
}
/**
@@ -171,8 +176,9 @@ public static void printOpCode(Prototype f, int pc) {
* @param ps the {@link PrintStream} to print to
* @param f the {@link Prototype}
* @param pc the program counter to look up and print
+ * @return pc same as above or changed
*/
- public static void printOpCode(PrintStream ps, Prototype f, int pc) {
+ public static int printOpCode(PrintStream ps, Prototype f, int pc) {
int[] code = f.code;
int i = code[pc];
int o = GET_OPCODE(i);
@@ -187,80 +193,67 @@ public static void printOpCode(PrintStream ps, Prototype f, int pc) {
ps.print("[" + line + "] ");
else
ps.print("[-] ");
- ps.print(OPNAMES[o] + " ");
- switch (getOpMode(o)) {
- case iABC:
- ps.print( a );
- if (getBMode(o) != OpArgN)
- ps.print(" "+(ISK(b) ? (-1 - INDEXK(b)) : b));
- if (getCMode(o) != OpArgN)
- ps.print(" "+(ISK(c) ? (-1 - INDEXK(c)) : c));
- break;
- case iABx:
- if (getBMode(o) == OpArgK) {
- ps.print(a + " " + (-1 - bx));
- } else {
- ps.print(a + " " + (bx));
+ if (o >= OPNAMES.length - 1) {
+ ps.print("UNKNOWN_OP_" + o + " ");
+ } else {
+ ps.print(OPNAMES[o] + " ");
+ switch (getOpMode(o)) {
+ case iABC:
+ ps.print( a );
+ if (getBMode(o) != OpArgN)
+ ps.print(" "+(ISK(b) ? (-1 - INDEXK(b)) : b));
+ if (getCMode(o) != OpArgN)
+ ps.print(" "+(ISK(c) ? (-1 - INDEXK(c)) : c));
+ break;
+ case iABx:
+ if (getBMode(o) == OpArgK) {
+ ps.print(a + " " + (-1 - bx));
+ } else {
+ ps.print(a + " " + (bx));
+ }
+ break;
+ case iAsBx:
+ if (o == OP_JMP)
+ ps.print( sbx );
+ else
+ ps.print(a + " " + sbx);
+ break;
}
- break;
- case iAsBx:
- if (o == OP_JMP)
- ps.print( sbx );
- else
- ps.print(a + " " + sbx);
- break;
- }
- switch (o) {
- case OP_LOADK:
- ps.print(" ; ");
- printConstant(ps, f, bx);
- break;
- case OP_GETUPVAL:
- case OP_SETUPVAL:
- ps.print(" ; ");
- printUpvalue(ps, f.upvalues[b]);
- break;
- case OP_GETTABUP:
- ps.print(" ; ");
- printUpvalue(ps, f.upvalues[b]);
- ps.print(" ");
- if (ISK(c))
- printConstant(ps, f, INDEXK(c));
- else
- ps.print("-");
- break;
- case OP_SETTABUP:
- ps.print(" ; ");
- printUpvalue(ps, f.upvalues[a]);
- ps.print(" ");
- if (ISK(b))
- printConstant(ps, f, INDEXK(b));
- else
- ps.print("-");
- ps.print(" ");
- if (ISK(c))
- printConstant(ps, f, INDEXK(c));
- else
- ps.print("-");
- break;
- case OP_GETTABLE:
- case OP_SELF:
- if (ISK(c)) {
+ switch (o) {
+ case OP_LOADK:
ps.print(" ; ");
- printConstant(ps, f, INDEXK(c));
- }
- break;
- case OP_SETTABLE:
- case OP_ADD:
- case OP_SUB:
- case OP_MUL:
- case OP_DIV:
- case OP_POW:
- case OP_EQ:
- case OP_LT:
- case OP_LE:
- if (ISK(b) || ISK(c)) {
+ printConstant(ps, f, bx);
+ break;
+ case OP_GETUPVAL:
+ case OP_SETUPVAL:
ps.print(" ; ");
+ if (b < f.upvalues.length) {
+ printUpvalue(ps, f.upvalues[b]);
+ } else {
+ ps.print("UNKNOWN_UPVALUE_" + b);
+ }
+ break;
+ case OP_GETTABUP:
+ ps.print(" ; ");
+ if (b < f.upvalues.length) {
+ printUpvalue(ps, f.upvalues[b]);
+ } else {
+ ps.print("UNKNOWN_UPVALUE_" + b);
+ }
+ ps.print(" ");
+ if (ISK(c))
+ printConstant(ps, f, INDEXK(c));
+ else
+ ps.print("-");
+ break;
+ case OP_SETTABUP:
+ ps.print(" ; ");
+ if (a < f.upvalues.length) {
+ printUpvalue(ps, f.upvalues[a]);
+ } else {
+ ps.print("UNKNOWN_UPVALUE_" + a);
+ }
+ ps.print(" ");
if (ISK(b))
printConstant(ps, f, INDEXK(b));
else
@@ -270,28 +263,62 @@ public static void printOpCode(PrintStream ps, Prototype f, int pc) {
printConstant(ps, f, INDEXK(c));
else
ps.print("-");
+ break;
+ case OP_GETTABLE:
+ case OP_SELF:
+ if (ISK(c)) {
+ ps.print(" ; ");
+ printConstant(ps, f, INDEXK(c));
+ }
+ break;
+ case OP_SETTABLE:
+ case OP_ADD:
+ case OP_SUB:
+ case OP_MUL:
+ case OP_DIV:
+ case OP_POW:
+ case OP_EQ:
+ case OP_LT:
+ case OP_LE:
+ if (ISK(b) || ISK(c)) {
+ ps.print(" ; ");
+ if (ISK(b))
+ printConstant(ps, f, INDEXK(b));
+ else
+ ps.print("-");
+ ps.print(" ");
+ if (ISK(c))
+ printConstant(ps, f, INDEXK(c));
+ else
+ ps.print("-");
+ }
+ break;
+ case OP_JMP:
+ case OP_FORLOOP:
+ case OP_FORPREP:
+ ps.print(" ; to " + (sbx + pc + 2));
+ break;
+ case OP_CLOSURE:
+ if (bx < f.p.length) {
+ ps.print(" ; " + f.p[bx].getClass().getName());
+ } else {
+ ps.print(" ; UNKNOWN_PROTYPE_" + bx);
+ }
+ break;
+ case OP_SETLIST:
+ if (c == 0)
+ ps.print(" ; " + ((int) code[++pc]) + " (stored in the next OP)");
+ else
+ ps.print(" ; " + ((int) c));
+ break;
+ case OP_VARARG:
+ ps.print( " ; is_vararg="+ f.is_vararg );
+ break;
+ default:
+ break;
}
- break;
- case OP_JMP:
- case OP_FORLOOP:
- case OP_FORPREP:
- ps.print(" ; to " + (sbx + pc + 2));
- break;
- case OP_CLOSURE:
- ps.print(" ; " + f.p[bx].getClass().getName());
- break;
- case OP_SETLIST:
- if (c == 0)
- ps.print(" ; " + ((int) code[++pc]));
- else
- ps.print(" ; " + ((int) c));
- break;
- case OP_VARARG:
- ps.print( " ; is_vararg="+ f.is_vararg );
- break;
- default:
- break;
}
+ return pc;
}
private static int getline(Prototype f, int pc) {
diff --git a/app/src/main/java/org/luaj/vm2/compiler/Constants.java b/app/src/main/java/org/luaj/vm2/compiler/Constants.java
index 50f2c2eb..fc505b49 100644
--- a/app/src/main/java/org/luaj/vm2/compiler/Constants.java
+++ b/app/src/main/java/org/luaj/vm2/compiler/Constants.java
@@ -46,20 +46,20 @@ public class Constants extends Lua {
/* OpMode - basic instruction format */
- static final int
+ static final int
iABC = 0,
iABx = 1,
iAsBx = 2;
/* OpArgMask */
- static final int
+ static final int
OpArgN = 0, /* argument is not used */
OpArgU = 1, /* argument is used */
OpArgR = 2, /* argument is a register or a jump offset */
OpArgK = 3; /* argument is a constant or register/constant */
- protected static void _assert(boolean b) {
+ protected static void _assert(boolean b) {
if (!b)
throw new LuaError("compiler assert failed");
}
@@ -104,6 +104,11 @@ static int CREATE_ABx(int o, int a, int bc) {
((a << POS_A) & MASK_A) |
((bc << POS_Bx) & MASK_Bx) ;
}
+
+ static int CREATE_Ax(int o, int a) {
+ return ((o << POS_OP) & MASK_OP) |
+ ((a << POS_Ax) & MASK_Ax) ;
+ }
// vector reallocation
@@ -150,7 +155,7 @@ static LexState.Vardesc[] realloc(LexState.Vardesc[] v, int n) {
}
static LexState.Labeldesc[] grow(LexState.Labeldesc[] v, int min_n) {
- return v == null ? new LexState.Labeldesc[2] : v.length < min_n ? realloc(v, v.length*2) : v;
+ return v == null ? new LexState.Labeldesc[2] : v.length < min_n ? realloc(v, v.length*2) : v;
}
static LexState.Labeldesc[] realloc(LexState.Labeldesc[] v, int n) {
diff --git a/app/src/main/java/org/luaj/vm2/compiler/FuncState.java b/app/src/main/java/org/luaj/vm2/compiler/FuncState.java
index 2717f369..70e0f885 100644
--- a/app/src/main/java/org/luaj/vm2/compiler/FuncState.java
+++ b/app/src/main/java/org/luaj/vm2/compiler/FuncState.java
@@ -50,7 +50,6 @@ static class BlockCnt {
Hashtable h; /* table to find (and reuse) elements in `k' */
FuncState prev; /* enclosing function */
LexState ls; /* lexical state */
- LuaC.CompileState L; /* compiler being invoked */
BlockCnt bl; /* chain of current blocks */
int pc; /* next position to code (equivalent to `ncode') */
int lasttarget; /* `pc' of last `jump target' */
@@ -113,8 +112,8 @@ void checklimit(int v, int l, String msg) {
void errorlimit (int limit, String what) {
// TODO: report message logic.
String msg = (f.linedefined == 0) ?
- L.pushfstring("main function has more than "+limit+" "+what) :
- L.pushfstring("function at line "+f.linedefined+" has more than "+limit+" "+what);
+ ls.L.pushfstring("main function has more than "+limit+" "+what) :
+ ls.L.pushfstring("function at line "+f.linedefined+" has more than "+limit+" "+what);
ls.lexerror(msg, 0);
}
@@ -296,7 +295,7 @@ void nil(int from, int n) {
}
} /* else go through */
}
- this.codeABC(OP_LOADNIL, from, n - 1, 0);
+ this.codeABC(OP_LOADNIL, from, n - 1, 0);
}
@@ -478,7 +477,7 @@ int addk(LuaValue v) {
this.h = new Hashtable();
} else if (this.h.containsKey(v)) {
return ((Integer) h.get(v)).intValue();
- }
+ }
final int idx = this.nk;
this.h.put(v, new Integer(idx));
final Prototype f = this.f;
@@ -496,7 +495,7 @@ int numberK(LuaValue r) {
if ( r instanceof LuaDouble ) {
double d = r.todouble();
int i = (int) d;
- if ( d == (double) i )
+ if ( d == (double) i )
r = LuaInteger.valueOf(i);
}
return this.addk(r);
@@ -581,11 +580,11 @@ void discharge2reg(expdesc e, int reg) {
break;
}
case LexState.VK: {
- this.codeABx(OP_LOADK, reg, e.u.info);
+ this.codeK(reg, e.u.info);
break;
}
case LexState.VKNUM: {
- this.codeABx(OP_LOADK, reg, this.numberK(e.u.nval()));
+ this.codeK(reg, this.numberK(e.u.nval()));
break;
}
case LexState.VRELOCABLE: {
@@ -688,7 +687,7 @@ int exp2RK(expdesc e) {
case LexState.VKNUM: {
e.u.info = this.numberK(e.u.nval());
e.k = LexState.VK;
- /* go through */
+ /* go through */
}
case LexState.VK: {
if (e.u.info <= MAXINDEXRK) /* constant fit in argC? */
@@ -1117,6 +1116,20 @@ int codeABx(int o, int a, int bc) {
return this.code(CREATE_ABx(o, a, bc), this.ls.lastline);
}
+ int codeextraarg(int a) {
+ _assert(a <= MAXARG_Ax);
+ return this.code(CREATE_Ax(OP_EXTRAARG, a), this.ls.lastline);
+ }
+
+ int codeK(int reg, int k) {
+ if (k <= MAXARG_Bx)
+ return codeABx(OP_LOADK, reg, k);
+ else {
+ int p = codeABx(OP_LOADKX, reg, 0);
+ codeextraarg(k);
+ return p;
+ }
+ }
void setlist(int base, int nelems, int tostore) {
int c = (nelems - 1) / LFIELDS_PER_FLUSH + 1;
diff --git a/app/src/main/java/org/luaj/vm2/compiler/LexState.java b/app/src/main/java/org/luaj/vm2/compiler/LexState.java
index c85cf68e..58864110 100644
--- a/app/src/main/java/org/luaj/vm2/compiler/LexState.java
+++ b/app/src/main/java/org/luaj/vm2/compiler/LexState.java
@@ -62,14 +62,14 @@ public class LexState extends Constants {
private static final int EOZ = (-1);
private static final int MAX_INT = Integer.MAX_VALUE-2;
- private static final int UCHAR_MAX = 255; // TODO, convert to unicode CHAR_MAX?
+ private static final int UCHAR_MAX = 255; // TODO, convert to unicode CHAR_MAX?
private static final int LUAI_MAXCCALLS = 200;
private static final String LUA_QS(String s) { return "'"+s+"'"; }
private static final String LUA_QL(Object o) { return LUA_QS(String.valueOf(o)); }
private static final int LUA_COMPAT_LSTR = 1; // 1 for compatibility, 2 for old behavior
- private static final boolean LUA_COMPAT_VARARG = true;
+ private static final boolean LUA_COMPAT_VARARG = true;
public static boolean isReservedKeyword(String varName) {
return RESERVED_LOCAL_VAR_KEYWORDS_TABLE.containsKey(varName);
@@ -84,7 +84,7 @@ public static boolean isReservedKeyword(String varName) {
/*
** grep "ORDER OPR" if you change these enums
*/
- static final int
+ static final int
OPR_ADD=0, OPR_SUB=1, OPR_MUL=2, OPR_DIV=3, OPR_MOD=4, OPR_POW=5,
OPR_CONCAT=6,
OPR_NE=7, OPR_EQ=8,
@@ -92,11 +92,11 @@ public static boolean isReservedKeyword(String varName) {
OPR_AND=13, OPR_OR=14,
OPR_NOBINOPR=15;
- static final int
+ static final int
OPR_MINUS=0, OPR_NOT=1, OPR_LEN=2, OPR_NOUNOPR=3;
/* exp kind */
- static final int
+ static final int
VVOID = 0, /* no value */
VNIL = 1,
VTRUE = 2,
@@ -153,14 +153,14 @@ public void set(Token other) {
"::", "
- * This contains all library functions listed as "basic functions" in the lua documentation for JME.
- * The functions dofile and loadfile use the
+ * This contains all library functions listed as "basic functions" in the lua documentation for JME.
+ * The functions dofile and loadfile use the
* {@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.
+ * 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.
- *
- * To use basic library functions that include a {@link ResourceFinder} based on
- * directory lookup, use {@link org.luaj.vm2.lib.jse.JseBaseLib} instead.
*
- * Typically, this library is included as part of a call to either
+ * To use basic library functions that include a {@link ResourceFinder} based on
+ * directory lookup, use {@link org.luaj.vm2.lib.jse.JseBaseLib} instead.
+ *
+ * Typically, this library is included as part of a call to either
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or
* {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()}
*
- * For special cases where the smallest possible footprint is desired,
+ * For special cases where the smallest possible footprint is desired,
* a minimal set of libraries could be loaded
* directly via {@link Globals#load(LuaValue)} using code such as:
*
* This is a direct port of the corresponding library in C.
* @see org.luaj.vm2.lib.jse.JseBaseLib
@@ -119,9 +119,9 @@ public LuaValue call(LuaValue modname, LuaValue env) {
return env;
}
- /** ResourceFinder implementation
+ /** ResourceFinder implementation
*
- * Tries to open the file as a resource, which can work for JSE and JME.
+ * Tries to open the file as a resource, which can work for JSE and JME.
*/
public InputStream findResource(String filename) {
return getClass().getResourceAsStream(filename.startsWith("/")? filename: "/"+filename);
@@ -131,7 +131,7 @@ public InputStream findResource(String filename) {
// "assert", // ( v [,message] ) -> v, message | ERR
static final class _assert extends VarArgFunction {
public Varargs invoke(Varargs args) {
- if ( !args.arg1().toboolean() )
+ if ( !args.arg1().toboolean() )
error( args.narg()>1? args.optjstring(2,"assertion failed!"): "assertion failed!" );
return args;
}
@@ -163,23 +163,23 @@ final class dofile extends VarArgFunction {
public Varargs invoke(Varargs args) {
args.argcheck(args.isstring(1) || args.isnil(1), 1, "filename must be string or nil");
String filename = args.isstring(1)? args.tojstring(1): null;
- Varargs v = filename == null?
+ Varargs v = filename == null?
loadStream( globals.STDIN, "=stdin", "bt", globals ):
loadFile( args.checkjstring(1), "bt", globals );
- return v.isnil(1)? error(v.tojstring(2)): v.arg1().invoke();
+ return v.isnil(1)? error(v.tojstring(2)): v.arg1().invoke();
}
}
// "error", // ( message [,level] ) -> ERR
static final class error extends TwoArgFunction {
public LuaValue call(LuaValue arg1, LuaValue arg2) {
- throw arg1.isnil()? new LuaError(null, arg2.optint(1)):
- arg1.isstring()? new LuaError(arg1.tojstring(), arg2.optint(1)):
+ throw arg1.isnil()? new LuaError(null, arg2.optint(1)):
+ arg1.isstring()? new LuaError(arg1.tojstring(), arg2.optint(1)):
new LuaError(arg1);
}
}
- // "getmetatable", // ( object ) -> table
+ // "getmetatable", // ( object ) -> table
static final class getmetatable extends LibFunction {
public LuaValue call() {
return argerror(1, "value");
@@ -197,7 +197,7 @@ public Varargs invoke(Varargs args) {
String source = args.optjstring(2, ld.isstring()? ld.tojstring(): "=(load)");
String mode = args.optjstring(3, "bt");
LuaValue env = args.optvalue(4, globals);
- return loadStream(ld.isstring()? ld.strvalue().toInputStream():
+ return loadStream(ld.isstring()? ld.strvalue().toInputStream():
new StringInputStream(ld.checkfunction()), source, mode, env);
}
}
@@ -209,7 +209,7 @@ public Varargs invoke(Varargs args) {
String filename = args.isstring(1)? args.tojstring(1): null;
String mode = args.optjstring(2, "bt");
LuaValue env = args.optvalue(3, globals);
- return filename == null?
+ return filename == null?
loadStream( globals.STDIN, "=stdin", mode, env ):
loadFile( filename, mode, env );
}
@@ -243,13 +243,13 @@ final class print extends VarArgFunction {
this.baselib = baselib;
}
public Varargs invoke(Varargs args) {
- LuaValue tostring = globals.get("tostring");
+ LuaValue tostring = globals.get("tostring");
for ( int i=1, n=args.narg(); i<=n; i++ ) {
if ( i>1 ) globals.STDOUT.print( '\t' );
LuaString s = tostring.call( args.arg(i) ).strvalue();
globals.STDOUT.print(s.tojstring());
}
- globals.STDOUT.println();
+ globals.STDOUT.print('\n');
return NONE;
}
}
@@ -299,7 +299,8 @@ public LuaValue call(LuaValue table, LuaValue index) {
}
public LuaValue call(LuaValue table, LuaValue index, LuaValue value) {
LuaTable t = table.checktable();
- t.rawset(index.checknotnil(), value);
+ if (!index.isvalidkey()) argerror(2, "value");
+ t.rawset(index, value);
return t;
}
}
@@ -307,7 +308,7 @@ public LuaValue call(LuaValue table, LuaValue index, LuaValue value) {
// "select", // (f, ...) -> value1, ...
static final class select extends VarArgFunction {
public Varargs invoke(Varargs args) {
- int n = args.narg()-1;
+ int n = args.narg()-1;
if ( args.arg1().equals(valueOf("#")) )
return valueOf(n);
int i = args.checkint(1);
@@ -349,10 +350,10 @@ public LuaValue call(LuaValue e, LuaValue base) {
static final class tostring extends LibFunction {
public LuaValue call(LuaValue arg) {
LuaValue h = arg.metatag(TOSTRING);
- if ( ! h.isnil() )
+ if ( ! h.isnil() )
return h.call(arg);
LuaValue v = arg.tostring();
- if ( ! v.isnil() )
+ if ( ! v.isnil() )
return v;
return valueOf(arg.tojstring());
}
@@ -365,7 +366,7 @@ public LuaValue call(LuaValue arg) {
}
}
- // "xpcall", // (f, err) -> result1, ...
+ // "xpcall", // (f, err) -> result1, ...
final class xpcall extends VarArgFunction {
public Varargs invoke(Varargs args) {
final LuaThread t = globals.running;
@@ -425,10 +426,10 @@ public Varargs invoke(Varargs args) {
}
}
- /**
+ /**
* Load from a named file, returning the chunk or nil,error of can't load
- * @param env
- * @param mode
+ * @param env
+ * @param mode
* @return Varargs containing chunk, or NIL,error-text on error
*/
public Varargs loadFile(String filename, String mode, LuaValue env) {
@@ -459,7 +460,7 @@ public Varargs loadStream(InputStream is, String chunkname, String mode, LuaValu
private static class StringInputStream extends InputStream {
final LuaValue func;
- byte[] bytes;
+ byte[] bytes;
int offset, remaining = 0;
StringInputStream(LuaValue func) {
this.func = func;
@@ -477,7 +478,7 @@ public int read() throws IOException {
return -1;
}
--remaining;
- return bytes[offset++];
+ return 0xFF&bytes[offset++];
}
}
}
diff --git a/app/src/main/java/org/luaj/vm2/lib/Bit32Lib.java b/app/src/main/java/org/luaj/vm2/lib/Bit32Lib.java
index 55db4f13..699c6945 100644
--- a/app/src/main/java/org/luaj/vm2/lib/Bit32Lib.java
+++ b/app/src/main/java/org/luaj/vm2/lib/Bit32Lib.java
@@ -27,15 +27,15 @@
/**
* Subclass of LibFunction that implements the Lua standard {@code bit32} library.
- *
- * Typically, this library is included as part of a call to either
+ *
+ * Typically, this library is included as part of a call to either
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()}
*
- * To instantiate and use it directly,
+ * To instantiate and use it directly,
* link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
*
+/**
+ * Subclass of {@link LibFunction} which implements the lua standard {@code coroutine}
+ * library.
+ *
* The coroutine library in luaj has the same behavior as the
- * coroutine library in C, but is implemented using Java Threads to maintain
- * the call state between invocations. Therefore it can be yielded from anywhere,
+ * coroutine library in C, but is implemented using Java Threads to maintain
+ * the call state between invocations. Therefore it can be yielded from anywhere,
* similar to the "Coco" yield-from-anywhere patch available for C-based lua.
* However, coroutines that are yielded but never resumed to complete their execution
- * may not be collected by the garbage collector.
- *
- * Typically, this library is included as part of a call to either
+ * may not be collected by the garbage collector.
+ *
+ * Typically, this library is included as part of a call to either
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()}
*
- * To instantiate and use it directly,
+ * To instantiate and use it directly,
* link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
*
+/**
+ * Subclass of {@link LibFunction} which implements the lua standard {@code debug}
+ * library.
+ *
* The debug library in luaj tries to emulate the behavior of the corresponding C-based lua library.
- * To do this, it must maintain a separate stack of calls to {@link LuaClosure} and {@link LibFunction}
- * instances.
+ * 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 org.luaj.vm2.Globals.Compiler} such as {@link org.luaj.vm2.luajc.LuaJC},
- * this cannot be done in all cases.
- *
- * Typically, this library is included as part of a call to either
- * {@link org.luaj.vm2.lib.jse.JsePlatform#debugGlobals()} or
+ * via a {@link org.luaj.vm2.Globals.Compiler} such as {@link org.luaj.vm2.luajc.LuaJC},
+ * this cannot be done in all cases.
+ *
+ * Typically, this library is included as part of a call to either
+ * {@link org.luaj.vm2.lib.jse.JsePlatform#debugGlobals()} or
* {@link org.luaj.vm2.lib.jme.JmePlatform#debugGlobals()}
*
- * To instantiate and use it directly,
+ * To instantiate and use it directly,
* link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
*
+/**
+ * Abstract base class extending {@link LibFunction} which implements the
+ * core of the lua standard {@code 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:
- * {@link org.luaj.vm2.lib.jse.JseIoLib} for the JSE platform, and
+ * the JSE and JME platforms.
+ * In practice on of the concrete IOLib subclasses is chosen:
+ * {@link org.luaj.vm2.lib.jse.JseIoLib} for the JSE platform, and
* {@link 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
+ * 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
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()}
*
- * To instantiate and use it directly,
+ * To instantiate and use it directly,
* link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
*
- * It contains only the math library support that is possible on JME.
- * For a more complete implementation based on math functions specific to JSE
- * use {@link org.luaj.vm2.lib.jse.JseMathLib}.
+/**
+ * Subclass of {@link LibFunction} which implements the lua standard {@code math}
+ * library.
+ *
+ * It contains only the math library support that is possible on JME.
+ * For a more complete implementation based on math functions specific to JSE
+ * use {@link org.luaj.vm2.lib.jse.JseMathLib}.
* In Particular the following math functions are not implemented by this library:
*
- * The implementations of {@code exp()} and {@code pow()} are constructed by
+ * The implementations of {@code exp()} and {@code pow()} are constructed by
* hand for JME, so will be slower and less accurate than when executed on the JSE platform.
- *
- * Typically, this library is included as part of a call to either
- * {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or
+ *
+ * Typically, this library is included as part of a call to either
+ * {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or
* {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()}
*
- * To instantiate and use it directly,
+ * To instantiate and use it directly,
* link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
*
* This has been implemented to match as closely as possible the behavior in the corresponding library in C.
* @see LibFunction
@@ -87,8 +87,8 @@ public class MathLib extends TwoArgFunction {
*/
public static MathLib MATHLIB = null;
- /** Construct a MathLib, which can be initialized by calling it with a
- * modname string, and a global environment table as arguments using
+ /** Construct a MathLib, which can be initialized by calling it with a
+ * modname string, and a global environment table as arguments using
* {@link #call(LuaValue, LuaValue)}. */
public MathLib() {
MATHLIB = this;
@@ -125,7 +125,7 @@ public LuaValue call(LuaValue modname, LuaValue env) {
math.set("sqrt", new sqrt());
math.set("tan", new tan());
env.set("math", math);
- env.get("package").get("loaded").set("math", math);
+ if (!env.get("package").isnil()) env.get("package").get("loaded").set("math", math);
return math;
}
@@ -158,15 +158,17 @@ static final class exp extends UnaryOp {
exp(MathLib mathlib) {
this.mathlib = mathlib;
}
- protected double call(double d) {
- return mathlib.dpow_lib(Math.E,d);
- }
+ protected double call(double d) {
+ return mathlib.dpow_lib(Math.E,d);
+ }
}
- static final class fmod extends BinaryOp {
- protected double call(double x, double y) {
- double q = x/y;
- return x - y * (q>=0? Math.floor(q): Math.ceil(q));
+ static final class fmod extends TwoArgFunction {
+ public LuaValue call(LuaValue xv, LuaValue yv) {
+ if (xv.islong() && yv.islong()) {
+ return valueOf(xv.tolong() % yv.tolong());
+ }
+ return valueOf(xv.checkdouble() % yv.checkdouble());
}
}
static final class ldexp extends BinaryOp {
@@ -194,27 +196,36 @@ public Varargs invoke(Varargs args) {
static class max extends VarArgFunction {
public Varargs invoke(Varargs args) {
- double m = args.checkdouble(1);
- for ( int i=2,n=args.narg(); i<=n; ++i )
- m = Math.max(m,args.checkdouble(i));
- return valueOf(m);
+ LuaValue m = args.checkvalue(1);
+ for ( int i=2,n=args.narg(); i<=n; ++i ) {
+ LuaValue v = args.checkvalue(i);
+ if (m.lt_b(v)) m = v;
+ }
+ return m;
}
}
static class min extends VarArgFunction {
public Varargs invoke(Varargs args) {
- double m = args.checkdouble(1);
- for ( int i=2,n=args.narg(); i<=n; ++i )
- m = Math.min(m,args.checkdouble(i));
- return valueOf(m);
+ LuaValue m = args.checkvalue(1);
+ for ( int i=2,n=args.narg(); i<=n; ++i ) {
+ LuaValue v = args.checkvalue(i);
+ if (v.lt_b(m)) m = v;
+ }
+ return m;
}
}
static class modf extends VarArgFunction {
public Varargs invoke(Varargs args) {
- double x = args.checkdouble(1);
+ LuaValue n = args.arg1();
+ /* number is its own integer part, no fractional part */
+ if (n.islong()) return varargsOf(n, valueOf(0.0));
+ double x = n.checkdouble();
+ /* integer part (rounds toward zero) */
double intPart = ( x > 0 ) ? Math.floor( x ) : Math.ceil( x );
- double fracPart = x - intPart;
+ /* fractional part (test needed for inf/-inf) */
+ double fracPart = x == intPart ? 0.0 : x - intPart;
return varargsOf( valueOf(intPart), valueOf(fracPart) );
}
}
@@ -252,26 +263,26 @@ public LuaValue call(LuaValue arg) {
/** compute power using installed math library, or default if there is no math library installed */
public static LuaValue dpow(double a, double b) {
- return LuaDouble.valueOf(
+ return LuaDouble.valueOf(
MATHLIB!=null?
MATHLIB.dpow_lib(a,b):
dpow_default(a,b) );
}
public static double dpow_d(double a, double b) {
- return MATHLIB!=null?
- MATHLIB.dpow_lib(a,b):
+ return MATHLIB!=null?
+ MATHLIB.dpow_lib(a,b):
dpow_default(a,b);
}
- /**
- * Hook to override default dpow behavior with faster implementation.
+ /**
+ * Hook to override default dpow behavior with faster implementation.
*/
public double dpow_lib(double a, double b) {
return dpow_default(a,b);
}
- /**
- * Default JME version computes using longhand heuristics.
+ /**
+ * Default JME version computes using longhand heuristics.
*/
protected static double dpow_default(double a, double b) {
if ( b < 0 )
diff --git a/app/src/main/java/org/luaj/vm2/lib/OsLib.java b/app/src/main/java/org/luaj/vm2/lib/OsLib.java
index b89ec6e9..85b8677e 100644
--- a/app/src/main/java/org/luaj/vm2/lib/OsLib.java
+++ b/app/src/main/java/org/luaj/vm2/lib/OsLib.java
@@ -35,17 +35,17 @@
* Subclass of {@link LibFunction} which implements the standard lua {@code os} library.
*
* It is a usable base with simplified stub functions
- * for library functions that cannot be implemented uniformly
- * on Jse and Jme.
+ * for library functions that cannot be implemented uniformly
+ * on Jse and Jme.
*
- * This can be installed as-is on either platform, or extended
+ * This can be installed as-is on either platform, or extended
* and refined to be used in a complete Jse implementation.
*
- * Because the nature of the {@code os} library is to encapsulate
- * os-specific features, the behavior of these functions varies considerably
- * from their counterparts in the C platform.
+ * Because the nature of the {@code os} library is to encapsulate
+ * os-specific features, the behavior of these functions varies considerably
+ * from their counterparts in the C platform.
*
- * The following functions have limited implementations of features
+ * The following functions have limited implementations of features
* that are not supported well on Jme:
*
- * Typically, this library is included as part of a call to either
+ * Typically, this library is included as part of a call to either
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()}
*
- * To instantiate and use it directly,
+ * To instantiate and use it directly,
* link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
*
- * To instantiate and use it directly,
+ * To instantiate and use it directly,
* link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
*
* @see LibFunction
* @see BaseLib
@@ -81,23 +81,26 @@ public class PackageLib extends TwoArgFunction {
/** The default value to use for package.path. This can be set with the system property
*
- * To instantiate and use it directly,
+ * To instantiate and use it directly,
* link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
*
@@ -61,8 +61,8 @@
*/
public class StringLib extends TwoArgFunction {
- /** Construct a StringLib, which can be initialized by calling it with a
- * modname string, and a global environment table as arguments using
+ /** Construct a StringLib, which can be initialized by calling it with a
+ * modname string, and a global environment table as arguments using
* {@link #call(LuaValue, LuaValue)}. */
public StringLib() {
}
@@ -75,8 +75,8 @@ public StringLib() {
* If the shared strings metatable instance is null, will set the metatable as
* the global shared metatable for strings.
*
- * All tables and metatables are read-write by default so if this will be used in
- * a server environment, sandboxing should be used. In particular, the
+ * All tables and metatables are read-write by default so if this will be used in
+ * a server environment, sandboxing should be used. In particular, the
* {@link LuaString#s_metatable} table should probably be made read-only.
* @param modname the module name supplied if this is loaded via 'require'.
* @param env the environment to load into, typically a Globals instance.
@@ -97,17 +97,17 @@ public LuaValue call(LuaValue modname, LuaValue env) {
string.set("reverse", new reverse());
string.set("sub", new sub());
string.set("upper", new upper());
- LuaTable mt = LuaValue.tableOf(
- new LuaValue[] { INDEX, string });
+
env.set("string", string);
- env.get("package").get("loaded").set("string", string);
- if (LuaString.s_metatable == null)
- LuaString.s_metatable = mt;
+ if (!env.get("package").isnil()) env.get("package").get("loaded").set("string", string);
+ if (LuaString.s_metatable == null) {
+ LuaString.s_metatable = LuaValue.tableOf(new LuaValue[] { INDEX, string });
+ }
return string;
}
/**
- * string.byte (s [, i [, j]])
+ * string.byte (s [, i [, j]])
*
* Returns the internal numerical codes of the
* characters s[i], s[i+1], ..., s[j]. The default value for i is 1; the
@@ -137,12 +137,12 @@ public Varargs invoke(Varargs args) {
}
}
- /**
+ /**
* string.char (...)
*
- * Receives zero or more integers. Returns a string with length equal
- * to the number of arguments, in which each character has the internal
- * numerical code equal to its corresponding argument.
+ * Receives zero or more integers. Returns a string with length equal
+ * to the number of arguments, in which each character has the internal
+ * numerical code equal to its corresponding argument.
*
* Note that numerical codes are not necessarily portable across platforms.
*
@@ -154,28 +154,30 @@ public Varargs invoke(Varargs args) {
byte[] bytes = new byte[n];
for ( int i=0, a=1; i
- * Typically, this library is included as part of a call to either
+ * Typically, this library is included as part of a call to either
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()}
*
- * To instantiate and use it directly,
+ * To instantiate and use it directly,
* link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
*
* A simple example of initializing globals and using them from Java is:
@@ -52,7 +51,7 @@
* globals.load( new FileInputStream("main.lua"), "main.lua" ).call();
* }
- * although {@code require} could also be used:
+ * although {@code require} could also be used:
*
+ * In addition, the {@link LuaC} compiler is installed so lua files may be loaded in their source form.
+ *
* The debug globals are simply the standard globals plus the {@code debug} library {@link DebugLib}.
*
* The class ensures that initialization is done in the correct order.
@@ -98,7 +97,7 @@ public static Globals standardGlobals() {
globals.load(new PackageLib());
globals.load(new Bit32Lib());
globals.load(new TableLib());
- globals.load(new StringLib());
+ globals.load(new JseStringLib());
globals.load(new CoroutineLib());
globals.load(new JseMathLib());
globals.load(new JseIoLib());
@@ -106,7 +105,7 @@ public static Globals standardGlobals() {
globals.load(new LuajavaLib());
LoadState.install(globals);
LuaC.install(globals);
- return globals;
+ return globals;
}
/** Create standard globals including the {@link DebugLib} library.
@@ -124,9 +123,9 @@ public static Globals debugGlobals() {
}
- /** Simple wrapper for invoking a lua function with command line arguments.
+ /** Simple wrapper for invoking a lua function with command line arguments.
* The supplied function is first given a new Globals object as its environment
- * then the program is run with arguments.
+ * then the program is run with arguments.
* @return {@link Varargs} containing any values returned by mainChunk.
*/
public static Varargs luaMain(LuaValue mainChunk, String[] args) {
diff --git a/app/src/main/java/org/luaj/vm2/lib/jse/JseStringLib.java b/app/src/main/java/org/luaj/vm2/lib/jse/JseStringLib.java
new file mode 100644
index 00000000..41177787
--- /dev/null
+++ b/app/src/main/java/org/luaj/vm2/lib/jse/JseStringLib.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+* Copyright (c) 2009 Luaj.org. All rights reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy
+* of this software and associated documentation files (the "Software"), to deal
+* in the Software without restriction, including without limitation the rights
+* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+* copies of the Software, and to permit persons to whom the Software is
+* furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in
+* all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+* THE SOFTWARE.
+******************************************************************************/
+package org.luaj.vm2.lib.jse;
+
+public class JseStringLib extends org.luaj.vm2.lib.StringLib {
+
+ /** public constructor */
+ public JseStringLib() {
+ }
+
+ protected String format(String src, double x) {
+ String out;
+ try {
+ out = String.format(src, new Object[] {Double.valueOf(x)});
+ } catch (Throwable e) {
+ out = super.format(src, x);
+ }
+ return out;
+ }
+}
diff --git a/app/src/main/java/org/luaj/vm2/lib/jse/LuajavaLib.java b/app/src/main/java/org/luaj/vm2/lib/jse/LuajavaLib.java
index 4d9b634f..35f1f850 100644
--- a/app/src/main/java/org/luaj/vm2/lib/jse/LuajavaLib.java
+++ b/app/src/main/java/org/luaj/vm2/lib/jse/LuajavaLib.java
@@ -37,38 +37,38 @@
import org.luaj.vm2.lib.LibFunction;
import org.luaj.vm2.lib.VarArgFunction;
-/**
- * Subclass of {@link LibFunction} which implements the features of the luajava package.
- *
- * Luajava is an approach to mixing lua and java using simple functions that bind
- * java classes and methods to lua dynamically. The API is documented on the
+/**
+ * Subclass of {@link LibFunction} which implements the features of the luajava package.
+ *
+ * Luajava is an approach to mixing lua and java using simple functions that bind
+ * java classes and methods to lua dynamically. The API is documented on the
* luajava documentation pages.
*
*
- * Typically, this library is included as part of a call to
+ * Typically, this library is included as part of a call to
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()}
*
- * To instantiate and use it directly,
+ * To instantiate and use it directly,
* link it into your globals table via {@link Globals#load} using code such as:
*
*
- * The {@code luajava} library is available
+ * The {@code luajava} library is available
* 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
+ * 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.
*
* This has been implemented to match as closely as possible the behavior in the corresponding library in C.
@@ -91,10 +91,10 @@ public class LuajavaLib extends VarArgFunction {
static final int LOADLIB = 5;
static final String[] NAMES = {
- "bindClass",
- "newInstance",
- "new",
- "createProxy",
+ "bindClass",
+ "newInstance",
+ "new",
+ "createProxy",
"loadLib",
};
@@ -112,7 +112,7 @@ public Varargs invoke(Varargs args) {
LuaTable t = new LuaTable();
bind( t, this.getClass(), NAMES, BINDCLASS );
env.set("luajava", t);
- env.get("package").get("loaded").set("luajava", t);
+ if (!env.get("package").isnil()) env.get("package").get("loaded").set("luajava", t);
return t;
}
case BINDCLASS: {
@@ -122,13 +122,13 @@ public Varargs invoke(Varargs args) {
case NEWINSTANCE:
case NEW: {
// get constructor
- final LuaValue c = args.checkvalue(1);
+ final LuaValue c = args.checkvalue(1);
final Class clazz = (opcode==NEWINSTANCE? classForName(c.tojstring()): (Class) c.checkuserdata(Class.class));
final Varargs consargs = args.subargs(2);
return JavaClass.forClass(clazz).getConstructor().invoke(consargs);
}
- case CREATEPROXY: {
+ case CREATEPROXY: {
final int niface = args.narg()-1;
if ( niface <= 0 )
throw new LuaError("no interfaces");
@@ -136,7 +136,7 @@ public Varargs invoke(Varargs args) {
// get the interfaces
final Class[] ifaces = new Class[niface];
- for ( int i=0; i
+ *
*
* {@code
* String script = "print( 'hello, world' )";
@@ -46,9 +46,9 @@
* LuaValue globals = JsePlatform.standardGlobals();
* LuaClosure f = new LuaClosure(p, globals);
* f.call();
- * }
+ * }
* {@code
* Globals globals = JsePlatform.standardGlobals();
* LuaFunction f = globals.load(new StringReader(script), "script");
@@ -56,11 +56,11 @@
* c.call();
* }
*
*
* @see LuaValue
* @see LuaFunction
@@ -92,13 +92,13 @@ public class LuaClosure extends LuaFunction {
/** Create a closure around a Prototype with a specific environment.
* If the prototype has upvalues, the environment will be written into the first upvalue.
- * @param p the Prototype to construct this Closure for.
+ * @param p the Prototype to construct this Closure for.
* @param env the environment to associate with the closure.
*/
public LuaClosure(Prototype p, LuaValue env) {
this.p = p;
this.initupvalue1(env);
- globals = env instanceof Globals? (Globals) env: null;
+ globals = env instanceof Globals? (Globals) env: null;
}
public void initupvalue1(LuaValue env) {
@@ -123,26 +123,24 @@ public LuaClosure checkclosure() {
return this;
}
- public LuaValue getmetatable() {
- return s_metatable;
- }
-
public String tojstring() {
return "function: " + p.toString();
}
+ private LuaValue[] getNewStack() {
+ int max = p.maxstacksize;
+ LuaValue[] stack = new LuaValue[max];
+ System.arraycopy(NILS, 0, stack, 0, max);
+ return stack;
+ }
+
public final LuaValue call() {
- LuaValue[] stack = new LuaValue[p.maxstacksize];
- for (int i = 0; i < p.numparams; ++i )
- stack[i] = NIL;
+ LuaValue[] stack = getNewStack();
return execute(stack,NONE).arg1();
}
public final LuaValue call(LuaValue arg) {
- LuaValue[] stack = new LuaValue[p.maxstacksize];
- System.arraycopy(NILS, 0, stack, 0, p.maxstacksize);
- for (int i = 1; i < p.numparams; ++i )
- stack[i] = NIL;
+ LuaValue[] stack = getNewStack();
switch ( p.numparams ) {
default: stack[0]=arg; return execute(stack,NONE).arg1();
case 0: return execute(stack,arg).arg1();
@@ -150,9 +148,7 @@ public final LuaValue call(LuaValue arg) {
}
public final LuaValue call(LuaValue arg1, LuaValue arg2) {
- LuaValue[] stack = new LuaValue[p.maxstacksize];
- for (int i = 2; i < p.numparams; ++i )
- stack[i] = NIL;
+ LuaValue[] stack = getNewStack();
switch ( p.numparams ) {
default: stack[0]=arg1; stack[1]=arg2; return execute(stack,NONE).arg1();
case 1: stack[0]=arg1; return execute(stack,arg2).arg1();
@@ -161,9 +157,7 @@ public final LuaValue call(LuaValue arg1, LuaValue arg2) {
}
public final LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) {
- LuaValue[] stack = new LuaValue[p.maxstacksize];
- for (int i = 3; i < p.numparams; ++i )
- stack[i] = NIL;
+ LuaValue[] stack = getNewStack();
switch ( p.numparams ) {
default: stack[0]=arg1; stack[1]=arg2; stack[2]=arg3; return execute(stack,NONE).arg1();
case 2: stack[0]=arg1; stack[1]=arg2; return execute(stack,arg3).arg1();
@@ -177,9 +171,9 @@ public final Varargs invoke(Varargs varargs) {
}
public final Varargs onInvoke(Varargs varargs) {
- LuaValue[] stack = new LuaValue[p.maxstacksize];
+ LuaValue[] stack = getNewStack();
for ( int i=0; i {@code
* LuaValue a = LuaValue.valueOf( 5 );
* LuaValue b = LuaValue.valueOf( 4 );
* LuaValue c = a.div(b);
* }
- * Note that in this example, c will be a {@link LuaDouble}, but would be a {@link LuaInteger}
- * if the value of a were changed to 8, say.
+ * Note that in this example, c will be a {@link LuaDouble}, but would be a {@link LuaInteger}
+ * if the value of a were changed to 8, say.
* In general the value of c in practice will vary depending on both the types and values of a and b
- * as well as any metatable/metatag processing that occurs.
+ * as well as any metatable/metatag processing that occurs.
* {@code
@@ -58,7 +56,7 @@
* print.call( LuaValue.valueOf("sqrt(5):"), a );
* }
* {@code
* LuaValue modf = globals.get("math").get("modf");
@@ -71,18 +69,18 @@
* LoadState.load( new FileInputStream("main.lua"), "main.lua", globals ).call();
* }
* {@code
* globals.get("require").call(LuaValue.valueOf("main"));
* }
- * For this to work the file must be in the current directory, or in the class path,
- * dependening on the platform.
- * See {@link org.luaj.vm2.lib.jse.JsePlatform} and {@link org.luaj.vm2.lib.jme.JmePlatform} for details.
+ * For this to work the file must be in the current directory, or in the class path,
+ * dependening on the platform.
+ * See {@link org.luaj.vm2.lib.jse.JsePlatform} and {@link org.luaj.vm2.lib.jme.JmePlatform} for details.
*
@@ -90,22 +88,22 @@
*
- * {@code
@@ -55,7 +55,7 @@
* globals.get("print").call(LuaValue.valueOf("hello, world"));
* }
* {@code
@@ -63,8 +63,8 @@
* globals.load(new JseBaseLib());
* globals.get("print").call(LuaValue.valueOf("hello, world"));
* }
- * Doing so will ensure the library is properly initialized
- * and loaded into the globals table.
+ * Doing so will ensure the library is properly initialized
+ * and loaded into the globals table.
* {@code
* Globals globals = JsePlatform.standardGlobals();
* System.out.println( globals.get("bit32").get("bnot").call( LuaValue.valueOf(2) ) );
* }
* {@code
* Globals globals = new Globals();
@@ -71,7 +71,7 @@ public LuaValue call(LuaValue modname, LuaValue env) {
"arshift", "lrotate", "lshift", "rrotate", "rshift"
});
env.set("bit32", t);
- env.get("package").get("loaded").set("bit32", t);
+ if (!env.get("package").isnil()) env.get("package").get("loaded").set("bit32", t);
return t;
}
@@ -219,6 +219,6 @@ static LuaValue replace(int n, int v, int field, int width) {
}
private static LuaValue bitsToValue( int x ) {
- return ( x < 0 ) ? valueOf((double) ((long) x & 0xFFFFFFFFL)) : valueOf(x);
+ return ( x < 0 ) ? valueOf((double) ((long) x & 0xFFFFFFFFL)) : valueOf(x);
}
}
diff --git a/app/src/main/java/org/luaj/vm2/lib/CoroutineLib.java b/app/src/main/java/org/luaj/vm2/lib/CoroutineLib.java
index 6fe7644e..28cb246b 100644
--- a/app/src/main/java/org/luaj/vm2/lib/CoroutineLib.java
+++ b/app/src/main/java/org/luaj/vm2/lib/CoroutineLib.java
@@ -27,25 +27,25 @@
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Varargs;
-/**
- * Subclass of {@link LibFunction} which implements the lua standard {@code coroutine}
- * library.
- * {@code
* Globals globals = JsePlatform.standardGlobals();
* System.out.println( globals.get("coroutine").get("running").call() );
* }
* {@code
* Globals globals = new Globals();
@@ -82,7 +82,7 @@ public LuaValue call(LuaValue modname, LuaValue env) {
coroutine.set("yield", new yield());
coroutine.set("wrap", new wrap());
env.set("coroutine", coroutine);
- env.get("package").get("loaded").set("coroutine", coroutine);
+ if (!env.get("package").isnil()) env.get("package").get("loaded").set("coroutine", coroutine);
return coroutine;
}
@@ -92,7 +92,7 @@ public LuaValue call(LuaValue f) {
}
}
- final class resume extends VarArgFunction {
+ static final class resume extends VarArgFunction {
public Varargs invoke(Varargs args) {
final LuaThread t = args.checkthread(1);
return t.resume( args.subargs(2) );
@@ -127,7 +127,7 @@ public LuaValue call(LuaValue f) {
}
}
- final class wrapper extends VarArgFunction {
+ static final class wrapper extends VarArgFunction {
final LuaThread luathread;
wrapper(LuaThread luathread) {
this.luathread = luathread;
diff --git a/app/src/main/java/org/luaj/vm2/lib/DebugLib.java b/app/src/main/java/org/luaj/vm2/lib/DebugLib.java
index 71b13cb2..fd7c4c3c 100644
--- a/app/src/main/java/org/luaj/vm2/lib/DebugLib.java
+++ b/app/src/main/java/org/luaj/vm2/lib/DebugLib.java
@@ -38,26 +38,26 @@
import org.luaj.vm2.Prototype;
import org.luaj.vm2.Varargs;
-/**
- * Subclass of {@link LibFunction} which implements the lua standard {@code debug}
- * library.
- * {@code
* Globals globals = JsePlatform.debugGlobals();
* System.out.println( globals.get("debug").get("traceback").call() );
* }
* {@code
* Globals globals = new Globals();
@@ -84,27 +84,27 @@ public class DebugLib extends TwoArgFunction {
try { TRACE = (null != System.getProperty("TRACE")); } catch (Exception e) {}
}
- private static final LuaString LUA = valueOf("Lua");
- private static final LuaString QMARK = valueOf("?");
- private static final LuaString CALL = valueOf("call");
- private static final LuaString LINE = valueOf("line");
- private static final LuaString COUNT = valueOf("count");
+ static final LuaString LUA = valueOf("Lua");
+ private static final LuaString QMARK = valueOf("?");
+ private static final LuaString CALL = valueOf("call");
+ private static final LuaString LINE = valueOf("line");
+ private static final LuaString COUNT = valueOf("count");
private static final LuaString RETURN = valueOf("return");
- private static final LuaString FUNC = valueOf("func");
- private static final LuaString ISTAILCALL = valueOf("istailcall");
- private static final LuaString ISVARARG = valueOf("isvararg");
- private static final LuaString NUPS = valueOf("nups");
- private static final LuaString NPARAMS = valueOf("nparams");
- private static final LuaString NAME = valueOf("name");
- private static final LuaString NAMEWHAT = valueOf("namewhat");
- private static final LuaString WHAT = valueOf("what");
- private static final LuaString SOURCE = valueOf("source");
- private static final LuaString SHORT_SRC = valueOf("short_src");
- private static final LuaString LINEDEFINED = valueOf("linedefined");
- private static final LuaString LASTLINEDEFINED = valueOf("lastlinedefined");
- private static final LuaString CURRENTLINE = valueOf("currentline");
- private static final LuaString ACTIVELINES = valueOf("activelines");
+ static final LuaString FUNC = valueOf("func");
+ static final LuaString ISTAILCALL = valueOf("istailcall");
+ static final LuaString ISVARARG = valueOf("isvararg");
+ static final LuaString NUPS = valueOf("nups");
+ static final LuaString NPARAMS = valueOf("nparams");
+ static final LuaString NAME = valueOf("name");
+ static final LuaString NAMEWHAT = valueOf("namewhat");
+ static final LuaString WHAT = valueOf("what");
+ static final LuaString SOURCE = valueOf("source");
+ static final LuaString SHORT_SRC = valueOf("short_src");
+ static final LuaString LINEDEFINED = valueOf("linedefined");
+ static final LuaString LASTLINEDEFINED = valueOf("lastlinedefined");
+ static final LuaString CURRENTLINE = valueOf("currentline");
+ static final LuaString ACTIVELINES = valueOf("activelines");
Globals globals;
@@ -135,19 +135,19 @@ public LuaValue call(LuaValue modname, LuaValue env) {
debug.set("upvalueid", new upvalueid());
debug.set("upvaluejoin", new upvaluejoin());
env.set("debug", debug);
- env.get("package").get("loaded").set("debug", debug);
+ if (!env.get("package").isnil()) env.get("package").get("loaded").set("debug", debug);
return debug;
}
// debug.debug()
- static final class debug extends ZeroArgFunction {
+ static final class debug extends ZeroArgFunction {
public LuaValue call() {
return NONE;
}
}
// debug.gethook ([thread])
- final class gethook extends VarArgFunction {
+ final class gethook extends VarArgFunction {
public Varargs invoke(Varargs args) {
LuaThread t = args.narg() > 0 ? args.checkthread(1): globals.running;
LuaThread.State s = t.state;
@@ -159,10 +159,10 @@ public Varargs invoke(Varargs args) {
}
// debug.getinfo ([thread,] f [, what])
- final class getinfo extends VarArgFunction {
+ final class getinfo extends VarArgFunction {
public Varargs invoke(Varargs args) {
int a=1;
- LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running;
+ LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running;
LuaValue func = args.arg(a++);
String what = args.optjstring(a++, "flnStu");
DebugLib.CallStack callstack = callstack(thread);
@@ -222,10 +222,10 @@ public Varargs invoke(Varargs args) {
}
// debug.getlocal ([thread,] f, local)
- final class getlocal extends VarArgFunction {
+ final class getlocal extends VarArgFunction {
public Varargs invoke(Varargs args) {
int a=1;
- LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running;
+ LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running;
int level = args.checkint(a++);
int local = args.checkint(a++);
CallFrame f = callstack(thread).getCallFrame(level);
@@ -234,7 +234,7 @@ public Varargs invoke(Varargs args) {
}
// debug.getmetatable (value)
- final class getmetatable extends LibFunction {
+ static final class getmetatable extends LibFunction {
public LuaValue call(LuaValue v) {
LuaValue mt = v.getmetatable();
return mt != null? mt: NIL;
@@ -249,7 +249,7 @@ public LuaValue call() {
}
// debug.getupvalue (f, up)
- static final class getupvalue extends VarArgFunction {
+ static final class getupvalue extends VarArgFunction {
public Varargs invoke(Varargs args) {
LuaValue func = args.checkfunction(1);
int up = args.checkint(2);
@@ -265,7 +265,7 @@ public Varargs invoke(Varargs args) {
}
// debug.getuservalue (u)
- static final class getuservalue extends LibFunction {
+ static final class getuservalue extends LibFunction {
public LuaValue call(LuaValue u) {
return u.isuserdata()? u: NIL;
}
@@ -273,10 +273,10 @@ public LuaValue call(LuaValue u) {
// debug.sethook ([thread,] hook, mask [, count])
- final class sethook extends VarArgFunction {
+ final class sethook extends VarArgFunction {
public Varargs invoke(Varargs args) {
int a=1;
- LuaThread t = args.isthread(a)? args.checkthread(a++): globals.running;
+ LuaThread t = args.isthread(a)? args.checkthread(a++): globals.running;
LuaValue func = args.optfunction(a++, null);
String str = args.optjstring(a++,"");
int count = args.optint(a++,0);
@@ -298,20 +298,20 @@ public Varargs invoke(Varargs args) {
}
// debug.setlocal ([thread,] level, local, value)
- final class setlocal extends VarArgFunction {
+ final class setlocal extends VarArgFunction {
public Varargs invoke(Varargs args) {
int a=1;
- LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running;
+ LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running;
int level = args.checkint(a++);
int local = args.checkint(a++);
LuaValue value = args.arg(a++);
- CallFrame f = callstack(thread).getCallFrame(level);
+ CallFrame f = callstack(thread).getCallFrame(level);
return f != null? f.setLocal(local, value): NONE;
}
}
// debug.setmetatable (value, table)
- final class setmetatable extends TwoArgFunction {
+ static final class setmetatable extends TwoArgFunction {
public LuaValue call(LuaValue value, LuaValue table) {
LuaValue mt = table.opttable(null);
switch ( value.type() ) {
@@ -328,7 +328,7 @@ public LuaValue call(LuaValue value, LuaValue table) {
}
// debug.setupvalue (f, up, value)
- final class setupvalue extends VarArgFunction {
+ static final class setupvalue extends VarArgFunction {
public Varargs invoke(Varargs args) {
LuaValue func = args.checkfunction(1);
int up = args.checkint(2);
@@ -346,7 +346,7 @@ public Varargs invoke(Varargs args) {
}
// debug.setuservalue (udata, value)
- final class setuservalue extends VarArgFunction {
+ static final class setuservalue extends VarArgFunction {
public Varargs invoke(Varargs args) {
Object o = args.checkuserdata(1);
LuaValue v = args.checkvalue(2);
@@ -358,10 +358,10 @@ public Varargs invoke(Varargs args) {
}
// debug.traceback ([thread,] [message [, level]])
- final class traceback extends VarArgFunction {
+ final class traceback extends VarArgFunction {
public Varargs invoke(Varargs args) {
int a=1;
- LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running;
+ LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running;
String message = args.optjstring(a++, null);
int level = args.optint(a++,1);
String tb = callstack(thread).traceback(level);
@@ -370,7 +370,7 @@ public Varargs invoke(Varargs args) {
}
// debug.upvalueid (f, n)
- final class upvalueid extends VarArgFunction {
+ static final class upvalueid extends VarArgFunction {
public Varargs invoke(Varargs args) {
LuaValue func = args.checkfunction(1);
int up = args.checkint(2);
@@ -385,7 +385,7 @@ public Varargs invoke(Varargs args) {
}
// debug.upvaluejoin (f1, n1, f2, n2)
- final class upvaluejoin extends VarArgFunction {
+ static final class upvaluejoin extends VarArgFunction {
public Varargs invoke(Varargs args) {
LuaClosure f1 = args.checkclosure(1);
int n1 = args.checkint(2);
@@ -565,7 +565,11 @@ else if ( ar.name != null ) {
sb.append( ar.name );
sb.append( '\'' );
} else {
- sb.append( "function <"+c.shortsource()+":"+c.linedefined()+">" );
+ sb.append( "function <" );
+ sb.append( c.shortsource() );
+ sb.append( ':' );
+ sb.append( c.linedefined() );
+ sb.append( '>' );
}
}
sb.append("\n\t[Java]: in ?");
@@ -583,7 +587,7 @@ synchronized DebugLib.CallFrame findCallFrame(LuaValue func) {
if (frame[calls-i].f == func)
return frame[i];
return null;
- }
+ }
synchronized DebugInfo auxgetinfo(String what, LuaFunction f, CallFrame ci) {
@@ -637,7 +641,7 @@ synchronized DebugInfo auxgetinfo(String what, LuaFunction f, CallFrame ci) {
}
}
return ar;
- }
+ }
}
@@ -673,16 +677,16 @@ void instr(int pc, Varargs v, int top) {
}
Varargs getLocal(int i) {
LuaString name = getlocalname(i);
- if ( name != null )
- return varargsOf( name, stack[i-1] );
+ if ( i >= 1 && i <= stack.length && stack[i-1] != null )
+ return varargsOf( name == null ? NIL : name, stack[i-1] );
else
return NIL;
}
Varargs setLocal(int i, LuaValue value) {
LuaString name = getlocalname(i);
- if ( name != null ) {
+ if ( i >= 1 && i <= stack.length && stack[i-1] != null ) {
stack[i-1] = value;
- return name;
+ return name == null ? NIL : name;
} else {
return NIL;
}
@@ -690,13 +694,13 @@ Varargs setLocal(int i, LuaValue value) {
int currentline() {
if ( !f.isclosure() ) return -1;
int[] li = f.checkclosure().p.lineinfo;
- return li==null || pc<0 || pc>=li.length? -1: li[pc];
+ return li==null || pc<0 || pc>=li.length? -1: li[pc];
}
String sourceline() {
if ( !f.isclosure() ) return f.tojstring();
return f.checkclosure().p.shortsource() + ":" + currentline();
}
- private int linedefined() {
+ int linedefined() {
return f.isclosure()? f.checkclosure().p.linedefined: -1;
}
LuaString getlocalname(int index) {
@@ -717,7 +721,7 @@ static LuaString findupvalue(LuaClosure c, int up) {
static void lua_assert(boolean x) {
if (!x) throw new RuntimeException("lua_assert failed");
- }
+ }
static class NameWhat {
final String name;
@@ -867,6 +871,10 @@ static int findsetreg (Prototype p, int lastpc, int reg) {
if (reg == a) setreg = pc; /* jumped code can change 'a' */
break;
}
+ case Lua.OP_SETLIST: { // Lua.testAMode(Lua.OP_SETLIST) == false
+ if ( ((i>>14)&0x1ff) == 0 ) pc++; // if c == 0 then c stored in next op -> skip
+ break;
+ }
default:
if (Lua.testAMode(op) && reg == a) /* any instruction that set A */
setreg = pc;
diff --git a/app/src/main/java/org/luaj/vm2/lib/IoLib.java b/app/src/main/java/org/luaj/vm2/lib/IoLib.java
index 0c2f88e9..fa41b7bf 100644
--- a/app/src/main/java/org/luaj/vm2/lib/IoLib.java
+++ b/app/src/main/java/org/luaj/vm2/lib/IoLib.java
@@ -31,31 +31,31 @@
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Varargs;
-/**
- * Abstract base class extending {@link LibFunction} which implements the
- * core of the lua standard {@code io} library.
- * {@code
* Globals globals = JsePlatform.standardGlobals();
* globals.get("io").get("write").call(LuaValue.valueOf("hello, world\n"));
* }
* 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
+ * 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}.
* {@code
* Globals globals = new Globals();
@@ -73,10 +73,10 @@
* @see org.luaj.vm2.lib.jme.JmeIoLib
* @see http://www.lua.org/manual/5.1/manual.html#5.7
*/
-abstract
+abstract
public class IoLib extends TwoArgFunction {
- abstract
+ abstract
protected class File extends LuaValue{
abstract public void write( LuaString string ) throws IOException;
abstract public void flush() throws IOException;
@@ -85,12 +85,12 @@ protected class File extends LuaValue{
abstract public boolean isclosed();
// returns new position
abstract public int seek(String option, int bytecount) throws IOException;
- abstract public void setvbuf(String mode, int size);
+ abstract public void setvbuf(String mode, int size);
// get length remaining to read
- abstract public int remaining() throws IOException;
+ abstract public int remaining() throws IOException;
// peek ahead one character
- abstract public int peek() throws IOException, EOFException;
- // return char if read, -1 if eof, throw IOException on other exception
+ abstract public int peek() throws IOException, EOFException;
+ // return char if read, -1 if eof, throw IOException on other exception
abstract public int read() throws IOException, EOFException;
// return number of bytes read if positive, false if eof, throw IOException on other exception
abstract public int read(byte[] bytes, int offset, int length) throws IOException;
@@ -123,29 +123,29 @@ public String tojstring() {
/** Enumerated value representing a file type for a named file */
protected static final int FTYPE_NAMED = 3;
- /**
- * Wrap the standard input.
- * @return File
+ /**
+ * Wrap the standard input.
+ * @return File
* @throws IOException
*/
abstract protected File wrapStdin() throws IOException;
- /**
- * Wrap the standard output.
- * @return File
+ /**
+ * Wrap the standard output.
+ * @return File
* @throws IOException
*/
abstract protected File wrapStdout() throws IOException;
- /**
- * Wrap the standard error output.
- * @return File
+ /**
+ * Wrap the standard error output.
+ * @return File
* @throws IOException
*/
abstract protected File wrapStderr() throws IOException;
/**
- * Open a file in a particular mode.
+ * Open a file in a particular mode.
* @param filename
* @param readMode true if opening in read mode
* @param appendMode true if opening in append mode
@@ -157,7 +157,7 @@ public String tojstring() {
abstract protected File openFile( String filename, boolean readMode, boolean appendMode, boolean updateMode, boolean binaryMode ) throws IOException;
/**
- * Open a temporary file.
+ * Open a temporary file.
* @return File object if successful
* @throws IOException if could not be opened
*/
@@ -167,7 +167,7 @@ public String tojstring() {
* Start a new process and return a file for input or output
* @param prog the program to execute
* @param mode "r" to read, "w" to write
- * @return File to read to or write from
+ * @return File to read to or write from
* @throws IOException if an i/o exception occurs
*/
abstract protected File openProgram(String prog, String mode) throws IOException;
@@ -178,7 +178,7 @@ public String tojstring() {
private static final LuaValue STDIN = valueOf("stdin");
private static final LuaValue STDOUT = valueOf("stdout");
- private static final LuaValue STDERR = valueOf("stderr");
+ private static final LuaValue STDERR = valueOf("stderr");
private static final LuaValue FILE = valueOf("file");
private static final LuaValue CLOSED_FILE = valueOf("closed file");
@@ -256,7 +256,7 @@ public LuaValue call(LuaValue modname, LuaValue env) {
// return the table
env.set("io", t);
- env.get("package").get("loaded").set("io", t);
+ if (!env.get("package").isnil()) env.get("package").get("loaded").set("io", t);
return t;
}
@@ -316,7 +316,7 @@ private File input() {
return infile!=null? infile: (infile=ioopenfile(FTYPE_STDIN, "-","r"));
}
- // io.flush() -> bool
+ // io.flush() -> bool
public Varargs _io_flush() throws IOException {
checkopen(output());
outfile.flush();
@@ -337,7 +337,7 @@ public Varargs _io_close(LuaValue file) throws IOException {
// io.input([file]) -> file
public Varargs _io_input(LuaValue file) {
- infile = file.isnil()? input():
+ infile = file.isnil()? input():
file.isstring()? ioopenfile(FTYPE_NAMED, file.checkjstring(),"r"):
checkfile(file);
return infile;
@@ -345,7 +345,7 @@ public Varargs _io_input(LuaValue file) {
// io.output(filename) -> file
public Varargs _io_output(LuaValue filename) {
- outfile = filename.isnil()? output():
+ outfile = filename.isnil()? output():
filename.isstring()? ioopenfile(FTYPE_NAMED, filename.checkjstring(),"w"):
checkfile(filename);
return outfile;
@@ -420,7 +420,7 @@ public Varargs _file_seek(LuaValue file, String whence, int offset) throws IOExc
return valueOf( checkfile(file).seek(whence,offset) );
}
- // file:write(...) -> void
+ // file:write(...) -> void
public Varargs _file_write(LuaValue file, Varargs subargs) throws IOException {
return iowrite(checkfile(file),subargs);
}
@@ -467,8 +467,8 @@ private static Varargs successresult() {
return LuaValue.TRUE;
}
- private static Varargs errorresult(Exception ioe) {
- String s = ioe.getMessage();
+ static Varargs errorresult(Exception ioe) {
+ String s = ioe.getMessage();
return errorresult("io error: "+(s!=null? s: ioe.toString()));
}
@@ -509,8 +509,8 @@ private Varargs ioread(File f, Varargs args) throws IOException {
case 'a': vi = freadall(f); break item;
}
}
- default:
- return argerror( i+1, "(invalid format)" );
+ default:
+ return argerror( i+1, "(invalid format)" );
}
if ( (v[i++] = vi).isnil() )
break;
@@ -544,7 +544,7 @@ private File rawopenfile(int filetype, String filename, String mode) throws IOEx
}
boolean isreadmode = mode.startsWith("r");
boolean isappend = mode.startsWith("a");
- boolean isupdate = mode.indexOf("+") > 0;
+ boolean isupdate = mode.indexOf('+') > 0;
boolean isbinary = mode.endsWith("b");
return openFile( filename, isreadmode, isappend, isupdate, isbinary );
}
@@ -564,7 +564,7 @@ public static LuaValue freaduntil(File f,boolean lineonly) throws IOException {
int c;
try {
if ( lineonly ) {
- loop: while ( (c = f.read()) > 0 ) {
+ loop: while ( (c = f.read()) > 0 ) {
switch ( c ) {
case '\r': break;
case '\n': break loop;
@@ -572,13 +572,13 @@ public static LuaValue freaduntil(File f,boolean lineonly) throws IOException {
}
}
} else {
- while ( (c = f.read()) > 0 )
+ while ( (c = f.read()) > 0 )
baos.write(c);
}
} catch ( EOFException e ) {
c = -1;
}
- return ( c < 0 && baos.size() == 0 )?
+ return ( c < 0 && baos.size() == 0 )?
(LuaValue) NIL:
(LuaValue) LuaString.valueUsing(baos.toByteArray());
}
@@ -619,7 +619,7 @@ private static void freadchars(File f, String chars, ByteArrayOutputStream baos)
if ( baos != null )
baos.write( c );
}
- }
+ }
diff --git a/app/src/main/java/org/luaj/vm2/lib/LibFunction.java b/app/src/main/java/org/luaj/vm2/lib/LibFunction.java
index 1585285b..b537dab4 100644
--- a/app/src/main/java/org/luaj/vm2/lib/LibFunction.java
+++ b/app/src/main/java/org/luaj/vm2/lib/LibFunction.java
@@ -139,7 +139,7 @@ protected LibFunction() {
}
public String tojstring() {
- return name != null? name: super.tojstring();
+ return name != null ? "function: " + name : super.tojstring();
}
/**
diff --git a/app/src/main/java/org/luaj/vm2/lib/MathLib.java b/app/src/main/java/org/luaj/vm2/lib/MathLib.java
index 6b288875..7aebee77 100644
--- a/app/src/main/java/org/luaj/vm2/lib/MathLib.java
+++ b/app/src/main/java/org/luaj/vm2/lib/MathLib.java
@@ -28,13 +28,13 @@
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Varargs;
-/**
- * Subclass of {@link LibFunction} which implements the lua standard {@code math}
- * library.
- *
*
* {@code
* Globals globals = JsePlatform.standardGlobals();
* System.out.println( globals.get("math").get("sqrt").call( LuaValue.valueOf(2) ) );
* }
- * When using {@link org.luaj.vm2.lib.jse.JsePlatform} as in this example,
- * the subclass {@link org.luaj.vm2.lib.jse.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.
* {@code
* Globals globals = new Globals();
@@ -70,8 +70,8 @@
* globals.load(new MathLib());
* System.out.println( globals.get("math").get("sqrt").call( LuaValue.valueOf(2) ) );
* }
- * Doing so will ensure the library is properly initialized
- * and loaded into the globals table.
+ * Doing so will ensure the library is properly initialized
+ * and loaded into the globals table.
*
*
* {@code
* Globals globals = JsePlatform.standardGlobals();
@@ -63,7 +63,7 @@
* 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.
* {@code
* Globals globals = new Globals();
@@ -80,8 +80,8 @@
* @see http://www.lua.org/manual/5.1/manual.html#5.8
*/
public class OsLib extends TwoArgFunction {
- public static String TMP_PREFIX = ".luaj";
- public static String TMP_SUFFIX = "tmp";
+ public static final String TMP_PREFIX = ".luaj";
+ public static final String TMP_SUFFIX = "tmp";
private static final int CLOCK = 0;
private static final int DATE = 1;
@@ -114,8 +114,8 @@ public class OsLib extends TwoArgFunction {
protected Globals globals;
- /**
- * Create and OsLib instance.
+ /**
+ * Create and OsLib instance.
*/
public OsLib() {
}
@@ -132,7 +132,7 @@ public LuaValue call(LuaValue modname, LuaValue env) {
for (int i = 0; i < NAMES.length; ++i)
os.set(NAMES[i], new OsLibFunc(i, NAMES[i]));
env.set("os", os);
- env.get("package").get("loaded").set("os", os);
+ if (!env.get("package").isnil()) env.get("package").get("loaded").set("os", os);
return os;
}
@@ -200,8 +200,8 @@ public Varargs invoke(Varargs args) {
}
/**
- * @return an approximation of the amount in seconds of CPU time used by
- * the program. For luaj this simple returns the elapsed time since the
+ * @return an approximation of the amount in seconds of CPU time used by
+ * the program. For luaj this simple returns the elapsed time since the
* OsLib class was loaded.
*/
protected double clock() {
@@ -209,7 +209,7 @@ protected double clock() {
}
/**
- * Returns the number of seconds from time t1 to time t2.
+ * Returns the number of seconds from time t1 to time t2.
* In POSIX, Windows, and some other systems, this value is exactly t2-t1.
* @param t2
* @param t1
@@ -220,21 +220,21 @@ protected double difftime(double t2, double t1) {
}
/**
- * If the time argument is present, this is the time to be formatted
- * (see the os.time function for a description of this value).
+ * If the time argument is present, this is the time to be formatted
+ * (see the os.time function for a description of this value).
* Otherwise, date formats the current time.
*
- * Date returns the date as a string,
+ * Date returns the date as a string,
* formatted according to the same rules as ANSII strftime, but without
* support for %g, %G, or %V.
*
- * When called without arguments, date returns a reasonable date and
- * time representation that depends on the host system and on the
+ * When called without arguments, date returns a reasonable date and
+ * time representation that depends on the host system and on the
* current locale (that is, os.date() is equivalent to os.date("%c")).
- *
- * @param format
+ *
+ * @param format
* @param time time since epoch, or -1 if not supplied
- * @return a LString or a LTable containing date and time,
+ * @return a LString or a LTable containing date and time,
* formatted according to the given string format.
*/
public String date(String format, double time) {
@@ -277,8 +277,8 @@ public String date(String format, double time) {
break;
case 'B':
result.append(MonthName[d.get(Calendar.MONTH)]);
- break;
- case 'c':
+ break;
+ case 'c':
result.append(date("%a %b %d %H:%M:%S %Y", time));
break;
case 'd':
@@ -314,7 +314,7 @@ public String date(String format, double time) {
case 'w':
result.append(String.valueOf((d.get(Calendar.DAY_OF_WEEK)+6)%7));
break;
- case 'W':
+ case 'W':
result.append(String.valueOf(weekNumber(d, 1)));
break;
case 'x':
@@ -372,7 +372,7 @@ private int weekNumber(Calendar d, int startDay) {
}
private int timeZoneOffset(Calendar d) {
- int localStandarTimeMillis = (
+ int localStandarTimeMillis = (
d.get(Calendar.HOUR_OF_DAY) * 3600 +
d.get(Calendar.MINUTE) * 60 +
d.get(Calendar.SECOND)) * 1000;
@@ -381,28 +381,28 @@ private int timeZoneOffset(Calendar d) {
d.get(Calendar.YEAR),
d.get(Calendar.MONTH),
d.get(Calendar.DAY_OF_MONTH),
- d.get(Calendar.DAY_OF_WEEK),
+ d.get(Calendar.DAY_OF_WEEK),
localStandarTimeMillis) / 1000;
}
private boolean isDaylightSavingsTime(Calendar d) {
- return timeZoneOffset(d) != d.getTimeZone().getRawOffset() / 1000;
+ return timeZoneOffset(d) != d.getTimeZone().getRawOffset() / 1000;
}
- /**
- * This function is equivalent to the C function system.
- * It passes command to be executed by an operating system shell.
- * It returns a status code, which is system-dependent.
- * If command is absent, then it returns nonzero if a shell
+ /**
+ * This function is equivalent to the C function system.
+ * It passes command to be executed by an operating system shell.
+ * It returns a status code, which is system-dependent.
+ * If command is absent, then it returns nonzero if a shell
* is available and zero otherwise.
* @param command command to pass to the system
- */
+ */
protected Varargs execute(String command) {
return varargsOf(NIL, valueOf("exit"), ONE);
}
/**
- * Calls the C function exit, with an optional code, to terminate the host program.
+ * Calls the C function exit, with an optional code, to terminate the host program.
* @param code
*/
protected void exit(int code) {
@@ -415,13 +415,13 @@ protected void exit(int code) {
* or null if the variable is not defined in either environment.
*
* The default implementation, which is used by the JmePlatform,
- * only queryies System.getProperty().
+ * only queryies System.getProperty().
*
* The JsePlatform overrides this behavior and returns the
- * environment variable value using System.getenv() if it exists,
+ * environment variable value using System.getenv() if it exists,
* or the System property value if it does not.
*
- * A SecurityException may be thrown if access is not allowed
+ * A SecurityException may be thrown if access is not allowed
* for 'varname'.
* @param varname
* @return String value, or null if not defined
@@ -431,10 +431,10 @@ protected String getenv(String varname) {
}
/**
- * Deletes the file or directory with the given name.
- * Directories must be empty to be removed.
+ * Deletes the file or directory with the given name.
+ * Directories must be empty to be removed.
* If this function fails, it throws and IOException
- *
+ *
* @param filename
* @throws IOException if it fails
*/
@@ -443,9 +443,9 @@ protected void remove(String filename) throws IOException {
}
/**
- * Renames file or directory named oldname to newname.
+ * Renames file or directory named oldname to newname.
* If this function fails,it throws and IOException
- *
+ *
* @param oldname old file name
* @param newname new file name
* @throws IOException if it fails
@@ -455,21 +455,21 @@ protected void rename(String oldname, String newname) throws IOException {
}
/**
- * Sets the current locale of the program. locale is a string specifying
- * a locale; category is an optional string describing which category to change:
- * "all", "collate", "ctype", "monetary", "numeric", or "time"; the default category
- * is "all".
+ * Sets the current locale of the program. locale is a string specifying
+ * a locale; category is an optional string describing which category to change:
+ * "all", "collate", "ctype", "monetary", "numeric", or "time"; the default category
+ * is "all".
*
* If locale is the empty string, the current locale is set to an implementation-
- * defined native locale. If locale is the string "C", the current locale is set
+ * defined native locale. If locale is the string "C", the current locale is set
* to the standard C locale.
*
- * When called with null as the first argument, this function only returns the
+ * When called with null as the first argument, this function only returns the
* name of the current locale for the given category.
- *
+ *
* @param locale
* @param category
- * @return the name of the new locale, or null if the request
+ * @return the name of the new locale, or null if the request
* cannot be honored.
*/
protected String setlocale(String locale, String category) {
@@ -477,10 +477,10 @@ protected String setlocale(String locale, String category) {
}
/**
- * Returns the current time when called without arguments,
- * or a time representing the date and time specified by the given table.
- * This table must have fields year, month, and day,
- * and may have fields hour, min, sec, and isdst
+ * Returns the current time when called without arguments,
+ * or a time representing the date and time specified by the given table.
+ * This table must have fields year, month, and day,
+ * and may have fields hour, min, sec, and isdst
* (for a description of these fields, see the os.date function).
* @param table
* @return long value for the time
@@ -504,15 +504,15 @@ protected double time(LuaTable table) {
}
/**
- * Returns a string with a file name that can be used for a temporary file.
- * The file must be explicitly opened before its use and explicitly removed
+ * Returns a string with a file name that can be used for a temporary file.
+ * The file must be explicitly opened before its use and explicitly removed
* when no longer needed.
*
- * On some systems (POSIX), this function also creates a file with that name,
- * to avoid security risks. (Someone else might create the file with wrong
- * permissions in the time between getting the name and creating the file.)
- * You still have to open the file to use it and to remove it (even if you
- * do not use it).
+ * On some systems (POSIX), this function also creates a file with that name,
+ * to avoid security risks. (Someone else might create the file with wrong
+ * permissions in the time between getting the name and creating the file.)
+ * You still have to open the file to use it and to remove it (even if you
+ * do not use it).
*
* @return String filename to use
*/
diff --git a/app/src/main/java/org/luaj/vm2/lib/PackageLib.java b/app/src/main/java/org/luaj/vm2/lib/PackageLib.java
index 74157fac..db344818 100644
--- a/app/src/main/java/org/luaj/vm2/lib/PackageLib.java
+++ b/app/src/main/java/org/luaj/vm2/lib/PackageLib.java
@@ -30,9 +30,9 @@
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Varargs;
-/**
- * Subclass of {@link LibFunction} which implements the lua standard package and module
- * library functions.
+/**
+ * Subclass of {@link LibFunction} which implements the lua standard package and module
+ * library functions.
*
* Lua Environment Variables
* The following variables are available to lua scrips when this library has been loaded:
@@ -50,14 +50,14 @@
*
*
* Loading
- * Typically, this library is included as part of a call to either
+ * Typically, this library is included as part of a call to either
* {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()}
* {@code
* Globals globals = JsePlatform.standardGlobals();
* System.out.println( globals.get("require").call"foo") );
* }
* {@code
* Globals globals = new Globals();
@@ -67,8 +67,8 @@
* }
* Limitations
* 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 org.luaj.vm2.lib.jse.JseBaseLib} documentation.
+ * However, the default filesystem search semantics are different and delegated to the bas library
+ * as outlined in the {@link BaseLib} and {@link org.luaj.vm2.lib.jse.JseBaseLib} documentation.
* "luaj.package.path", and is "?.lua" by default. */
- public static String DEFAULT_LUA_PATH;
+ public static final String DEFAULT_LUA_PATH;
static {
+ String path = null;
try {
- DEFAULT_LUA_PATH = System.getProperty("luaj.package.path");
+ path = System.getProperty("luaj.package.path");
} catch (Exception e) {
System.out.println(e.toString());
}
- if (DEFAULT_LUA_PATH == null)
- DEFAULT_LUA_PATH = "?.lua";
+ if (path == null) {
+ path = "?.lua";
+ }
+ DEFAULT_LUA_PATH = path;
}
- private static final LuaString _LOADED = valueOf("loaded");
+ static final LuaString _LOADED = valueOf("loaded");
private static final LuaString _LOADLIB = valueOf("loadlib");
- private static final LuaString _PRELOAD = valueOf("preload");
- private static final LuaString _PATH = valueOf("path");
- private static final LuaString _SEARCHPATH = valueOf("searchpath");
- private static final LuaString _SEARCHERS = valueOf("searchers");
+ static final LuaString _PRELOAD = valueOf("preload");
+ static final LuaString _PATH = valueOf("path");
+ static final LuaString _SEARCHPATH = valueOf("searchpath");
+ static final LuaString _SEARCHERS = valueOf("searchers");
/** The globals that were used to load this library. */
Globals globals;
@@ -153,7 +156,7 @@ public void setIsLoaded(String name, LuaTable value) {
}
- /** Set the lua path used by this library instance to a new value.
+ /** Set the lua path used by this library instance to a new value.
* Merely sets the value of {@link path} to be used in subsequent searches. */
public void setLuaPath( String newLuaPath ) {
package_.set(_PATH, LuaValue.valueOf(newLuaPath));
@@ -165,33 +168,33 @@ public String tojstring() {
// ======================== Package loading =============================
- /**
+ /**
* require (modname)
*
- * Loads the given module. The function starts by looking into the package.loaded table
- * to determine whether modname is already loaded. If it is, then require returns the value
+ * Loads the given module. The function starts by looking into the package.loaded table
+ * to determine whether modname is already loaded. If it is, then require returns the value
* stored at package.loaded[modname]. Otherwise, it tries to find a loader for the module.
*
- * To find a loader, require is guided by the package.searchers sequence.
- * By changing this sequence, we can change how require looks for a module.
+ * To find a loader, require is guided by the package.searchers sequence.
+ * By changing this sequence, we can change how require looks for a module.
* The following explanation is based on the default configuration for package.searchers.
*
- * First require queries package.preload[modname]. If it has a value, this value
- * (which should be a function) is the loader. Otherwise require searches for a Lua loader using
- * the path stored in package.path. If that also fails, it searches for a Java loader using
+ * First require queries package.preload[modname]. If it has a value, this value
+ * (which should be a function) is the loader. Otherwise require searches for a Lua loader using
+ * the path stored in package.path. If that also fails, it searches for a Java loader using
* the classpath, using the public default constructor, and casting the instance to LuaFunction.
*
- * Once a loader is found, require calls the loader with two arguments: modname and an extra value
+ * Once a loader is found, require calls the loader with two arguments: modname and an extra value
* dependent on how it got the loader. If the loader came from a file, this extra value is the file name.
- * If the loader is a Java instance of LuaFunction, this extra value is the environment.
- * If the loader returns any non-nil value, require assigns the returned value to package.loaded[modname].
- * If the loader does not return a non-nil value and has not assigned any value to package.loaded[modname],
+ * If the loader is a Java instance of LuaFunction, this extra value is the environment.
+ * If the loader returns any non-nil value, require assigns the returned value to package.loaded[modname].
+ * If the loader does not return a non-nil value and has not assigned any value to package.loaded[modname],
* then require assigns true to this entry.
* In any case, require returns the final value of package.loaded[modname].
- *
+ *
* If there is any error loading or running the module, or if it cannot find any loader for the module,
* then require raises an error.
- */
+ */
public class require extends OneArgFunction {
public LuaValue call( LuaValue arg ) {
LuaString name = arg.checkstring();
@@ -210,7 +213,7 @@ public LuaValue call( LuaValue arg ) {
for ( int i=1; true; i++ ) {
LuaValue searcher = tbl.get(i);
if ( searcher.isnil() ) {
- error( "module '"+name+"' not found: "+name+sb );
+ error( "module '"+name+"' not found: "+name+sb );
}
/* call loader with module name as argument */
@@ -226,14 +229,14 @@ public LuaValue call( LuaValue arg ) {
result = loader.arg1().call(name, loader.arg(2));
if ( ! result.isnil() )
loaded.set( name, result );
- else if ( (result = loaded.get(name)) == _SENTINEL )
+ else if ( (result = loaded.get(name)) == _SENTINEL )
loaded.set( name, result = LuaValue.TRUE );
return result;
}
}
public static class loadlib extends VarArgFunction {
- public Varargs loadlib( Varargs args ) {
+ public Varargs invoke( Varargs args ) {
args.checkstring(1);
return varargsOf(NIL, valueOf("dynamic libraries not enabled"), valueOf("absent"));
}
@@ -243,7 +246,7 @@ public class preload_searcher extends VarArgFunction {
public Varargs invoke(Varargs args) {
LuaString name = args.checkstring(1);
LuaValue val = package_.get(_PRELOAD).get(name);
- return val.isnil()?
+ return val.isnil()?
valueOf("\n\tno field package.preload['"+name+"']"):
val;
}
@@ -252,11 +255,10 @@ public Varargs invoke(Varargs args) {
public class lua_searcher extends VarArgFunction {
public Varargs invoke(Varargs args) {
LuaString name = args.checkstring(1);
- InputStream is = null;
// get package path
LuaValue path = package_.get(_PATH);
- if ( ! path.isstring() )
+ if ( ! path.isstring() )
return valueOf("package.path is not a string");
// get the searchpath function.
@@ -268,7 +270,7 @@ public Varargs invoke(Varargs args) {
LuaString filename = v.arg1().strvalue();
// Try to load the file.
- v = globals.loadfile(filename.tojstring());
+ v = globals.loadfile(filename.tojstring());
if ( v.arg1().isfunction() )
return LuaValue.varargsOf(v.arg1(), filename);
@@ -353,9 +355,9 @@ public static final String toClassname( String filename ) {
StringBuffer sb = new StringBuffer(j);
for ( int i=0; i {@code
* Globals globals = JsePlatform.standardGlobals();
* System.out.println( globals.get("string").get("upper").call( LuaValue.valueOf("abcde") ) );
* }
* {@code
* Globals globals = new Globals();
* globals.load(new JseBaseLib());
* globals.load(new PackageLib());
- * globals.load(new StringLib());
+ * globals.load(new JseStringLib());
* System.out.println( globals.get("string").get("upper").call( LuaValue.valueOf("abcde") ) );
* }
* {@code
* Globals globals = JsePlatform.standardGlobals();
* System.out.println( globals.get("table").get("length").call( LuaValue.tableOf() ) );
* }
* {@code
* Globals globals = new Globals();
@@ -70,7 +70,7 @@ public LuaValue call(LuaValue modname, LuaValue env) {
table.set("sort", new sort());
table.set("unpack", new unpack());
env.set("table", table);
- env.get("package").get("loaded").set("table", table);
+ if (!env.get("package").isnil()) env.get("package").get("loaded").set("table", table);
return NIL;
}
diff --git a/app/src/main/java/org/luaj/vm2/lib/jse/CoerceJavaToLua.java b/app/src/main/java/org/luaj/vm2/lib/jse/CoerceJavaToLua.java
index 107fafd0..177f9acf 100644
--- a/app/src/main/java/org/luaj/vm2/lib/jse/CoerceJavaToLua.java
+++ b/app/src/main/java/org/luaj/vm2/lib/jse/CoerceJavaToLua.java
@@ -102,11 +102,11 @@ public LuaValue coerce( Object javaValue ) {
}
}
- //private static final class BytesCoercion implements Coercion {
- // public LuaValue coerce( Object javaValue ) {
- // return LuaValue.valueOf((byte[]) javaValue);
- // }
- //}
+ private static final class BytesCoercion implements Coercion {
+ public LuaValue coerce( Object javaValue ) {
+ return LuaValue.valueOf((byte[]) javaValue);
+ }
+ }
private static final class ClassCoercion implements Coercion {
public LuaValue coerce( Object javaValue ) {
@@ -142,7 +142,7 @@ public LuaValue coerce( Object javaValue ) {
Coercion charCoercion = new CharCoercion() ;
Coercion doubleCoercion = new DoubleCoercion() ;
Coercion stringCoercion = new StringCoercion() ;
- //Coercion bytesCoercion = new BytesCoercion() ;
+ Coercion bytesCoercion = new BytesCoercion() ;
Coercion classCoercion = new ClassCoercion() ;
COERCIONS.put( Boolean.class, boolCoercion );
COERCIONS.put( Byte.class, intCoercion );
@@ -153,7 +153,7 @@ public LuaValue coerce( Object javaValue ) {
COERCIONS.put( Float.class, doubleCoercion );
COERCIONS.put( Double.class, doubleCoercion );
COERCIONS.put( String.class, stringCoercion );
- //COERCIONS.put( byte[].class, bytesCoercion );
+ COERCIONS.put( byte[].class, bytesCoercion );
COERCIONS.put( Class.class, classCoercion );
}
diff --git a/app/src/main/java/org/luaj/vm2/lib/jse/JavaClass.java b/app/src/main/java/org/luaj/vm2/lib/jse/JavaClass.java
index 4011eee3..553c8e73 100644
--- a/app/src/main/java/org/luaj/vm2/lib/jse/JavaClass.java
+++ b/app/src/main/java/org/luaj/vm2/lib/jse/JavaClass.java
@@ -26,7 +26,6 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@@ -76,22 +75,10 @@ public LuaValue coerce(Object javaValue) {
Field getField(LuaValue key) {
if ( fields == null ) {
Map m = new HashMap();
- List
* {@code
* globals.get("require").call(LuaValue.valueOf("main"));
* }
@@ -73,8 +72,8 @@
* {@code
* Globals globals = JsePlatform.standardGlobals();
* System.out.println( globals.get("luajava").get("bindClass").call( LuaValue.valueOf("java.lang.System") ).invokeMethod("currentTimeMillis") );
* }
* {@code
* Globals globals = new Globals();
* globals.load(new JseBaseLib());
* globals.load(new PackageLib());
* globals.load(new LuajavaLib());
- * globals.load(
+ * globals.load(
* "sys = luajava.bindClass('java.lang.System')\n"+
- * "print ( sys:currentTimeMillis() )\n", "main.lua" ).call();
+ * "print ( sys:currentTimeMillis() )\n", "main.lua" ).call();
* }
*