org.luaj.vm2
Class LuaValue

java.lang.Object
  extended by org.luaj.vm2.Varargs
      extended by org.luaj.vm2.LuaValue
Direct Known Subclasses:
IoLib.File, LuaBoolean, LuaFunction, LuaNil, LuaNumber, LuaString, LuaTable, LuaThread, LuaUserdata

public abstract class LuaValue
extends Varargs

Base class for all concrete lua type values.

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 LuaValue.

Constructors are provided as static methods for common Java types, such as valueOf(int) or valueOf(String) to allow for instance pooling.

Constants are defined for the lua values NIL, TRUE, and FALSE. A constant NONE is defined which is a Varargs list having no values.

Operations are performed on values directly via their Java methods. For example, the following code divides two numbers:

 LuaValue a = LuaValue.valueOf( 5 );
 LuaValue b = LuaValue.valueOf( 4 );
 LuaValue c = a.div(b);
  
Note that in this example, c will be a LuaDouble, but would be a 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.

Field access and function calls are similar, with common overloads to simplify Java usage:

 LuaValue globals = JsePlatform.standardGlobals();
 LuaValue sqrt = globals.get("math").get("sqrt");
 LuaValue print = globals.get("print");
 LuaValue d = sqrt.call( a );
 print.call( LuaValue.valueOf("sqrt(5):"), a );
  

To supply variable arguments or get multiple return values, use invoke(Varargs) or invokemethod(LuaValue, Varargs) methods:

 LuaValue modf = globals.get("math").get("modf");
 Varargs r = modf.invoke( d );
 print.call( r.arg(1), r.arg(2) );
  

To load and run a script, LoadState is used:

 LoadState.load( new FileInputStream("main.lua"), "main.lua", globals ).call();
  

although require could also be used:

 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 JsePlatform and JmePlatform for details.

In general a 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 TNIL, TBOOLEAN, TLIGHTUSERDATA, TNUMBER, TSTRING, TTABLE, TFUNCTION, TUSERDATA, TTHREAD, and extended lua type constants TINT, TNONE, TVALUE

Predefined constants exist for all strings used as metatags: INDEX, NEWINDEX, CALL, MODE, METATABLE, ADD, SUB, DIV, MUL, POW, MOD, UNM, LEN, EQ, LT, LE, TOSTRING, and CONCAT.

See Also:
JsePlatform, JmePlatform, LoadState, Varargs

Field Summary
static LuaString ADD
          LuaString constant with value "__add" for use as metatag
static LuaString CALL
          LuaString constant with value "__call" for use as metatag
static LuaString CONCAT
          LuaString constant with value "__concat" for use as metatag
static LuaString DIV
          LuaString constant with value "__div" for use as metatag
static LuaString EMPTYSTRING
          LuaString constant with value ""
static LuaString ENV
          The variable name of the environment.
static LuaString EQ
          LuaString constant with value "__eq" for use as metatag
static LuaBoolean FALSE
          LuaBoolean constant corresponding to lua false
static LuaString INDEX
          LuaString constant with value "__index" for use as metatag
static LuaString LE
          LuaString constant with value "__le" for use as metatag
static LuaString LEN
          LuaString constant with value "__len" for use as metatag
static LuaString LT
          LuaString constant with value "__lt" for use as metatag
static LuaString METATABLE
          LuaString constant with value "__metatable" for use as metatag
static LuaNumber MINUSONE
          LuaValue number constant equal to -1
static LuaString MOD
          LuaString constant with value "__mod" for use as metatag
static LuaString MODE
          LuaString constant with value "__mode" for use as metatag
static LuaString MUL
          LuaString constant with value "__mul" for use as metatag
static LuaString NEWINDEX
          LuaString constant with value "__newindex" for use as metatag
static LuaValue NIL
          LuaValue constant corresponding to lua #NIL
static LuaValue[] NILS
          Array of NIL values to optimize filling stacks using System.arraycopy().
static LuaValue NONE
          LuaValue constant corresponding to a Varargs list of no values
static LuaValue[] NOVALS
          LuaValue array constant with no values
static LuaNumber ONE
          LuaValue number constant equal to 1
static LuaString POW
          LuaString constant with value "__pow" for use as metatag
static LuaString SUB
          LuaString constant with value "__sub" for use as metatag
static int TBOOLEAN
          Type enumeration constant for lua booleans
static int TFUNCTION
          Type enumeration constant for lua functions
static int TINT
          Type enumeration constant for lua numbers that are ints, for compatibility with lua 5.1 number patch only
static int TLIGHTUSERDATA
          Type enumeration constant for lua light userdata, for compatibility with C-based lua only
static int TNIL
          Type enumeration constant for lua nil
static int TNONE
          Type enumeration constant for lua values that have no type, for example weak table entries
static int TNUMBER
          Type enumeration constant for lua numbers
static LuaString TOSTRING
          LuaString constant with value "__tostring" for use as metatag
static LuaBoolean TRUE
          LuaBoolean constant corresponding to lua true
static int TSTRING
          Type enumeration constant for lua strings
static int TTABLE
          Type enumeration constant for lua tables
static int TTHREAD
          Type enumeration constant for lua threads
static int TUSERDATA
          Type enumeration constant for lua userdatas
static int TVALUE
          Type enumeration constant for unknown values, for compatibility with C-based lua only
static java.lang.String[] TYPE_NAMES
          String array constant containing names of each of the lua value types
static LuaString UNM
          LuaString constant with value "__unm" for use as metatag
static LuaNumber ZERO
          LuaValue number constant equal to 0
 
Constructor Summary
LuaValue()
           
 
Method Summary
 LuaValue add(double rhs)
          Add: Perform numeric add operation with another value of double type with metatag processing
 LuaValue add(int rhs)
          Add: Perform numeric add operation with another value of int type with metatag processing
 LuaValue add(LuaValue rhs)
          Add: Perform numeric add operation with another value including metatag processing.
 LuaValue and(LuaValue rhs)
          Perform boolean and with another operand, based on lua rules for boolean evaluation.
 LuaValue arg(int index)
          Get the n-th argument value (1-based).
 LuaValue arg1()
          Get the first argument in the list.
static LuaValue argerror(int iarg, java.lang.String msg)
          Throw a LuaError indicating an invalid argument was supplied to a function
protected  LuaValue argerror(java.lang.String expected)
          Throw a LuaError indicating an invalid argument was supplied to a function
protected  LuaValue aritherror()
          Throw a LuaError based on an arithmetic error such as add, or pow, typically due to an invalid operand type
protected  LuaValue aritherror(java.lang.String fun)
          Throw a LuaError based on an arithmetic error such as add, or pow, typically due to an invalid operand type
protected  LuaValue arithmt(LuaValue tag, LuaValue op2)
          Perform metatag processing for arithmetic operations.
protected  LuaValue arithmtwith(LuaValue tag, double op1)
          Perform metatag processing for arithmetic operations when the left-hand-side is a number.
static void assert_(boolean b, java.lang.String msg)
          Assert a condition is true, or throw a LuaError if not Returns no value when b is true, throws error(String) with msg as argument and does not return if b is false.
 Buffer buffer()
          Convert the value to a Buffer for more efficient concatenation of multiple strings.
 LuaValue call()
          Call this with 0 arguments, including metatag processing, and return only the first return value.
 LuaValue call(LuaValue arg)
          Call this with 1 argument, including metatag processing, and return only the first return value.
 LuaValue call(LuaValue arg1, LuaValue arg2)
          Call this with 2 arguments, including metatag processing, and return only the first return value.
 LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3)
          Call this with 3 arguments, including metatag processing, and return only the first return value.
 LuaValue call(java.lang.String arg)
          Convenience function which calls a luavalue with a single, string argument.
protected  LuaValue callmt()
          Get the metatag value for the CALL metatag, if it exists.
 boolean checkboolean()
          Check that the value is a LuaBoolean, or throw LuaError if not
 LuaClosure checkclosure()
          Check that the value is a LuaClosure , or throw LuaError if not
 double checkdouble()
          Check that the value is numeric and return the value as a double, or throw LuaError if not numeric
 LuaFunction checkfunction()
          Check that the value is a function , or throw LuaError if not
 Globals checkglobals()
          Check that the value is a Globals instance, or throw LuaError if not
 int checkint()
          Check that the value is numeric, and convert and cast value to int, or throw LuaError if not numeric
 LuaInteger checkinteger()
          Check that the value is numeric, and convert and cast value to int, or throw LuaError if not numeric
 java.lang.String checkjstring()
          Convert this value to a Java String.
 long checklong()
          Check that the value is numeric, and convert and cast value to long, or throw LuaError if not numeric
protected  LuaValue checkmetatag(LuaValue tag, java.lang.String reason)
          Get particular metatag, or throw LuaError if it doesn't exist
 LuaValue checknotnil()
          Check that this is not the value NIL, or throw LuaError if it is
 LuaNumber checknumber()
          Check that the value is numeric, and return as a LuaNumber if so, or throw LuaError
 LuaNumber checknumber(java.lang.String msg)
          Check that the value is numeric, and return as a LuaNumber if so, or throw LuaError
 LuaString checkstring()
          Check that this is a lua string, or throw LuaError if it is not.
 LuaTable checktable()
          Check that this is a LuaTable, or throw LuaError if it is not
 LuaThread checkthread()
          Check that this is a LuaThread, or throw LuaError if it is not
 java.lang.Object checkuserdata()
          Check that this is a LuaUserdata, or throw LuaError if it is not
 java.lang.Object checkuserdata(java.lang.Class c)
          Check that this is a LuaUserdata, or throw LuaError if it is not
protected  LuaValue compareerror(LuaValue rhs)
          Throw a LuaError based on a comparison error such as greater-than or less-than, typically due to an invalid operand type
protected  LuaValue compareerror(java.lang.String rhs)
          Throw a LuaError based on a comparison error such as greater-than or less-than, typically due to an invalid operand type
 LuaValue comparemt(LuaValue tag, LuaValue op1)
          Perform metatag processing for comparison operations.
 Buffer concat(Buffer rhs)
          Concatenate a Buffer onto this value and return the result using rules of lua string concatenation including metatag processing.
 LuaValue concat(LuaValue rhs)
          Concatenate another value onto this value and return the result using rules of lua string concatenation including metatag processing.
 LuaValue concatmt(LuaValue rhs)
          Perform metatag processing for concatenation operations.
 LuaValue concatTo(LuaNumber lhs)
          Reverse-concatenation: concatenate this value onto another value known to be a LuaNumber and return the result using rules of lua string concatenation including metatag processing.
 LuaValue concatTo(LuaString lhs)
          Reverse-concatenation: concatenate this value onto another value known to be a LuaString and return the result using rules of lua string concatenation including metatag processing.
 LuaValue concatTo(LuaValue lhs)
          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.
 LuaValue div(double rhs)
          Divide: Perform numeric divide operation by another value of double type without metatag processing
 LuaValue div(int rhs)
          Divide: Perform numeric divide operation by another value of int type without metatag processing
 LuaValue div(LuaValue rhs)
          Divide: Perform numeric divide operation by another value of unknown type, including metatag processing.
 LuaValue divInto(double lhs)
          Reverse-divide: Perform numeric divide operation into another value with metatag processing
 boolean eq_b(LuaValue val)
          Equals: Perform equality comparison with another value including metatag processing using EQ, and return java boolean
 LuaValue eq(LuaValue val)
          Equals: Perform equality comparison with another value including metatag processing using EQ.
static boolean eqmtcall(LuaValue lhs, LuaValue lhsmt, LuaValue rhs, LuaValue rhsmt)
          Perform equality testing metatag processing
 boolean equals(java.lang.Object obj)
           
static LuaValue error(java.lang.String message)
          Throw a LuaError with a particular message
 LuaValue get(int key)
          Get a value in a table including metatag processing using INDEX.
 LuaValue get(LuaValue key)
          Get a value in a table including metatag processing using INDEX.
 LuaValue get(java.lang.String key)
          Get a value in a table including metatag processing using INDEX.
 LuaValue getmetatable()
          Get the metatable for this LuaValue
protected static LuaValue gettable(LuaValue t, LuaValue key)
          get value from metatable operations, or NIL if not defined by metatables
 boolean gt_b(double rhs)
          Greater than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.
 boolean gt_b(int rhs)
          Greater than: Perform numeric comparison with another value of int type, including metatag processing, and returning java boolean.
 boolean gt_b(LuaValue rhs)
          Greater than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.
 LuaValue gt(double rhs)
          Greater than: Perform numeric comparison with another value of double type, including metatag processing, and returning LuaValue.
 LuaValue gt(int rhs)
          Greater than: Perform numeric comparison with another value of int type, including metatag processing, and returning LuaValue.
 LuaValue gt(LuaValue rhs)
          Greater than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning LuaValue.
 boolean gteq_b(double rhs)
          Greater than or equals: Perform numeric comparison with another value of double type, including metatag processing, and returning java boolean.
 boolean gteq_b(int rhs)
          Greater than or equals: Perform numeric comparison with another value of int type, including metatag processing, and returning java boolean.
 boolean gteq_b(LuaValue rhs)
          Greater than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.
 LuaValue gteq(double rhs)
          Greater than or equals: Perform numeric comparison with another value of double type, including metatag processing, and returning LuaValue.
 LuaValue gteq(int rhs)
          Greater than or equals: Perform numeric comparison with another value of int type, including metatag processing, and returning LuaValue.
 LuaValue gteq(LuaValue rhs)
          Greater than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning LuaValue.
protected  LuaValue illegal(java.lang.String op, java.lang.String typename)
          Throw a LuaError indicating an illegal operation occurred, typically involved in managing weak references
 Varargs inext(LuaValue index)
          Find the next integer-key,value pair if this is a table, return NIL if there are no more, or throw a LuaError if not a table.
 void initupvalue1(LuaValue env)
          Hook for implementations such as LuaJC to load the environment of the main chunk into the first upvalue location.
 Varargs invoke()
          Call this with 0 arguments, including metatag processing, and retain all return values in a Varargs.
 Varargs invoke(LuaValue[] args)
          Call this with variable arguments, including metatag processing, and retain all return values in a Varargs.
 Varargs invoke(LuaValue[] args, Varargs varargs)
          Call this with variable arguments, including metatag processing, and retain all return values in a Varargs.
 Varargs invoke(LuaValue arg1, LuaValue arg2, Varargs varargs)
          Call this with variable arguments, including metatag processing, and retain all return values in a Varargs.
 Varargs invoke(LuaValue arg, Varargs varargs)
          Call this with variable arguments, including metatag processing, and retain all return values in a Varargs.
 Varargs invoke(Varargs args)
          Call this with variable arguments, including metatag processing, and retain all return values in a Varargs.
 Varargs invokemethod(LuaValue name)
          Call named method on this with 0 arguments, including metatag processing, and retain all return values in a Varargs.
 Varargs invokemethod(LuaValue name, LuaValue[] args)
          Call named method on this with variable arguments, including metatag processing, and retain all return values in a Varargs.
 Varargs invokemethod(LuaValue name, Varargs args)
          Call named method on this with variable arguments, including metatag processing, and retain all return values in a Varargs.
 Varargs invokemethod(java.lang.String name)
          Call named method on this with 0 arguments, including metatag processing, and retain all return values in a Varargs.
 Varargs invokemethod(java.lang.String name, LuaValue[] args)
          Call named method on this with 1 argument, including metatag processing, and retain all return values in a Varargs.
 Varargs invokemethod(java.lang.String name, Varargs args)
          Call named method on this with 1 argument, including metatag processing, and retain all return values in a Varargs.
 boolean isboolean()
          Check if this is a boolean
 boolean isclosure()
          Check if this is a function that is a closure, meaning interprets lua bytecode for its execution
 boolean isfunction()
          Check if this is a function
 boolean isint()
          Check if this is a number and is representable by java int without rounding or truncation
 boolean isinttype()
          Check if this is a LuaInteger
 boolean islong()
          Check if this is a number and is representable by java long without rounding or truncation
 boolean isnil()
          Check if this is #NIL
 boolean isnumber()
          Check if this is a number
 boolean isstring()
          Check if this is a string
 boolean istable()
          Check if this is a table
 boolean isthread()
          Check if this is a thread
 boolean isuserdata()
          Check if this is a userdata
 boolean isuserdata(java.lang.Class c)
          Check if this is a userdata of type c
 boolean isvalidkey()
          Return true if this is a valid key in a table index operation.
 LuaValue len()
          Length operator: return lua length of object (#this) including metatag processing as java int
protected  LuaValue lenerror()
          Throw a LuaError based on the len operator, typically due to an invalid operand type
 int length()
          Length operator: return lua length of object (#this) including metatag processing as java int
static LuaTable listOf(LuaValue[] unnamedValues)
          Construct a LuaTable initialized with supplied array values.
static LuaTable listOf(LuaValue[] unnamedValues, Varargs lastarg)
          Construct a LuaTable initialized with supplied array values.
 LuaValue load(LuaValue library)
          Load a library instance by calling it with and empty string as the modname, and this Globals as the environment.
 boolean lt_b(double rhs)
          Less than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.
 boolean lt_b(int rhs)
          Less than: Perform numeric comparison with another value of int type, including metatag processing, and returning java boolean.
 boolean lt_b(LuaValue rhs)
          Less than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.
 LuaValue lt(double rhs)
          Less than: Perform numeric comparison with another value of double type, including metatag processing, and returning LuaValue.
 LuaValue lt(int rhs)
          Less than: Perform numeric comparison with another value of int type, including metatag processing, and returning LuaValue.
 LuaValue lt(LuaValue rhs)
          Less than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning LuaValue.
 boolean lteq_b(double rhs)
          Less than or equals: Perform numeric comparison with another value of double type, including metatag processing, and returning java boolean.
 boolean lteq_b(int rhs)
          Less than or equals: Perform numeric comparison with another value of int type, including metatag processing, and returning java boolean.
 boolean lteq_b(LuaValue rhs)
          Less than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.
 LuaValue lteq(double rhs)
          Less than or equals: Perform numeric comparison with another value of double type, including metatag processing, and returning LuaValue.
 LuaValue lteq(int rhs)
          Less than or equals: Perform numeric comparison with another value of int type, including metatag processing, and returning LuaValue.
 LuaValue lteq(LuaValue rhs)
          Less than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning LuaValue.
protected static org.luaj.vm2.Metatable metatableOf(LuaValue mt)
          Construct a Metatable instance from the given LuaValue
 LuaValue metatag(LuaValue tag)
          Get particular metatag, or return NIL if it doesn't exist
 LuaValue method(LuaValue name)
          Call named method on this with 0 arguments, including metatag processing, and return only the first return value.
 LuaValue method(LuaValue name, LuaValue arg)
          Call named method on this with 1 argument, including metatag processing, and return only the first return value.
 LuaValue method(LuaValue name, LuaValue arg1, LuaValue arg2)
          Call named method on this with 2 arguments, including metatag processing, and return only the first return value.
 LuaValue method(java.lang.String name)
          Call named method on this with 0 arguments, including metatag processing, and return only the first return value.
 LuaValue method(java.lang.String name, LuaValue arg)
          Call named method on this with 1 argument, including metatag processing, and return only the first return value.
 LuaValue method(java.lang.String name, LuaValue arg1, LuaValue arg2)
          Call named method on this with 2 arguments, including metatag processing, and return only the first return value.
 LuaValue mod(double rhs)
          Modulo: Perform numeric modulo operation with another value of double type without metatag processing
 LuaValue mod(int rhs)
          Modulo: Perform numeric modulo operation with another value of int type without metatag processing
 LuaValue mod(LuaValue rhs)
          Modulo: Perform numeric modulo operation with another value of unknown type, including metatag processing.
 LuaValue modFrom(double lhs)
          Reverse-modulo: Perform numeric modulo operation from another value with metatag processing
 LuaValue mul(double rhs)
          Multiply: Perform numeric multiply operation with another value of double type with metatag processing
 LuaValue mul(int rhs)
          Multiply: Perform numeric multiply operation with another value of int type with metatag processing
 LuaValue mul(LuaValue rhs)
          Multiply: Perform numeric multiply operation with another value of unknown type, including metatag processing.
 int narg()
          Get the number of arguments, or 0 if there are none.
 LuaValue neg()
          Unary minus: return negative value (-this) as defined by lua unary minus operator
 boolean neq_b(LuaValue val)
          Notquals: Perform inequality comparison with another value including metatag processing using EQ.
 LuaValue neq(LuaValue val)
          Notquals: Perform inequality comparison with another value including metatag processing using EQ.
 Varargs next(LuaValue index)
          Find the next key,value pair if this is a table, return NIL if there are no more, or throw a LuaError if not a table.
 LuaValue not()
          Unary not: return inverse boolean value (~this) as defined by lua not operator
 Varargs onInvoke(Varargs args)
          Callback used during tail call processing to invoke the function once.
 boolean optboolean(boolean defval)
          Check that optional argument is a boolean and return its boolean value
 LuaClosure optclosure(LuaClosure defval)
          Check that optional argument is a closure and return as LuaClosure
 double optdouble(double defval)
          Check that optional argument is a number or string convertible to number and return as double
 LuaFunction optfunction(LuaFunction defval)
          Check that optional argument is a function and return as LuaFunction
 int optint(int defval)
          Check that optional argument is a number or string convertible to number and return as int
 LuaInteger optinteger(LuaInteger defval)
          Check that optional argument is a number or string convertible to number and return as LuaInteger
 java.lang.String optjstring(java.lang.String defval)
          Check that optional argument is a string or number and return as Java String
 long optlong(long defval)
          Check that optional argument is a number or string convertible to number and return as long
 LuaNumber optnumber(LuaNumber defval)
          Check that optional argument is a number or string convertible to number and return as LuaNumber
 LuaString optstring(LuaString defval)
          Check that optional argument is a string or number and return as LuaString
 LuaTable opttable(LuaTable defval)
          Check that optional argument is a table and return as LuaTable
 LuaThread optthread(LuaThread defval)
          Check that optional argument is a thread and return as LuaThread
 java.lang.Object optuserdata(java.lang.Class c, java.lang.Object defval)
          Check that optional argument is a userdata whose instance is of a type and return the Object instance
 java.lang.Object optuserdata(java.lang.Object defval)
          Check that optional argument is a userdata and return the Object instance
 LuaValue optvalue(LuaValue defval)
          Perform argument check that this is not nil or none.
 LuaValue or(LuaValue rhs)
          Perform boolean or with another operand, based on lua rules for boolean evaluation.
 LuaValue pow(double rhs)
          Raise to power: Raise this value to a power of double type with metatag processing
 LuaValue pow(int rhs)
          Raise to power: Raise this value to a power of int type with metatag processing
 LuaValue pow(LuaValue rhs)
          Raise to power: Raise this value to a power including metatag processing.
 LuaValue powWith(double lhs)
          Reverse-raise to power: Raise another value of double type to this power with metatag processing
 LuaValue powWith(int lhs)
          Reverse-raise to power: Raise another value of double type to this power with metatag processing
 void presize(int i)
          Preallocate the array part of a table to be a certain size,
 boolean raweq(double val)
          Equals: Perform direct equality comparison with a double value without metatag processing.
 boolean raweq(int val)
          Equals: Perform direct equality comparison with a int value without metatag processing.
 boolean raweq(LuaString val)
          Equals: Perform direct equality comparison with a LuaString value without metatag processing.
 boolean raweq(LuaUserdata val)
          Equals: Perform direct equality comparison with a LuaUserdata value without metatag processing.
 boolean raweq(LuaValue val)
          Equals: Perform direct equality comparison with another value without metatag processing.
 LuaValue rawget(int key)
          Get a value in a table without metatag processing.
 LuaValue rawget(LuaValue key)
          Get a value in a table without metatag processing.
 LuaValue rawget(java.lang.String key)
          Get a value in a table without metatag processing.
 int rawlen()
          Get raw length of table or string without metatag processing.
 void rawset(int key, LuaValue value)
          Set a value in a table without metatag processing.
 void rawset(int key, java.lang.String value)
          Set a value in a table without metatag processing.
 void rawset(LuaValue key, LuaValue value)
          Set a value in a table without metatag processing.
 void rawset(java.lang.String key, double value)
          Set a value in a table without metatag processing.
 void rawset(java.lang.String key, int value)
          Set a value in a table without metatag processing.
 void rawset(java.lang.String key, LuaValue value)
          Set a value in a table without metatag processing.
 void rawset(java.lang.String key, java.lang.String value)
          Set a value in a table without metatag processing.
 void rawsetlist(int key0, Varargs values)
          Set list values in a table without invoking metatag processing
 void set(int key, LuaValue value)
          Set a value in a table without metatag processing using NEWINDEX.
 void set(int key, java.lang.String value)
          Set a value in a table without metatag processing using NEWINDEX.
 void set(LuaValue key, LuaValue value)
          Set a value in a table without metatag processing using NEWINDEX.
 void set(java.lang.String key, double value)
          Set a value in a table without metatag processing using NEWINDEX.
 void set(java.lang.String key, int value)
          Set a value in a table without metatag processing using NEWINDEX.
 void set(java.lang.String key, LuaValue value)
          Set a value in a table without metatag processing using NEWINDEX.
 void set(java.lang.String key, java.lang.String value)
          Set a value in a table without metatag processing using NEWINDEX.
 LuaValue setmetatable(LuaValue metatable)
          Set the metatable for this LuaValue
protected static boolean settable(LuaValue t, LuaValue key, LuaValue value)
          Perform field assignment including metatag processing.
 int strcmp(LuaString rhs)
          Perform string comparison with another value known to be a LuaString using string comparison based on byte values.
 int strcmp(LuaValue rhs)
          Perform string comparison with another value of any type using string comparison based on byte values.
 LuaValue strongvalue()
          Return this value as a strong reference, or null if it was weak and is no longer referenced.
 LuaString strvalue()
          Convert this value to a string if it is a LuaString or LuaNumber, or throw a LuaError if it is not
 LuaValue sub(double rhs)
          Subtract: Perform numeric subtract operation with another value of double type with metatag processing
 LuaValue sub(int rhs)
          Subtract: Perform numeric subtract operation with another value of int type with metatag processing
 LuaValue sub(LuaValue rhs)
          Subtract: Perform numeric subtract operation with another value of unknown type, including metatag processing.
 Varargs subargs(int start)
          Create a Varargs instance containing arguments starting at index start
 LuaValue subFrom(double lhs)
          Reverse-subtract: Perform numeric subtract operation from an int value with metatag processing
 LuaValue subFrom(int lhs)
          Reverse-subtract: Perform numeric subtract operation from a double value without metatag processing
static LuaTable tableOf()
          Construct an empty LuaTable.
static LuaTable tableOf(int narray, int nhash)
          Construct an empty LuaTable preallocated to hold array and hashed elements
static LuaTable tableOf(LuaValue[] namedValues)
          Construct a LuaTable initialized with supplied named values.
static LuaTable tableOf(LuaValue[] namedValues, LuaValue[] unnamedValues)
          Construct a LuaTable initialized with supplied named values and sequential elements.
static LuaTable tableOf(LuaValue[] namedValues, LuaValue[] unnamedValues, Varargs lastarg)
          Construct a LuaTable initialized with supplied named values and sequential elements in an array part and as varargs.
static LuaTable tableOf(Varargs varargs, int firstarg)
          Construct a LuaTable initialized with supplied array values.
static Varargs tailcallOf(LuaValue func, Varargs args)
          Construct a TailcallVarargs around a function and arguments.
 boolean testfor_b(LuaValue limit, LuaValue step)
          Perform end-condition test in for-loop processing.
 boolean toboolean()
          Convert to boolean false if NIL or FALSE, true if anything else
 byte tobyte()
          Convert to byte if numeric, or 0 if not.
 char tochar()
          Convert to char if numeric, or 0 if not.
 double todouble()
          Convert to double if numeric, or 0 if not.
 float tofloat()
          Convert to float if numeric, or 0 if not.
 int toint()
          Convert to int if numeric, or 0 if not.
 java.lang.String tojstring()
          Convert to human readable String for any type.
 long tolong()
          Convert to long if numeric, or 0 if not.
 LuaValue tonumber()
          Conditionally convert to lua number without throwing errors.
 short toshort()
          Convert to short if numeric, or 0 if not.
 LuaValue tostring()
          Conditionally convert to lua string without throwing errors.
 java.lang.String toString()
          Convert the value to a human readable string using tojstring()
 java.lang.Object touserdata()
          Convert to userdata instance, or null.
 java.lang.Object touserdata(java.lang.Class c)
          Convert to userdata instance if specific type, or null.
abstract  int type()
          Get the enumeration value for the type of this value.
abstract  java.lang.String typename()
          Get the String name of the type of this value.
protected  LuaValue typerror(java.lang.String expected)
          Throw a LuaError indicating an invalid type was supplied to a function
protected  LuaValue unimplemented(java.lang.String fun)
          Throw a LuaError indicating an operation is not implemented
static LuaUserdata userdataOf(java.lang.Object o)
          Construct a LuaUserdata for an object.
static LuaUserdata userdataOf(java.lang.Object o, LuaValue metatable)
          Construct a LuaUserdata for an object with a user supplied metatable.
static LuaBoolean valueOf(boolean b)
          Convert java boolean to a LuaValue.
static LuaString valueOf(byte[] bytes)
          Convert bytes in an array to a LuaValue.
static LuaString valueOf(byte[] bytes, int off, int len)
          Convert bytes in an array to a LuaValue.
static LuaNumber valueOf(double d)
          Convert java double to a LuaValue.
static LuaInteger valueOf(int i)
          Convert java int to a LuaValue.
static LuaString valueOf(java.lang.String s)
          Convert java string to a LuaValue.
static Varargs varargsOf(LuaValue[] v)
          Construct a Varargs around an array of LuaValues.
static Varargs varargsOf(LuaValue[] v, int offset, int length)
          Construct a Varargs around an array of LuaValues.
static Varargs varargsOf(LuaValue[] v, int offset, int length, Varargs more)
          Construct a Varargs around an array of LuaValues.
static Varargs varargsOf(LuaValue[] v, Varargs r)
          Construct a Varargs around an array of LuaValues.
static Varargs varargsOf(LuaValue v1, LuaValue v2, Varargs v3)
          Construct a Varargs around a set of 3 or more LuaValues.
static Varargs varargsOf(LuaValue v, Varargs r)
          Construct a Varargs around a set of 2 or more LuaValues.
 
Methods inherited from class org.luaj.vm2.Varargs
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TINT

public static final int TINT
Type enumeration constant for lua numbers that are ints, for compatibility with lua 5.1 number patch only

See Also:
Constant Field Values

TNONE

public static final int TNONE
Type enumeration constant for lua values that have no type, for example weak table entries

See Also:
Constant Field Values

TNIL

public static final int TNIL
Type enumeration constant for lua nil

See Also:
Constant Field Values

TBOOLEAN

public static final int TBOOLEAN
Type enumeration constant for lua booleans

See Also:
Constant Field Values

TLIGHTUSERDATA

public static final int TLIGHTUSERDATA
Type enumeration constant for lua light userdata, for compatibility with C-based lua only

See Also:
Constant Field Values

TNUMBER

public static final int TNUMBER
Type enumeration constant for lua numbers

See Also:
Constant Field Values

TSTRING

public static final int TSTRING
Type enumeration constant for lua strings

See Also:
Constant Field Values

TTABLE

public static final int TTABLE
Type enumeration constant for lua tables

See Also:
Constant Field Values

TFUNCTION

public static final int TFUNCTION
Type enumeration constant for lua functions

See Also:
Constant Field Values

TUSERDATA

public static final int TUSERDATA
Type enumeration constant for lua userdatas

See Also:
Constant Field Values

TTHREAD

public static final int TTHREAD
Type enumeration constant for lua threads

See Also:
Constant Field Values

TVALUE

public static final int TVALUE
Type enumeration constant for unknown values, for compatibility with C-based lua only

See Also:
Constant Field Values

TYPE_NAMES

public static final java.lang.String[] TYPE_NAMES
String array constant containing names of each of the lua value types

See Also:
type(), typename()

NIL

public static final LuaValue NIL
LuaValue constant corresponding to lua #NIL


TRUE

public static final LuaBoolean TRUE
LuaBoolean constant corresponding to lua true


FALSE

public static final LuaBoolean FALSE
LuaBoolean constant corresponding to lua false


NONE

public static final LuaValue NONE
LuaValue constant corresponding to a Varargs list of no values


ZERO

public static final LuaNumber ZERO
LuaValue number constant equal to 0


ONE

public static final LuaNumber ONE
LuaValue number constant equal to 1


MINUSONE

public static final LuaNumber MINUSONE
LuaValue number constant equal to -1


NOVALS

public static final LuaValue[] NOVALS
LuaValue array constant with no values


ENV

public static LuaString ENV
The variable name of the environment.


INDEX

public static final LuaString INDEX
LuaString constant with value "__index" for use as metatag


NEWINDEX

public static final LuaString NEWINDEX
LuaString constant with value "__newindex" for use as metatag


CALL

public static final LuaString CALL
LuaString constant with value "__call" for use as metatag


MODE

public static final LuaString MODE
LuaString constant with value "__mode" for use as metatag


METATABLE

public static final LuaString METATABLE
LuaString constant with value "__metatable" for use as metatag


ADD

public static final LuaString ADD
LuaString constant with value "__add" for use as metatag


SUB

public static final LuaString SUB
LuaString constant with value "__sub" for use as metatag


DIV

public static final LuaString DIV
LuaString constant with value "__div" for use as metatag


MUL

public static final LuaString MUL
LuaString constant with value "__mul" for use as metatag


POW

public static final LuaString POW
LuaString constant with value "__pow" for use as metatag


MOD

public static final LuaString MOD
LuaString constant with value "__mod" for use as metatag


UNM

public static final LuaString UNM
LuaString constant with value "__unm" for use as metatag


LEN

public static final LuaString LEN
LuaString constant with value "__len" for use as metatag


EQ

public static final LuaString EQ
LuaString constant with value "__eq" for use as metatag


LT

public static final LuaString LT
LuaString constant with value "__lt" for use as metatag


LE

public static final LuaString LE
LuaString constant with value "__le" for use as metatag


TOSTRING

public static final LuaString TOSTRING
LuaString constant with value "__tostring" for use as metatag


CONCAT

public static final LuaString CONCAT
LuaString constant with value "__concat" for use as metatag


EMPTYSTRING

public static final LuaString EMPTYSTRING
LuaString constant with value ""


NILS

public static final LuaValue[] NILS
Array of NIL values to optimize filling stacks using System.arraycopy(). Must not be modified.

Constructor Detail

LuaValue

public LuaValue()
Method Detail

type

public abstract int type()
Get the enumeration value for the type of this value.

Returns:
value for this type, one of TNIL, TBOOLEAN, TNUMBER, TSTRING, TTABLE, TFUNCTION, TUSERDATA, TTHREAD
See Also:
typename()

typename

public abstract java.lang.String typename()
Get the String name of the type of this value.

Returns:
name from type name list TYPE_NAMES corresponding to the type of this value: "nil", "boolean", "number", "string", "table", "function", "userdata", "thread"
See Also:
type()

isboolean

public boolean isboolean()
Check if this is a boolean

Returns:
true if this is a boolean, otherwise false
See Also:
isboolean(), toboolean(), checkboolean(), optboolean(boolean), TBOOLEAN

isclosure

public boolean isclosure()
Check if this is a function that is a closure, meaning interprets lua bytecode for its execution

Returns:
true if this is a closure, otherwise false
See Also:
isfunction(), checkclosure(), optclosure(LuaClosure), TFUNCTION

isfunction

public boolean isfunction()
Check if this is a function

Returns:
true if this is a function, otherwise false
See Also:
isclosure(), checkfunction(), optfunction(LuaFunction), TFUNCTION

isint

public boolean isint()
Check if this is a number and is representable by java int without rounding or truncation

Returns:
true if this is a number meaning derives from LuaNumber or derives from LuaString and is convertible to a number, and can be represented by int, otherwise false
See Also:
isinttype(), islong(), tonumber(), checkint(), optint(int), TNUMBER

isinttype

public boolean isinttype()
Check if this is a LuaInteger

No attempt to convert from string will be made by this call.

Returns:
true if this is a LuaInteger, otherwise false
See Also:
isint(), isnumber(), tonumber(), TNUMBER

islong

public boolean islong()
Check if this is a number and is representable by java long without rounding or truncation

Returns:
true if this is a number meaning derives from LuaNumber or derives from LuaString and is convertible to a number, and can be represented by long, otherwise false
See Also:
tonumber(), checklong(), optlong(long), TNUMBER

isnil

public boolean isnil()
Check if this is #NIL

Returns:
true if this is #NIL, otherwise false
See Also:
NIL, NONE, checknotnil(), optvalue(LuaValue), Varargs.isnoneornil(int), TNIL, TNONE

isnumber

public boolean isnumber()
Check if this is a number

Returns:
true if this is a number, meaning derives from LuaNumber or derives from LuaString and is convertible to a number, otherwise false
See Also:
tonumber(), checknumber(), optnumber(LuaNumber), TNUMBER

isstring

public boolean isstring()
Check if this is a string

Returns:
true if this is a string, meaning derives from LuaString or LuaNumber, otherwise false
See Also:
tostring(), checkstring(), optstring(LuaString), TSTRING

isthread

public boolean isthread()
Check if this is a thread

Returns:
true if this is a thread, otherwise false
See Also:
checkthread(), optthread(LuaThread), TTHREAD

istable

public boolean istable()
Check if this is a table

Returns:
true if this is a table, otherwise false
See Also:
checktable(), opttable(LuaTable), TTABLE

isuserdata

public boolean isuserdata()
Check if this is a userdata

Returns:
true if this is a userdata, otherwise false
See Also:
isuserdata(Class), touserdata(), checkuserdata(), optuserdata(Object), TUSERDATA

isuserdata

public boolean isuserdata(java.lang.Class c)
Check if this is a userdata of type c

Parameters:
c - Class to test instance against
Returns:
true if this is a userdata and the instance is assignable to c, otherwise false
See Also:
isuserdata(), touserdata(Class), checkuserdata(Class), optuserdata(Class, Object), TUSERDATA

toboolean

public boolean toboolean()
Convert to boolean false if NIL or FALSE, true if anything else

Returns:
Value cast to byte if number or string convertible to number, otherwise 0
See Also:
optboolean(boolean), checkboolean(), isboolean(), TBOOLEAN

tobyte

public byte tobyte()
Convert to byte if numeric, or 0 if not.

Returns:
Value cast to byte if number or string convertible to number, otherwise 0
See Also:
toint(), todouble(), checknumber(), isnumber(), TNUMBER

tochar

public char tochar()
Convert to char if numeric, or 0 if not.

Returns:
Value cast to char if number or string convertible to number, otherwise 0
See Also:
toint(), todouble(), checknumber(), isnumber(), TNUMBER

todouble

public double todouble()
Convert to double if numeric, or 0 if not.

Returns:
Value cast to double if number or string convertible to number, otherwise 0
See Also:
toint(), tobyte(), tochar(), toshort(), tolong(), tofloat(), optdouble(double), checknumber(), isnumber(), TNUMBER

tofloat

public float tofloat()
Convert to float if numeric, or 0 if not.

Returns:
Value cast to float if number or string convertible to number, otherwise 0
See Also:
toint(), todouble(), checknumber(), isnumber(), TNUMBER

toint

public int toint()
Convert to int if numeric, or 0 if not.

Returns:
Value cast to int if number or string convertible to number, otherwise 0
See Also:
tobyte(), tochar(), toshort(), tolong(), tofloat(), todouble(), optint(int), checknumber(), isnumber(), TNUMBER

tolong

public long tolong()
Convert to long if numeric, or 0 if not.

Returns:
Value cast to long if number or string convertible to number, otherwise 0
See Also:
isint(), isinttype(), toint(), todouble(), optlong(long), checknumber(), isnumber(), TNUMBER

toshort

public short toshort()
Convert to short if numeric, or 0 if not.

Returns:
Value cast to short if number or string convertible to number, otherwise 0
See Also:
toint(), todouble(), checknumber(), isnumber(), TNUMBER

tojstring

public java.lang.String tojstring()
Convert to human readable String for any type.

Overrides:
tojstring in class Varargs
Returns:
String for use by human readers based on type.
See Also:
tostring(), optjstring(String), checkjstring(), isstring(), TSTRING

touserdata

public java.lang.Object touserdata()
Convert to userdata instance, or null.

Returns:
userdata instance if userdata, or null if not LuaUserdata
See Also:
optuserdata(Object), checkuserdata(), isuserdata(), TUSERDATA

touserdata

public java.lang.Object touserdata(java.lang.Class c)
Convert to userdata instance if specific type, or null.

Returns:
userdata instance if is a userdata whose instance derives from c, or null if not LuaUserdata
See Also:
optuserdata(Class,Object), checkuserdata(Class), isuserdata(Class), TUSERDATA

toString

public java.lang.String toString()
Convert the value to a human readable string using tojstring()

Overrides:
toString in class Varargs
Returns:
String value intended to be human readible.
See Also:
tostring(), tojstring(), optstring(LuaString), checkstring(), toString()

tonumber

public LuaValue tonumber()
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 LuaValue this if it is a number or a string convertible to a number, and 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.

Returns:
this if it is a LuaNumber or LuaString that can be converted to a number, otherwise NIL
See Also:
tostring(), optnumber(LuaNumber), checknumber(), toint(), todouble()

tostring

public LuaValue tostring()
Conditionally convert to lua string without throwing errors.

In lua all numbers are strings, so this function will return the LuaValue this if it is a string or number, and NIL for all other cases.

This allows values to be tested for their "string-ness" without the penalty of throwing exceptions.

Returns:
this if it is a LuaString or LuaNumber, otherwise NIL
See Also:
tonumber(), tojstring(), optstring(LuaString), checkstring(), toString()

optboolean

public boolean optboolean(boolean defval)
Check that optional argument is a boolean and return its boolean value

Parameters:
defval - boolean value to return if this is nil or none
Returns:
this cast to boolean if a LuaBoolean, defval if nil or none, throws LuaError otherwise
Throws:
LuaError - if was not a boolean or nil or none.
See Also:
checkboolean(), isboolean(), TBOOLEAN

optclosure

public LuaClosure optclosure(LuaClosure defval)
Check that optional argument is a closure and return as LuaClosure

A LuaClosure is a LuaFunction that executes lua byteccode.

Parameters:
defval - LuaClosure to return if this is nil or none
Returns:
this cast to LuaClosure if a function, defval if nil or none, throws LuaError otherwise
Throws:
LuaError - if was not a closure or nil or none.
See Also:
checkclosure(), isclosure(), TFUNCTION

optdouble

public double optdouble(double defval)
Check that optional argument is a number or string convertible to number and return as double

Parameters:
defval - double to return if this is nil or none
Returns:
this cast to double if numeric, defval if nil or none, throws LuaError otherwise
Throws:
LuaError - if was not numeric or nil or none.
See Also:
optint(int), optinteger(LuaInteger), checkdouble(), todouble(), tonumber(), isnumber(), TNUMBER

optfunction

public LuaFunction optfunction(LuaFunction defval)
Check that optional argument is a function and return as LuaFunction

A LuaFunction may either be a Java function that implements functionality directly in Java, or a LuaClosure which is a LuaFunction that executes lua bytecode.

Parameters:
defval - LuaFunction to return if this is nil or none
Returns:
this cast to LuaFunction if a function, defval if nil or none, throws LuaError otherwise
Throws:
LuaError - if was not a function or nil or none.
See Also:
checkfunction(), isfunction(), TFUNCTION

optint

public int optint(int defval)
Check that optional argument is a number or string convertible to number and return as int

Parameters:
defval - int to return if this is nil or none
Returns:
this cast to int if numeric, defval if nil or none, throws LuaError otherwise
Throws:
LuaError - if was not numeric or nil or none.
See Also:
optdouble(double), optlong(long), optinteger(LuaInteger), checkint(), toint(), tonumber(), isnumber(), TNUMBER

optinteger

public LuaInteger optinteger(LuaInteger defval)
Check that optional argument is a number or string convertible to number and return as LuaInteger

Parameters:
defval - LuaInteger to return if this is nil or none
Returns:
this converted and wrapped in LuaInteger if numeric, defval if nil or none, throws LuaError otherwise
Throws:
LuaError - if was not numeric or nil or none.
See Also:
optdouble(double), optint(int), checkint(), toint(), tonumber(), isnumber(), TNUMBER

optlong

public long optlong(long defval)
Check that optional argument is a number or string convertible to number and return as long

Parameters:
defval - long to return if this is nil or none
Returns:
this cast to long if numeric, defval if nil or none, throws LuaError otherwise
Throws:
LuaError - if was not numeric or nil or none.
See Also:
optdouble(double), optint(int), checkint(), toint(), tonumber(), isnumber(), TNUMBER

optnumber

public LuaNumber optnumber(LuaNumber defval)
Check that optional argument is a number or string convertible to number and return as LuaNumber

Parameters:
defval - LuaNumber to return if this is nil or none
Returns:
this cast to LuaNumber if numeric, defval if nil or none, throws LuaError otherwise
Throws:
LuaError - if was not numeric or nil or none.
See Also:
optdouble(double), optlong(long), optint(int), checkint(), toint(), tonumber(), isnumber(), TNUMBER

optjstring

public java.lang.String optjstring(java.lang.String defval)
Check that optional argument is a string or number and return as Java String

Parameters:
defval - LuaString to return if this is nil or none
Returns:
this converted to String if a string or number, defval if nil or none, throws LuaError if some other type
Throws:
LuaError - if was not a string or number or nil or none.
See Also:
tojstring(), optstring(LuaString), checkjstring(), toString(), TSTRING

optstring

public LuaString optstring(LuaString defval)
Check that optional argument is a string or number and return as LuaString

Parameters:
defval - LuaString to return if this is nil or none
Returns:
this converted to LuaString if a string or number, defval if nil or none, throws LuaError if some other type
Throws:
LuaError - if was not a string or number or nil or none.
See Also:
tojstring(), optjstring(String), checkstring(), toString(), TSTRING

opttable

public LuaTable opttable(LuaTable defval)
Check that optional argument is a table and return as LuaTable

Parameters:
defval - LuaTable to return if this is nil or none
Returns:
this cast to LuaTable if a table, defval if nil or none, throws LuaError if some other type
Throws:
LuaError - if was not a table or nil or none.
See Also:
checktable(), istable(), TTABLE

optthread

public LuaThread optthread(LuaThread defval)
Check that optional argument is a thread and return as LuaThread

Parameters:
defval - LuaThread to return if this is nil or none
Returns:
this cast to LuaTable if a thread, defval if nil or none, throws LuaError if some other type
Throws:
LuaError - if was not a thread or nil or none.
See Also:
checkthread(), isthread(), TTHREAD

optuserdata

public java.lang.Object optuserdata(java.lang.Object defval)
Check that optional argument is a userdata and return the Object instance

Parameters:
defval - Object to return if this is nil or none
Returns:
Object instance of the userdata if a LuaUserdata, defval if nil or none, throws LuaError if some other type
Throws:
LuaError - if was not a userdata or nil or none.
See Also:
checkuserdata(), isuserdata(), optuserdata(Class, Object), TUSERDATA

optuserdata

public java.lang.Object optuserdata(java.lang.Class c,
                                    java.lang.Object defval)
Check that optional argument is a userdata whose instance is of a type and return the Object instance

Parameters:
c - Class to test userdata instance against
defval - Object to return if this is nil or none
Returns:
Object instance of the userdata if a LuaUserdata and instance is assignable to c, defval if nil or none, throws LuaError if some other type
Throws:
LuaError - if was not a userdata whose instance is assignable to c or nil or none.
See Also:
checkuserdata(Class), isuserdata(Class), optuserdata(Object), TUSERDATA

optvalue

public LuaValue optvalue(LuaValue defval)
Perform argument check that this is not nil or none.

Parameters:
defval - LuaValue to return if this is nil or none
Returns:
this if not nil or none, else defval
See Also:
NIL, NONE, isnil(), Varargs.isnoneornil(int), TNIL, TNONE

checkboolean

public boolean checkboolean()
Check that the value is a LuaBoolean, or throw LuaError if not

Returns:
boolean value for this if it is a LuaBoolean
Throws:
LuaError - if not a LuaBoolean
See Also:
optboolean(boolean), TBOOLEAN

checkclosure

public LuaClosure checkclosure()
Check that the value is a LuaClosure , or throw LuaError if not

LuaClosure is a subclass of LuaFunction that interprets lua bytecode.

Returns:
this cast as LuaClosure
Throws:
LuaError - if not a LuaClosure
See Also:
checkfunction(), optclosure(LuaClosure), isclosure(), TFUNCTION

checkdouble

public double checkdouble()
Check that the value is numeric and return the value as a double, or throw LuaError if not numeric

Values that are LuaNumber and values that are LuaString that can be converted to a number will be converted to double.

Returns:
value cast to a double if numeric
Throws:
LuaError - if not a LuaNumber or is a LuaString that can't be converted to number
See Also:
checkint(), checkinteger(), checklong(), optdouble(double), TNUMBER

checkfunction

public LuaFunction checkfunction()
Check that the value is a function , or throw LuaError if not

A LuaFunction may either be a Java function that implements functionality directly in Java, or a LuaClosure which is a LuaFunction that executes lua bytecode.

Returns:
this if it is a lua function or closure
Throws:
LuaError - if not a function
See Also:
checkclosure()

checkglobals

public Globals checkglobals()
Check that the value is a Globals instance, or throw LuaError if not

Globals are a special LuaTable that establish the default global environment.

Returns:
this if if an instance fof Globals
Throws:
LuaError - if not a Globals instance.

checkint

public int checkint()
Check that the value is numeric, and convert and cast value to int, or throw LuaError if not numeric

Values that are LuaNumber will be cast to int and may lose precision. Values that are LuaString that can be converted to a number will be converted, then cast to int, so may also lose precision.

Returns:
value cast to a int if numeric
Throws:
LuaError - if not a LuaNumber or is a LuaString that can't be converted to number
See Also:
checkinteger(), checklong(), checkdouble(), optint(int), TNUMBER

checkinteger

public LuaInteger checkinteger()
Check that the value is numeric, and convert and cast value to int, or throw LuaError if not numeric

Values that are LuaNumber will be cast to int and may lose precision. Values that are LuaString that can be converted to a number will be converted, then cast to int, so may also lose precision.

Returns:
value cast to a int and wrapped in LuaInteger if numeric
Throws:
LuaError - if not a LuaNumber or is a LuaString that can't be converted to number
See Also:
checkint(), checklong(), checkdouble(), optinteger(LuaInteger), TNUMBER

checklong

public long checklong()
Check that the value is numeric, and convert and cast value to long, or throw LuaError if not numeric

Values that are LuaNumber will be cast to long and may lose precision. Values that are LuaString that can be converted to a number will be converted, then cast to long, so may also lose precision.

Returns:
value cast to a long if numeric
Throws:
LuaError - if not a LuaNumber or is a LuaString that can't be converted to number
See Also:
checkint(), checkinteger(), checkdouble(), optlong(long), TNUMBER

checknumber

public LuaNumber checknumber()
Check that the value is numeric, and return as a LuaNumber if so, or throw LuaError

Values that are LuaString that can be converted to a number will be converted and returned.

Returns:
value as a LuaNumber if numeric
Throws:
LuaError - if not a LuaNumber or is a LuaString that can't be converted to number
See Also:
checkint(), checkinteger(), checkdouble(), checklong(), optnumber(LuaNumber), TNUMBER

checknumber

public LuaNumber checknumber(java.lang.String msg)
Check that the value is numeric, and return as a LuaNumber if so, or throw LuaError

Values that are LuaString that can be converted to a number will be converted and returned.

Parameters:
msg - String message to supply if conversion fails
Returns:
value as a LuaNumber if numeric
Throws:
LuaError - if not a LuaNumber or is a LuaString that can't be converted to number
See Also:
checkint(), checkinteger(), checkdouble(), checklong(), optnumber(LuaNumber), TNUMBER

checkjstring

public java.lang.String checkjstring()
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.

Returns:
String representation of the value
See Also:
checkstring(), optjstring(String), tojstring(), isstring(), TSTRING

checkstring

public LuaString checkstring()
Check that this is a lua string, or throw LuaError if it is not.

In lua all numbers are strings, so this will succeed for anything that derives from LuaString or LuaNumber. Numbers will be converted to LuaString.

Returns:
LuaString representation of the value if it is a LuaString or LuaNumber
Throws:
LuaError - if this is not a LuaTable
See Also:
checkjstring(), optstring(LuaString), tostring(), isstring(), TSTRING

checktable

public LuaTable checktable()
Check that this is a LuaTable, or throw LuaError if it is not

Returns:
this if it is a LuaTable
Throws:
LuaError - if this is not a LuaTable
See Also:
istable(), opttable(LuaTable), TTABLE

checkthread

public LuaThread checkthread()
Check that this is a LuaThread, or throw LuaError if it is not

Returns:
this if it is a LuaThread
Throws:
LuaError - if this is not a LuaThread
See Also:
isthread(), optthread(LuaThread), TTHREAD

checkuserdata

public java.lang.Object checkuserdata()
Check that this is a LuaUserdata, or throw LuaError if it is not

Returns:
this if it is a LuaUserdata
Throws:
LuaError - if this is not a LuaUserdata
See Also:
isuserdata(), optuserdata(Object), checkuserdata(Class), TUSERDATA

checkuserdata

public java.lang.Object checkuserdata(java.lang.Class c)
Check that this is a LuaUserdata, or throw LuaError if it is not

Returns:
this if it is a LuaUserdata
Throws:
LuaError - if this is not a LuaUserdata
See Also:
isuserdata(Class), optuserdata(Class, Object), checkuserdata(), TUSERDATA

checknotnil

public LuaValue checknotnil()
Check that this is not the value NIL, or throw LuaError if it is

Returns:
this if it is not NIL
Throws:
LuaError - if this is NIL
See Also:
optvalue(LuaValue)

isvalidkey

public boolean isvalidkey()
Return true if this is a valid key in a table index operation.

Returns:
true if valid as a table key, otherwise false
See Also:
isnil(), isinttype()

error

public static LuaValue error(java.lang.String message)
Throw a LuaError with a particular message

Parameters:
message - String providing message details
Throws:
LuaError - in all cases

assert_

public static void assert_(boolean b,
                           java.lang.String msg)
Assert a condition is true, or throw a LuaError if not Returns no value when b is true, throws error(String) with msg as argument and does not return if b is false.

Parameters:
b - condition to test
msg - String message to produce on failure
Throws:
LuaError - if b is not true

argerror

protected LuaValue argerror(java.lang.String expected)
Throw a LuaError indicating an invalid argument was supplied to a function

Parameters:
expected - String naming the type that was expected
Throws:
LuaError - in all cases

argerror

public static LuaValue argerror(int iarg,
                                java.lang.String msg)
Throw a LuaError indicating an invalid argument was supplied to a function

Parameters:
iarg - index of the argument that was invalid, first index is 1
msg - String providing information about the invalid argument
Throws:
LuaError - in all cases

typerror

protected LuaValue typerror(java.lang.String expected)
Throw a LuaError indicating an invalid type was supplied to a function

Parameters:
expected - String naming the type that was expected
Throws:
LuaError - in all cases

unimplemented

protected LuaValue unimplemented(java.lang.String fun)
Throw a LuaError indicating an operation is not implemented

Throws:
LuaError - in all cases

illegal

protected LuaValue illegal(java.lang.String op,
                           java.lang.String typename)
Throw a LuaError indicating an illegal operation occurred, typically involved in managing weak references

Throws:
LuaError - in all cases

lenerror

protected LuaValue lenerror()
Throw a LuaError based on the len operator, typically due to an invalid operand type

Throws:
LuaError - in all cases

aritherror

protected LuaValue aritherror()
Throw a LuaError based on an arithmetic error such as add, or pow, typically due to an invalid operand type

Throws:
LuaError - in all cases

aritherror

protected LuaValue aritherror(java.lang.String fun)
Throw a LuaError based on an arithmetic error such as add, or pow, typically due to an invalid operand type

Parameters:
fun - String description of the function that was attempted
Throws:
LuaError - in all cases

compareerror

protected LuaValue compareerror(java.lang.String rhs)
Throw a LuaError based on a comparison error such as greater-than or less-than, typically due to an invalid operand type

Parameters:
rhs - String description of what was on the right-hand-side of the comparison that resulted in the error.
Throws:
LuaError - in all cases

compareerror

protected LuaValue compareerror(LuaValue rhs)
Throw a LuaError based on a comparison error such as greater-than or less-than, typically due to an invalid operand type

Parameters:
rhs - Right-hand-side of the comparison that resulted in the error.
Throws:
LuaError - in all cases

get

public LuaValue get(LuaValue key)
Get a value in a table including metatag processing using INDEX.

Parameters:
key - the key to look up, must not be NIL or null
Returns:
LuaValue for that key, or NIL if not found and no metatag
Throws:
LuaError - if this is not a table, or there is no INDEX metatag, or key is NIL
See Also:
get(int), get(String), rawget(LuaValue)

get

public LuaValue get(int key)
Get a value in a table including metatag processing using INDEX.

Parameters:
key - the key to look up
Returns:
LuaValue for that key, or NIL if not found
Throws:
LuaError - if this is not a table, or there is no INDEX metatag
See Also:
get(LuaValue), rawget(int)

get

public LuaValue get(java.lang.String key)
Get a value in a table including metatag processing using INDEX.

Parameters:
key - the key to look up, must not be null
Returns:
LuaValue for that key, or NIL if not found
Throws:
LuaError - if this is not a table, or there is no INDEX metatag
See Also:
get(LuaValue), rawget(String)

set

public void set(LuaValue key,
                LuaValue value)
Set a value in a table without metatag processing using NEWINDEX.

Parameters:
key - the key to use, must not be NIL or null
value - the value to use, can be NIL, must not be null
Throws:
LuaError - if this is not a table, or key is NIL, or there is no NEWINDEX metatag

set

public void set(int key,
                LuaValue value)
Set a value in a table without metatag processing using NEWINDEX.

Parameters:
key - the key to use
value - the value to use, can be NIL, must not be null
Throws:
LuaError - if this is not a table, or there is no NEWINDEX metatag

set

public void set(int key,
                java.lang.String value)
Set a value in a table without metatag processing using NEWINDEX.

Parameters:
key - the key to use
value - the value to use, must not be null
Throws:
LuaError - if this is not a table, or there is no NEWINDEX metatag

set

public void set(java.lang.String key,
                LuaValue value)
Set a value in a table without metatag processing using NEWINDEX.

Parameters:
key - the key to use, must not be NIL or null
value - the value to use, can be NIL, must not be null
Throws:
LuaError - if this is not a table, or there is no NEWINDEX metatag

set

public void set(java.lang.String key,
                double value)
Set a value in a table without metatag processing using NEWINDEX.

Parameters:
key - the key to use, must not be null
value - the value to use
Throws:
LuaError - if this is not a table, or there is no NEWINDEX metatag

set

public void set(java.lang.String key,
                int value)
Set a value in a table without metatag processing using NEWINDEX.

Parameters:
key - the key to use, must not be null
value - the value to use
Throws:
LuaError - if this is not a table, or there is no NEWINDEX metatag

set

public void set(java.lang.String key,
                java.lang.String value)
Set a value in a table without metatag processing using NEWINDEX.

Parameters:
key - the key to use, must not be null
value - the value to use, must not be null
Throws:
LuaError - if this is not a table, or there is no NEWINDEX metatag

rawget

public LuaValue rawget(LuaValue key)
Get a value in a table without metatag processing.

Parameters:
key - the key to look up, must not be NIL or null
Returns:
LuaValue for that key, or NIL if not found
Throws:
LuaError - if this is not a table, or key is NIL

rawget

public LuaValue rawget(int key)
Get a value in a table without metatag processing.

Parameters:
key - the key to look up
Returns:
LuaValue for that key, or NIL if not found
Throws:
LuaError - if this is not a table

rawget

public LuaValue rawget(java.lang.String key)
Get a value in a table without metatag processing.

Parameters:
key - the key to look up, must not be null
Returns:
LuaValue for that key, or NIL if not found
Throws:
LuaError - if this is not a table

rawset

public void rawset(LuaValue key,
                   LuaValue value)
Set a value in a table without metatag processing.

Parameters:
key - the key to use, must not be NIL or null
value - the value to use, can be NIL, must not be null
Throws:
LuaError - if this is not a table, or key is NIL

rawset

public void rawset(int key,
                   LuaValue value)
Set a value in a table without metatag processing.

Parameters:
key - the key to use
value - the value to use, can be NIL, must not be null
Throws:
LuaError - if this is not a table

rawset

public void rawset(int key,
                   java.lang.String value)
Set a value in a table without metatag processing.

Parameters:
key - the key to use
value - the value to use, can be NIL, must not be null
Throws:
LuaError - if this is not a table

rawset

public void rawset(java.lang.String key,
                   LuaValue value)
Set a value in a table without metatag processing.

Parameters:
key - the key to use, must not be null
value - the value to use, can be NIL, must not be null
Throws:
LuaError - if this is not a table

rawset

public void rawset(java.lang.String key,
                   double value)
Set a value in a table without metatag processing.

Parameters:
key - the key to use, must not be null
value - the value to use
Throws:
LuaError - if this is not a table

rawset

public void rawset(java.lang.String key,
                   int value)
Set a value in a table without metatag processing.

Parameters:
key - the key to use, must not be null
value - the value to use
Throws:
LuaError - if this is not a table

rawset

public void rawset(java.lang.String key,
                   java.lang.String value)
Set a value in a table without metatag processing.

Parameters:
key - the key to use, must not be null
value - the value to use, must not be null
Throws:
LuaError - if this is not a table

rawsetlist

public void rawsetlist(int key0,
                       Varargs values)
Set list values in a table without invoking metatag processing

Primarily used internally in response to a SETLIST bytecode.

Parameters:
key0 - the first key to set in the table
values - the list of values to set
Throws:
LuaError - if this is not a table.

presize

public void presize(int i)
Preallocate the array part of a table to be a certain size,

Primarily used internally in response to a SETLIST bytecode.

Parameters:
i - the number of array slots to preallocate in the table.
Throws:
LuaError - if this is not a table.

next

public Varargs next(LuaValue index)
Find the next key,value pair if this is a table, return NIL if there are no more, or throw a LuaError if not a table.

To iterate over all key-value pairs in a table you can use

 LuaValue k = LuaValue.NIL;
 while ( true ) {
    Varargs n = table.next(k);
    if ( (k = n.arg1()).isnil() )
       break;
    LuaValue v = n.arg(2)
    process( k, v )
 }

Parameters:
index - LuaInteger value identifying a key to start from, or NIL to start at the beginning
Returns:
Varargs containing {key,value} for the next entry, or NIL if there are no more.
Throws:
LuaError - if this is not a table, or the supplied key is invalid.
See Also:
LuaTable, inext(LuaValue), valueOf(int), Varargs.arg1(), Varargs.arg(int), isnil()

inext

public Varargs inext(LuaValue index)
Find the next integer-key,value pair if this is a table, return NIL if there are no more, or throw a LuaError if not a table.

To iterate over integer keys in a table you can use

 LuaValue k = LuaValue.NIL;
   while ( true ) {
      Varargs n = table.inext(k);
      if ( (k = n.arg1()).isnil() )
         break;
      LuaValue v = n.arg(2)
      process( k, v )
   }
  

Parameters:
index - LuaInteger value identifying a key to start from, or NIL to start at the beginning
Returns:
Varargs containing (key,value) for the next entry, or NONE if there are no more.
Throws:
LuaError - if this is not a table, or the supplied key is invalid.
See Also:
LuaTable, next(LuaValue), valueOf(int), Varargs.arg1(), Varargs.arg(int), isnil()

load

public LuaValue load(LuaValue library)
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.

Parameters:
library - The callable LuaValue to load into this
Returns:
LuaValue returned by the initialization call.

arg

public LuaValue arg(int index)
Description copied from class: Varargs
Get the n-th argument value (1-based).

Specified by:
arg in class Varargs
Parameters:
index - the index of the argument to get, 1 is the first argument
Returns:
Value at position i, or LuaValue.NIL if there is none.
See Also:
Varargs.arg1(), NIL

narg

public int narg()
Description copied from class: Varargs
Get the number of arguments, or 0 if there are none.

Specified by:
narg in class Varargs
Returns:
number of arguments.

arg1

public LuaValue arg1()
Description copied from class: Varargs
Get the first argument in the list.

Specified by:
arg1 in class Varargs
Returns:
LuaValue which is first in the list, or LuaValue.NIL if there are no values.
See Also:
Varargs.arg(int), NIL

getmetatable

public LuaValue getmetatable()
Get the metatable for this LuaValue

For LuaTable and LuaUserdata instances, the metatable returned is this instance metatable. For all other types, the class metatable value will be returned.

Returns:
metatable, or null if it there is none
See Also:
LuaBoolean.s_metatable, LuaNumber.s_metatable, LuaNil.s_metatable, LuaFunction.s_metatable, LuaThread.s_metatable

setmetatable

public LuaValue setmetatable(LuaValue metatable)
Set the metatable for this LuaValue

For LuaTable and LuaUserdata instances, the metatable is per instance. For all other types, there is one metatable per type that can be set directly from java

Parameters:
metatable - LuaValue instance to serve as the metatable, or null to reset it.
Returns:
this to allow chaining of Java function calls
See Also:
LuaBoolean.s_metatable, LuaNumber.s_metatable, LuaNil.s_metatable, LuaFunction.s_metatable, LuaThread.s_metatable

call

public LuaValue call()
Call this with 0 arguments, including metatag processing, and return only the first return value.

If this is a LuaFunction, call it, and return only its first return value, dropping any others. Otherwise, look for the CALL metatag and call that.

If the return value is a Varargs, only the 1st value will be returned. To get multiple values, use invoke() instead.

To call this as a method call, use method(LuaValue) instead.

Returns:
First return value (this()), or NIL if there were none.
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
call(LuaValue), call(LuaValue,LuaValue), call(LuaValue, LuaValue, LuaValue), invoke(), method(String), method(LuaValue)

call

public LuaValue call(LuaValue arg)
Call this with 1 argument, including metatag processing, and return only the first return value.

If this is a LuaFunction, call it, and return only its first return value, dropping any others. Otherwise, look for the CALL metatag and call that.

If the return value is a Varargs, only the 1st value will be returned. To get multiple values, use invoke() instead.

To call this as a method call, use method(LuaValue) instead.

Parameters:
arg - First argument to supply to the called function
Returns:
First return value (this(arg)), or NIL if there were none.
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
call(), call(LuaValue,LuaValue), call(LuaValue, LuaValue, LuaValue), invoke(Varargs), method(String,LuaValue), method(LuaValue,LuaValue)

call

public LuaValue call(java.lang.String arg)
Convenience function which calls a luavalue with a single, string argument.

Parameters:
arg - String argument to the function. This will be converted to a LuaString.
Returns:
return value of the invocation.
See Also:
call(LuaValue)

call

public LuaValue call(LuaValue arg1,
                     LuaValue arg2)
Call this with 2 arguments, including metatag processing, and return only the first return value.

If this is a LuaFunction, call it, and return only its first return value, dropping any others. Otherwise, look for the CALL metatag and call that.

If the return value is a Varargs, only the 1st value will be returned. To get multiple values, use invoke() instead.

To call this as a method call, use method(LuaValue) instead.

Parameters:
arg1 - First argument to supply to the called function
arg2 - Second argument to supply to the called function
Returns:
First return value (this(arg1,arg2)), or NIL if there were none.
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
call(), call(LuaValue), call(LuaValue, LuaValue, LuaValue), invoke(LuaValue, Varargs), method(String,LuaValue,LuaValue), method(LuaValue,LuaValue,LuaValue)

call

public LuaValue call(LuaValue arg1,
                     LuaValue arg2,
                     LuaValue arg3)
Call this with 3 arguments, including metatag processing, and return only the first return value.

If this is a LuaFunction, call it, and return only its first return value, dropping any others. Otherwise, look for the CALL metatag and call that.

If the return value is a Varargs, only the 1st value will be returned. To get multiple values, use invoke() instead.

To call this as a method call, use method(LuaValue) instead.

Parameters:
arg1 - First argument to supply to the called function
arg2 - Second argument to supply to the called function
arg3 - Second argument to supply to the called function
Returns:
First return value (this(arg1,arg2,arg3)), or NIL if there were none.
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
call(), call(LuaValue), call(LuaValue, LuaValue), invoke(LuaValue, LuaValue, Varargs), invokemethod(String,Varargs), invokemethod(LuaValue,Varargs)

method

public LuaValue method(java.lang.String name)
Call named method on this with 0 arguments, including metatag processing, and return only the first return value.

Look up this[name] and if it is a LuaFunction, call it inserting this as an additional first argument. and return only its first return value, dropping any others. Otherwise, look for the CALL metatag and call that.

If the return value is a Varargs, only the 1st value will be returned. To get multiple values, use invoke() instead.

To call this as a plain call, use call() instead.

Parameters:
name - Name of the method to look up for invocation
Returns:
All values returned from this:name() as a Varargs instance
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
call(), invoke(), method(LuaValue), method(String,LuaValue), method(String,LuaValue,LuaValue)

method

public LuaValue method(LuaValue name)
Call named method on this with 0 arguments, including metatag processing, and return only the first return value.

Look up this[name] and if it is a LuaFunction, call it inserting this as an additional first argument, and return only its first return value, dropping any others. Otherwise, look for the CALL metatag and call that.

If the return value is a Varargs, only the 1st value will be returned. To get multiple values, use invoke() instead.

To call this as a plain call, use call() instead.

Parameters:
name - Name of the method to look up for invocation
Returns:
All values returned from this:name() as a Varargs instance
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
call(), invoke(), method(String), method(LuaValue,LuaValue), method(LuaValue,LuaValue,LuaValue)

method

public LuaValue method(java.lang.String name,
                       LuaValue arg)
Call named method on this with 1 argument, including metatag processing, and return only the first return value.

Look up this[name] and if it is a LuaFunction, call it inserting this as an additional first argument, and return only its first return value, dropping any others. Otherwise, look for the CALL metatag and call that.

If the return value is a Varargs, only the 1st value will be returned. To get multiple values, use invoke() instead.

To call this as a plain call, use call(LuaValue) instead.

Parameters:
name - Name of the method to look up for invocation
arg - Argument to supply to the method
Returns:
All values returned from this:name(arg) as a Varargs instance
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
call(LuaValue), invoke(Varargs), method(String), method(LuaValue), method(String,LuaValue,LuaValue)

method

public LuaValue method(LuaValue name,
                       LuaValue arg)
Call named method on this with 1 argument, including metatag processing, and return only the first return value.

Look up this[name] and if it is a LuaFunction, call it inserting this as an additional first argument, and return only its first return value, dropping any others. Otherwise, look for the CALL metatag and call that.

If the return value is a Varargs, only the 1st value will be returned. To get multiple values, use invoke() instead.

To call this as a plain call, use call(LuaValue) instead.

Parameters:
name - Name of the method to look up for invocation
arg - Argument to supply to the method
Returns:
All values returned from this:name(arg) as a Varargs instance
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
call(LuaValue), invoke(Varargs), method(String,LuaValue), method(LuaValue), method(LuaValue,LuaValue,LuaValue)

method

public LuaValue method(java.lang.String name,
                       LuaValue arg1,
                       LuaValue arg2)
Call named method on this with 2 arguments, including metatag processing, and return only the first return value.

Look up this[name] and if it is a LuaFunction, call it inserting this as an additional first argument, and return only its first return value, dropping any others. Otherwise, look for the CALL metatag and call that.

If the return value is a Varargs, only the 1st value will be returned. To get multiple values, use invoke() instead.

To call this as a plain call, use call(LuaValue,LuaValue) instead.

Parameters:
name - Name of the method to look up for invocation
arg1 - First argument to supply to the method
arg2 - Second argument to supply to the method
Returns:
All values returned from this:name(arg1,arg2) as a Varargs instance
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
call(LuaValue,LuaValue), invoke(LuaValue,Varargs), method(String,LuaValue), method(LuaValue,LuaValue,LuaValue)

method

public LuaValue method(LuaValue name,
                       LuaValue arg1,
                       LuaValue arg2)
Call named method on this with 2 arguments, including metatag processing, and return only the first return value.

Look up this[name] and if it is a LuaFunction, call it inserting this as an additional first argument, and return only its first return value, dropping any others. Otherwise, look for the CALL metatag and call that.

If the return value is a Varargs, only the 1st value will be returned. To get multiple values, use invoke() instead.

To call this as a plain call, use call(LuaValue,LuaValue) instead.

Parameters:
name - Name of the method to look up for invocation
arg1 - First argument to supply to the method
arg2 - Second argument to supply to the method
Returns:
All values returned from this:name(arg1,arg2) as a Varargs instance
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
call(LuaValue,LuaValue), invoke(LuaValue,Varargs), method(LuaValue,LuaValue), method(String,LuaValue,LuaValue)

invoke

public Varargs invoke()
Call this with 0 arguments, including metatag processing, and retain all return values in a Varargs.

If this is a LuaFunction, call it, and return all values. Otherwise, look for the CALL metatag and call that.

To get a particular return value, us Varargs.arg(int)

To call this as a method call, use invokemethod(LuaValue) instead.

Returns:
All return values as a Varargs instance.
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
call(), invoke(Varargs), invokemethod(String), invokemethod(LuaValue)

invoke

public Varargs invoke(Varargs args)
Call this with variable arguments, including metatag processing, and retain all return values in a Varargs.

If this is a LuaFunction, call it, and return all values. Otherwise, look for the CALL metatag and call that.

To get a particular return value, us Varargs.arg(int)

To call this as a method call, use invokemethod(LuaValue) instead.

Parameters:
args - Varargs containing the arguments to supply to the called function
Returns:
All return values as a Varargs instance.
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
varargsOf(LuaValue[]), call(LuaValue), invoke(), invoke(LuaValue,Varargs), invokemethod(String,Varargs), invokemethod(LuaValue,Varargs)

invoke

public Varargs invoke(LuaValue arg,
                      Varargs varargs)
Call this with variable arguments, including metatag processing, and retain all return values in a Varargs.

If this is a LuaFunction, call it, and return all values. Otherwise, look for the CALL metatag and call that.

To get a particular return value, us Varargs.arg(int)

To call this as a method call, use invokemethod(LuaValue,Varargs) instead.

Parameters:
arg - The first argument to supply to the called function
varargs - Varargs containing the remaining arguments to supply to the called function
Returns:
All return values as a Varargs instance.
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
varargsOf(LuaValue[]), call(LuaValue,LuaValue), invoke(LuaValue,Varargs), invokemethod(String,Varargs), invokemethod(LuaValue,Varargs)

invoke

public Varargs invoke(LuaValue arg1,
                      LuaValue arg2,
                      Varargs varargs)
Call this with variable arguments, including metatag processing, and retain all return values in a Varargs.

If this is a LuaFunction, call it, and return all values. Otherwise, look for the CALL metatag and call that.

To get a particular return value, us Varargs.arg(int)

To call this as a method call, use invokemethod(LuaValue,Varargs) instead.

Parameters:
arg1 - The first argument to supply to the called function
arg2 - The second argument to supply to the called function
varargs - Varargs containing the remaining arguments to supply to the called function
Returns:
All return values as a Varargs instance.
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
varargsOf(LuaValue[]), call(LuaValue,LuaValue,LuaValue), invoke(LuaValue,LuaValue,Varargs), invokemethod(String,Varargs), invokemethod(LuaValue,Varargs)

invoke

public Varargs invoke(LuaValue[] args)
Call this with variable arguments, including metatag processing, and retain all return values in a Varargs.

If this is a LuaFunction, call it, and return all values. Otherwise, look for the CALL metatag and call that.

To get a particular return value, us Varargs.arg(int)

To call this as a method call, use invokemethod(LuaValue,Varargs) instead.

Parameters:
args - Array of arguments to supply to the called function
Returns:
All return values as a Varargs instance.
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
varargsOf(LuaValue[]), call(LuaValue,LuaValue,LuaValue), invoke(LuaValue,LuaValue,Varargs), invokemethod(String,LuaValue[]), invokemethod(LuaValue,LuaValue[])

invoke

public Varargs invoke(LuaValue[] args,
                      Varargs varargs)
Call this with variable arguments, including metatag processing, and retain all return values in a Varargs.

If this is a LuaFunction, call it, and return all values. Otherwise, look for the CALL metatag and call that.

To get a particular return value, us Varargs.arg(int)

To call this as a method call, use invokemethod(LuaValue,Varargs) instead.

Parameters:
args - Array of arguments to supply to the called function
varargs - Varargs containing additional arguments to supply to the called function
Returns:
All return values as a Varargs instance.
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
varargsOf(LuaValue[]), call(LuaValue,LuaValue,LuaValue), invoke(LuaValue,LuaValue,Varargs), invokemethod(String,LuaValue[]), invokemethod(LuaValue,LuaValue[]), invokemethod(String,Varargs), invokemethod(LuaValue,Varargs)

invokemethod

public Varargs invokemethod(java.lang.String name)
Call named method on this with 0 arguments, including metatag processing, and retain all return values in a Varargs.

Look up this[name] and if it is a LuaFunction, call it inserting this as an additional first argument, and return all return values as a Varargs instance. Otherwise, look for the CALL metatag and call that.

To get a particular return value, us Varargs.arg(int)

To call this as a plain call, use invoke() instead.

Parameters:
name - Name of the method to look up for invocation
Returns:
All values returned from this:name() as a Varargs instance
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
call(), invoke(), method(String), invokemethod(LuaValue), invokemethod(String, LuaValue[]), invokemethod(String, Varargs), invokemethod(LuaValue, LuaValue[]), invokemethod(LuaValue, Varargs)

invokemethod

public Varargs invokemethod(LuaValue name)
Call named method on this with 0 arguments, including metatag processing, and retain all return values in a Varargs.

Look up this[name] and if it is a LuaFunction, call it inserting this as an additional first argument, and return all return values as a Varargs instance. Otherwise, look for the CALL metatag and call that.

To get a particular return value, us Varargs.arg(int)

To call this as a plain call, use invoke() instead.

Parameters:
name - Name of the method to look up for invocation
Returns:
All values returned from this:name() as a Varargs instance
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
call(), invoke(), method(LuaValue), invokemethod(String), invokemethod(String, LuaValue[]), invokemethod(String, Varargs), invokemethod(LuaValue, LuaValue[]), invokemethod(LuaValue, Varargs)

invokemethod

public Varargs invokemethod(java.lang.String name,
                            Varargs args)
Call named method on this with 1 argument, including metatag processing, and retain all return values in a Varargs.

Look up this[name] and if it is a LuaFunction, call it inserting this as an additional first argument, and return all return values as a Varargs instance. Otherwise, look for the CALL metatag and call that.

To get a particular return value, us Varargs.arg(int)

To call this as a plain call, use invoke(Varargs) instead.

Parameters:
name - Name of the method to look up for invocation
args - Varargs containing arguments to supply to the called function after this
Returns:
All values returned from this:name(args) as a Varargs instance
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
call(), invoke(Varargs), method(String), invokemethod(String), invokemethod(LuaValue), invokemethod(String, LuaValue[]), invokemethod(LuaValue, LuaValue[]), invokemethod(LuaValue, Varargs)

invokemethod

public Varargs invokemethod(LuaValue name,
                            Varargs args)
Call named method on this with variable arguments, including metatag processing, and retain all return values in a Varargs.

Look up this[name] and if it is a LuaFunction, call it inserting this as an additional first argument, and return all return values as a Varargs instance. Otherwise, look for the CALL metatag and call that.

To get a particular return value, us Varargs.arg(int)

To call this as a plain call, use invoke(Varargs) instead.

Parameters:
name - Name of the method to look up for invocation
args - Varargs containing arguments to supply to the called function after this
Returns:
All values returned from this:name(args) as a Varargs instance
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
call(), invoke(Varargs), method(String), invokemethod(String), invokemethod(LuaValue), invokemethod(String, LuaValue[]), invokemethod(String, Varargs), invokemethod(LuaValue, LuaValue[])

invokemethod

public Varargs invokemethod(java.lang.String name,
                            LuaValue[] args)
Call named method on this with 1 argument, including metatag processing, and retain all return values in a Varargs.

Look up this[name] and if it is a LuaFunction, call it inserting this as an additional first argument, and return all return values as a Varargs instance. Otherwise, look for the CALL metatag and call that.

To get a particular return value, us Varargs.arg(int)

To call this as a plain call, use invoke(Varargs) instead.

Parameters:
name - Name of the method to look up for invocation
args - Array of LuaValue containing arguments to supply to the called function after this
Returns:
All values returned from this:name(args) as a Varargs instance
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
call(), invoke(Varargs), method(String), invokemethod(String), invokemethod(LuaValue), invokemethod(String, Varargs), invokemethod(LuaValue, LuaValue[]), invokemethod(LuaValue, Varargs), varargsOf(LuaValue[])

invokemethod

public Varargs invokemethod(LuaValue name,
                            LuaValue[] args)
Call named method on this with variable arguments, including metatag processing, and retain all return values in a Varargs.

Look up this[name] and if it is a LuaFunction, call it inserting this as an additional first argument, and return all return values as a Varargs instance. Otherwise, look for the CALL metatag and call that.

To get a particular return value, us Varargs.arg(int)

To call this as a plain call, use invoke(Varargs) instead.

Parameters:
name - Name of the method to look up for invocation
args - Array of LuaValue containing arguments to supply to the called function after this
Returns:
All values returned from this:name(args) as a Varargs instance
Throws:
LuaError - if not a function and CALL is not defined, or the invoked function throws a LuaError or the invoked closure throw a lua error
See Also:
call(), invoke(Varargs), method(String), invokemethod(String), invokemethod(LuaValue), invokemethod(String, LuaValue[]), invokemethod(String, Varargs), invokemethod(LuaValue, Varargs), varargsOf(LuaValue[])

callmt

protected LuaValue callmt()
Get the metatag value for the CALL metatag, if it exists.

Returns:
LuaValue value if metatag is defined
Throws:
LuaError - if CALL metatag is not defined.

not

public LuaValue not()
Unary not: return inverse boolean value (~this) as defined by lua not operator

Returns:
TRUE if NIL or FALSE, otherwise FALSE

neg

public LuaValue neg()
Unary minus: return negative value (-this) as defined by lua unary minus operator

Returns:
boolean inverse as LuaBoolean if boolean or nil, numeric inverse as LuaNumber if numeric, or metatag processing result if UNM metatag is defined
Throws:
LuaError - if this is not a table or string, and has no UNM metatag

len

public LuaValue len()
Length operator: return lua length of object (#this) including metatag processing as java int

Returns:
length as defined by the lua # operator or metatag processing result
Throws:
LuaError - if this is not a table or string, and has no LEN metatag

length

public int length()
Length operator: return lua length of object (#this) including metatag processing as java int

Returns:
length as defined by the lua # operator or metatag processing result converted to java int using toint()
Throws:
LuaError - if this is not a table or string, and has no LEN metatag

rawlen

public int rawlen()
Get raw length of table or string without metatag processing.

Returns:
the length of the table or string.
Throws:
LuaError - if this is not a table or string.

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

eq

public LuaValue eq(LuaValue val)
Equals: Perform equality comparison with another value including metatag processing using EQ.

Parameters:
val - The value to compare with.
Returns:
TRUE if values are comparable and (this == rhs), FALSE if comparable but not equal, LuaValue if metatag processing occurs.
See Also:
eq_b(LuaValue), raweq(LuaValue), neq(LuaValue), eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue), EQ

eq_b

public boolean eq_b(LuaValue val)
Equals: Perform equality comparison with another value including metatag processing using EQ, and return java boolean

Parameters:
val - The value to compare with.
Returns:
true if values are comparable and (this == rhs), false if comparable but not equal, result converted to java boolean if metatag processing occurs.
See Also:
eq(LuaValue), raweq(LuaValue), neq_b(LuaValue), eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue), EQ

neq

public LuaValue neq(LuaValue val)
Notquals: Perform inequality comparison with another value including metatag processing using EQ.

Parameters:
val - The value to compare with.
Returns:
TRUE if values are comparable and (this != rhs), FALSE if comparable but equal, inverse of LuaValue converted to LuaBoolean if metatag processing occurs.
See Also:
eq(LuaValue), raweq(LuaValue), eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue), EQ

neq_b

public boolean neq_b(LuaValue val)
Notquals: Perform inequality comparison with another value including metatag processing using EQ.

Parameters:
val - The value to compare with.
Returns:
true if values are comparable and (this != rhs), false if comparable but equal, inverse of result converted to boolean if metatag processing occurs.
See Also:
eq_b(LuaValue), raweq(LuaValue), eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue), EQ

raweq

public boolean raweq(LuaValue val)
Equals: Perform direct equality comparison with another value without metatag processing.

Parameters:
val - The value to compare with.
Returns:
true if (this == rhs), false otherwise
See Also:
eq(LuaValue), raweq(LuaUserdata), raweq(LuaString), raweq(double), raweq(int), EQ

raweq

public boolean raweq(LuaUserdata val)
Equals: Perform direct equality comparison with a LuaUserdata value without metatag processing.

Parameters:
val - The LuaUserdata to compare with.
Returns:
true if this is userdata and their metatables are the same using == and their instances are equal using equals(Object), otherwise false
See Also:
eq(LuaValue), raweq(LuaValue)

raweq

public boolean raweq(LuaString val)
Equals: Perform direct equality comparison with a LuaString value without metatag processing.

Parameters:
val - The LuaString to compare with.
Returns:
true if this is a LuaString and their byte sequences match, otherwise false

raweq

public boolean raweq(double val)
Equals: Perform direct equality comparison with a double value without metatag processing.

Parameters:
val - The double value to compare with.
Returns:
true if this is a LuaNumber whose value equals val, otherwise false

raweq

public boolean raweq(int val)
Equals: Perform direct equality comparison with a int value without metatag processing.

Parameters:
val - The double value to compare with.
Returns:
true if this is a LuaNumber whose value equals val, otherwise false

eqmtcall

public static final boolean eqmtcall(LuaValue lhs,
                                     LuaValue lhsmt,
                                     LuaValue rhs,
                                     LuaValue rhsmt)
Perform equality testing metatag processing

Parameters:
lhs - left-hand-side of equality expression
lhsmt - metatag value for left-hand-side
rhs - right-hand-side of equality expression
rhsmt - metatag value for right-hand-side
Returns:
true if metatag processing result is not NIL or FALSE
Throws:
LuaError - if metatag was not defined for either operand
See Also:
equals(Object), eq(LuaValue), raweq(LuaValue), EQ

add

public LuaValue add(LuaValue rhs)
Add: Perform numeric add operation with another value including metatag processing.

Each operand must derive from LuaNumber or derive from LuaString and be convertible to a number

Parameters:
rhs - The right-hand-side value to perform the add with
Returns:
value of (this + rhs) if both are numeric, or LuaValue if metatag processing occurs
Throws:
LuaError - if either operand is not a number or string convertible to number, and neither has the ADD metatag defined
See Also:
arithmt(LuaValue, LuaValue)

add

public LuaValue add(double rhs)
Add: Perform numeric add operation with another value of double type with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Parameters:
rhs - The right-hand-side value to perform the add with
Returns:
value of (this + rhs) if this is numeric
Throws:
LuaError - if this is not a number or string convertible to number
See Also:
add(LuaValue)

add

public LuaValue add(int rhs)
Add: Perform numeric add operation with another value of int type with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Parameters:
rhs - The right-hand-side value to perform the add with
Returns:
value of (this + rhs) if this is numeric
Throws:
LuaError - if this is not a number or string convertible to number
See Also:
add(LuaValue)

sub

public LuaValue sub(LuaValue rhs)
Subtract: Perform numeric subtract operation with another value of unknown type, including metatag processing.

Each operand must derive from LuaNumber or derive from LuaString and be convertible to a number

Parameters:
rhs - The right-hand-side value to perform the subtract with
Returns:
value of (this - rhs) if both are numeric, or LuaValue if metatag processing occurs
Throws:
LuaError - if either operand is not a number or string convertible to number, and neither has the SUB metatag defined
See Also:
arithmt(LuaValue, LuaValue)

sub

public LuaValue sub(double rhs)
Subtract: Perform numeric subtract operation with another value of double type with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Parameters:
rhs - The right-hand-side value to perform the subtract with
Returns:
value of (this - rhs) if this is numeric
Throws:
LuaError - if this is not a number or string convertible to number
See Also:
sub(LuaValue)

sub

public LuaValue sub(int rhs)
Subtract: Perform numeric subtract operation with another value of int type with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Parameters:
rhs - The right-hand-side value to perform the subtract with
Returns:
value of (this - rhs) if this is numeric
Throws:
LuaError - if this is not a number or string convertible to number
See Also:
sub(LuaValue)

subFrom

public LuaValue subFrom(double lhs)
Reverse-subtract: Perform numeric subtract operation from an int value with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Parameters:
lhs - The left-hand-side value from which to perform the subtraction
Returns:
value of (lhs - this) if this is numeric
Throws:
LuaError - if this is not a number or string convertible to number
See Also:
sub(LuaValue), sub(double), sub(int)

subFrom

public LuaValue subFrom(int lhs)
Reverse-subtract: Perform numeric subtract operation from a double value without metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

For metatag processing sub(LuaValue) must be used

Parameters:
lhs - The left-hand-side value from which to perform the subtraction
Returns:
value of (lhs - this) if this is numeric
Throws:
LuaError - if this is not a number or string convertible to number
See Also:
sub(LuaValue), sub(double), sub(int)

mul

public LuaValue mul(LuaValue rhs)
Multiply: Perform numeric multiply operation with another value of unknown type, including metatag processing.

Each operand must derive from LuaNumber or derive from LuaString and be convertible to a number

Parameters:
rhs - The right-hand-side value to perform the multiply with
Returns:
value of (this * rhs) if both are numeric, or LuaValue if metatag processing occurs
Throws:
LuaError - if either operand is not a number or string convertible to number, and neither has the MUL metatag defined
See Also:
arithmt(LuaValue, LuaValue)

mul

public LuaValue mul(double rhs)
Multiply: Perform numeric multiply operation with another value of double type with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Parameters:
rhs - The right-hand-side value to perform the multiply with
Returns:
value of (this * rhs) if this is numeric
Throws:
LuaError - if this is not a number or string convertible to number
See Also:
mul(LuaValue)

mul

public LuaValue mul(int rhs)
Multiply: Perform numeric multiply operation with another value of int type with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Parameters:
rhs - The right-hand-side value to perform the multiply with
Returns:
value of (this * rhs) if this is numeric
Throws:
LuaError - if this is not a number or string convertible to number
See Also:
mul(LuaValue)

pow

public LuaValue pow(LuaValue rhs)
Raise to power: Raise this value to a power including metatag processing.

Each operand must derive from LuaNumber or derive from LuaString and be convertible to a number

Parameters:
rhs - The power to raise this value to
Returns:
value of (this ^ rhs) if both are numeric, or LuaValue if metatag processing occurs
Throws:
LuaError - if either operand is not a number or string convertible to number, and neither has the POW metatag defined
See Also:
arithmt(LuaValue, LuaValue)

pow

public LuaValue pow(double rhs)
Raise to power: Raise this value to a power of double type with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Parameters:
rhs - The power to raise this value to
Returns:
value of (this ^ rhs) if this is numeric
Throws:
LuaError - if this is not a number or string convertible to number
See Also:
pow(LuaValue)

pow

public LuaValue pow(int rhs)
Raise to power: Raise this value to a power of int type with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Parameters:
rhs - The power to raise this value to
Returns:
value of (this ^ rhs) if this is numeric
Throws:
LuaError - if this is not a number or string convertible to number
See Also:
pow(LuaValue)

powWith

public LuaValue powWith(double lhs)
Reverse-raise to power: Raise another value of double type to this power with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Parameters:
lhs - The left-hand-side value which will be raised to this power
Returns:
value of (lhs ^ this) if this is numeric
Throws:
LuaError - if this is not a number or string convertible to number
See Also:
pow(LuaValue), pow(double), pow(int)

powWith

public LuaValue powWith(int lhs)
Reverse-raise to power: Raise another value of double type to this power with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Parameters:
lhs - The left-hand-side value which will be raised to this power
Returns:
value of (lhs ^ this) if this is numeric
Throws:
LuaError - if this is not a number or string convertible to number
See Also:
pow(LuaValue), pow(double), pow(int)

div

public LuaValue div(LuaValue rhs)
Divide: Perform numeric divide operation by another value of unknown type, including metatag processing.

Each operand must derive from LuaNumber or derive from LuaString and be convertible to a number

Parameters:
rhs - The right-hand-side value to perform the divulo with
Returns:
value of (this / rhs) if both are numeric, or LuaValue if metatag processing occurs
Throws:
LuaError - if either operand is not a number or string convertible to number, and neither has the DIV metatag defined
See Also:
arithmt(LuaValue, LuaValue)

div

public LuaValue div(double rhs)
Divide: Perform numeric divide operation by another value of double type without metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

For metatag processing div(LuaValue) must be used

Parameters:
rhs - The right-hand-side value to perform the divulo with
Returns:
value of (this / rhs) if this is numeric
Throws:
LuaError - if this is not a number or string convertible to number
See Also:
div(LuaValue)

div

public LuaValue div(int rhs)
Divide: Perform numeric divide operation by another value of int type without metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

For metatag processing div(LuaValue) must be used

Parameters:
rhs - The right-hand-side value to perform the divulo with
Returns:
value of (this / rhs) if this is numeric
Throws:
LuaError - if this is not a number or string convertible to number
See Also:
div(LuaValue)

divInto

public LuaValue divInto(double lhs)
Reverse-divide: Perform numeric divide operation into another value with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Parameters:
lhs - The left-hand-side value which will be divided by this
Returns:
value of (lhs / this) if this is numeric
Throws:
LuaError - if this is not a number or string convertible to number
See Also:
div(LuaValue), div(double), div(int)

mod

public LuaValue mod(LuaValue rhs)
Modulo: Perform numeric modulo operation with another value of unknown type, including metatag processing.

Each operand must derive from LuaNumber or derive from LuaString and be convertible to a number

Parameters:
rhs - The right-hand-side value to perform the modulo with
Returns:
value of (this % rhs) if both are numeric, or LuaValue if metatag processing occurs
Throws:
LuaError - if either operand is not a number or string convertible to number, and neither has the MOD metatag defined
See Also:
arithmt(LuaValue, LuaValue)

mod

public LuaValue mod(double rhs)
Modulo: Perform numeric modulo operation with another value of double type without metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

For metatag processing mod(LuaValue) must be used

Parameters:
rhs - The right-hand-side value to perform the modulo with
Returns:
value of (this % rhs) if this is numeric
Throws:
LuaError - if this is not a number or string convertible to number
See Also:
mod(LuaValue)

mod

public LuaValue mod(int rhs)
Modulo: Perform numeric modulo operation with another value of int type without metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

For metatag processing mod(LuaValue) must be used

Parameters:
rhs - The right-hand-side value to perform the modulo with
Returns:
value of (this % rhs) if this is numeric
Throws:
LuaError - if this is not a number or string convertible to number
See Also:
mod(LuaValue)

modFrom

public LuaValue modFrom(double lhs)
Reverse-modulo: Perform numeric modulo operation from another value with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Parameters:
lhs - The left-hand-side value which will be modulo'ed by this
Returns:
value of (lhs % this) if this is numeric
Throws:
LuaError - if this is not a number or string convertible to number
See Also:
mod(LuaValue), mod(double), mod(int)

arithmt

protected LuaValue arithmt(LuaValue tag,
                           LuaValue op2)
Perform metatag processing for arithmetic operations.

Finds the supplied metatag value for this or op2 and invokes it, or throws LuaError if neither is defined.

Parameters:
tag - The metatag to look up
op2 - The other operand value to perform the operation with
Returns:
LuaValue resulting from metatag processing
Throws:
LuaError - if metatag was not defined for either operand
See Also:
add(LuaValue), sub(LuaValue), mul(LuaValue), pow(LuaValue), div(LuaValue), mod(LuaValue), ADD, SUB, MUL, POW, DIV, MOD

arithmtwith

protected LuaValue arithmtwith(LuaValue tag,
                               double op1)
Perform metatag processing for arithmetic operations when the left-hand-side is a number.

Finds the supplied metatag value for this and invokes it, or throws LuaError if neither is defined.

Parameters:
tag - The metatag to look up
op1 - The value of the left-hand-side to perform the operation with
Returns:
LuaValue resulting from metatag processing
Throws:
LuaError - if metatag was not defined for either operand
See Also:
add(LuaValue), sub(LuaValue), mul(LuaValue), pow(LuaValue), div(LuaValue), mod(LuaValue), ADD, SUB, MUL, POW, DIV, MOD

lt

public LuaValue lt(LuaValue rhs)
Less than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning LuaValue.

To be comparable, both operands must derive from LuaString or both must derive from LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
TRUE if (this < rhs), FALSE if not, or LuaValue if metatag processing occurs
Throws:
LuaError - if either both operands are not a strings or both are not numbers and no LT metatag is defined.
See Also:
gteq_b(LuaValue), comparemt(LuaValue, LuaValue)

lt

public LuaValue lt(double rhs)
Less than: Perform numeric comparison with another value of double type, including metatag processing, and returning LuaValue.

To be comparable, this must derive from LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
TRUE if (this < rhs), FALSE if not, or LuaValue if metatag processing occurs
Throws:
LuaError - if this is not a number and no LT metatag is defined.
See Also:
gteq_b(double), comparemt(LuaValue, LuaValue)

lt

public LuaValue lt(int rhs)
Less than: Perform numeric comparison with another value of int type, including metatag processing, and returning LuaValue.

To be comparable, this must derive from LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
TRUE if (this < rhs), FALSE if not, or LuaValue if metatag processing occurs
Throws:
LuaError - if this is not a number and no LT metatag is defined.
See Also:
gteq_b(int), comparemt(LuaValue, LuaValue)

lt_b

public boolean lt_b(LuaValue rhs)
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 LuaString or both must derive from LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (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 LT metatag is defined.
See Also:
gteq(LuaValue), comparemt(LuaValue, LuaValue)

lt_b

public boolean lt_b(int rhs)
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 LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (this < rhs), false if not, and boolean interpreation of result if metatag processing occurs.
Throws:
LuaError - if this is not a number and no LT metatag is defined.
See Also:
gteq(int), comparemt(LuaValue, LuaValue)

lt_b

public boolean lt_b(double rhs)
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 LuaString or both must derive from LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (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 LT metatag is defined.
See Also:
gteq(LuaValue), comparemt(LuaValue, LuaValue)

lteq

public LuaValue lteq(LuaValue rhs)
Less than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning LuaValue.

To be comparable, both operands must derive from LuaString or both must derive from LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
TRUE if (this <= rhs), FALSE if not, or LuaValue if metatag processing occurs
Throws:
LuaError - if either both operands are not a strings or both are not numbers and no LE metatag is defined.
See Also:
gteq_b(LuaValue), comparemt(LuaValue, LuaValue)

lteq

public LuaValue lteq(double rhs)
Less than or equals: Perform numeric comparison with another value of double type, including metatag processing, and returning LuaValue.

To be comparable, this must derive from LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
TRUE if (this <= rhs), FALSE if not, or LuaValue if metatag processing occurs
Throws:
LuaError - if this is not a number and no LE metatag is defined.
See Also:
gteq_b(double), comparemt(LuaValue, LuaValue)

lteq

public LuaValue lteq(int rhs)
Less than or equals: Perform numeric comparison with another value of int type, including metatag processing, and returning LuaValue.

To be comparable, this must derive from LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
TRUE if (this <= rhs), FALSE if not, or LuaValue if metatag processing occurs
Throws:
LuaError - if this is not a number and no LE metatag is defined.
See Also:
gteq_b(int), comparemt(LuaValue, LuaValue)

lteq_b

public boolean lteq_b(LuaValue rhs)
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 LuaString or both must derive from LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (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 LE metatag is defined.
See Also:
gteq(LuaValue), comparemt(LuaValue, LuaValue)

lteq_b

public boolean lteq_b(int rhs)
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 LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (this <= rhs), false if not, and boolean interpreation of result if metatag processing occurs.
Throws:
LuaError - if this is not a number and no LE metatag is defined.
See Also:
gteq(int), comparemt(LuaValue, LuaValue)

lteq_b

public boolean lteq_b(double rhs)
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 LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (this <= rhs), false if not, and boolean interpreation of result if metatag processing occurs.
Throws:
LuaError - if this is not a number and no LE metatag is defined.
See Also:
gteq(double), comparemt(LuaValue, LuaValue)

gt

public LuaValue gt(LuaValue rhs)
Greater than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning LuaValue.

To be comparable, both operands must derive from LuaString or both must derive from LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
TRUE if (this > rhs), FALSE if not, or LuaValue if metatag processing occurs
Throws:
LuaError - if either both operands are not a strings or both are not numbers and no LE metatag is defined.
See Also:
gteq_b(LuaValue), comparemt(LuaValue, LuaValue)

gt

public LuaValue gt(double rhs)
Greater than: Perform numeric comparison with another value of double type, including metatag processing, and returning LuaValue.

To be comparable, this must derive from LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
TRUE if (this > rhs), FALSE if not, or LuaValue if metatag processing occurs
Throws:
LuaError - if this is not a number and no LE metatag is defined.
See Also:
gteq_b(double), comparemt(LuaValue, LuaValue)

gt

public LuaValue gt(int rhs)
Greater than: Perform numeric comparison with another value of int type, including metatag processing, and returning LuaValue.

To be comparable, this must derive from LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
TRUE if (this > rhs), FALSE if not, or LuaValue if metatag processing occurs
Throws:
LuaError - if this is not a number and no LE metatag is defined.
See Also:
gteq_b(int), comparemt(LuaValue, LuaValue)

gt_b

public boolean gt_b(LuaValue rhs)
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 LuaString or both must derive from LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (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 LE metatag is defined.
See Also:
gteq(LuaValue), comparemt(LuaValue, LuaValue)

gt_b

public boolean gt_b(int rhs)
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 LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (this > rhs), false if not, and boolean interpreation of result if metatag processing occurs.
Throws:
LuaError - if this is not a number and no LE metatag is defined.
See Also:
gteq(int), comparemt(LuaValue, LuaValue)

gt_b

public boolean gt_b(double rhs)
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 LuaString or both must derive from LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (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 LE metatag is defined.
See Also:
gteq(LuaValue), comparemt(LuaValue, LuaValue)

gteq

public LuaValue gteq(LuaValue rhs)
Greater than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning LuaValue.

To be comparable, both operands must derive from LuaString or both must derive from LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
TRUE if (this >= rhs), FALSE if not, or LuaValue if metatag processing occurs
Throws:
LuaError - if either both operands are not a strings or both are not numbers and no LT metatag is defined.
See Also:
gteq_b(LuaValue), comparemt(LuaValue, LuaValue)

gteq

public LuaValue gteq(double rhs)
Greater than or equals: Perform numeric comparison with another value of double type, including metatag processing, and returning LuaValue.

To be comparable, this must derive from LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
TRUE if (this >= rhs), FALSE if not, or LuaValue if metatag processing occurs
Throws:
LuaError - if this is not a number and no LT metatag is defined.
See Also:
gteq_b(double), comparemt(LuaValue, LuaValue)

gteq

public LuaValue gteq(int rhs)
Greater than or equals: Perform numeric comparison with another value of int type, including metatag processing, and returning LuaValue.

To be comparable, this must derive from LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
TRUE if (this >= rhs), FALSE if not, or LuaValue if metatag processing occurs
Throws:
LuaError - if this is not a number and no LT metatag is defined.
See Also:
gteq_b(int), comparemt(LuaValue, LuaValue)

gteq_b

public boolean gteq_b(LuaValue rhs)
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 LuaString or both must derive from LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (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 LT metatag is defined.
See Also:
gteq(LuaValue), comparemt(LuaValue, LuaValue)

gteq_b

public boolean gteq_b(int rhs)
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 LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (this >= rhs), false if not, and boolean interpreation of result if metatag processing occurs.
Throws:
LuaError - if this is not a number and no LT metatag is defined.
See Also:
gteq(int), comparemt(LuaValue, LuaValue)

gteq_b

public boolean gteq_b(double rhs)
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 LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (this >= rhs), false if not, and boolean interpreation of result if metatag processing occurs.
Throws:
LuaError - if this is not a number and no LT metatag is defined.
See Also:
gteq(double), comparemt(LuaValue, LuaValue)

comparemt

public LuaValue comparemt(LuaValue tag,
                          LuaValue op1)
Perform metatag processing for comparison operations.

Finds the supplied metatag value and invokes it, or throws LuaError if none applies.

Parameters:
tag - The metatag to look up
op1 - The operand with which to to perform the operation
Returns:
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.
See Also:
gt(LuaValue), gteq(LuaValue), lt(LuaValue), lteq(LuaValue)

strcmp

public int strcmp(LuaValue rhs)
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 LuaString.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
int < 0 for (this < rhs), int > 0 for (this > rhs), or 0 when same string.
Throws:
LuaError - if either operand is not a string

strcmp

public int strcmp(LuaString rhs)
Perform string comparison with another value known to be a LuaString using string comparison based on byte values.

Only strings can be compared, meaning each operand must derive from LuaString.

Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
int < 0 for (this < rhs), int > 0 for (this > rhs), or 0 when same string.
Throws:
LuaError - if this is not a string

concat

public LuaValue concat(LuaValue rhs)
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 LuaString or LuaNumber.

Parameters:
rhs - The right-hand-side value to perform the operation with
Returns:
LuaValue resulting from concatenation of (this .. rhs)
Throws:
LuaError - if either operand is not of an appropriate type, such as nil or a table

concatTo

public LuaValue concatTo(LuaValue lhs)
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 LuaString or LuaNumber.

Parameters:
lhs - The left-hand-side value onto which this will be concatenated
Returns:
LuaValue resulting from concatenation of (lhs .. this)
Throws:
LuaError - if either operand is not of an appropriate type, such as nil or a table
See Also:
concat(LuaValue)

concatTo

public LuaValue concatTo(LuaNumber lhs)
Reverse-concatenation: concatenate this value onto another value known to be a 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 LuaString or LuaNumber.

Parameters:
lhs - The left-hand-side value onto which this will be concatenated
Returns:
LuaValue resulting from concatenation of (lhs .. this)
Throws:
LuaError - if either operand is not of an appropriate type, such as nil or a table
See Also:
concat(LuaValue)

concatTo

public LuaValue concatTo(LuaString lhs)
Reverse-concatenation: concatenate this value onto another value known to be a 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 LuaString or LuaNumber.

Parameters:
lhs - The left-hand-side value onto which this will be concatenated
Returns:
LuaValue resulting from concatenation of (lhs .. this)
Throws:
LuaError - if either operand is not of an appropriate type, such as nil or a table
See Also:
concat(LuaValue)

buffer

public Buffer buffer()
Convert the value to a Buffer for more efficient concatenation of multiple strings.

Returns:
Buffer instance containing the string or number

concat

public Buffer concat(Buffer rhs)
Concatenate a 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 LuaString or LuaNumber.

Parameters:
rhs - The right-hand-side Buffer to perform the operation with
Returns:
LuaString resulting from concatenation of (this .. rhs)
Throws:
LuaError - if either operand is not of an appropriate type, such as nil or a table

concatmt

public LuaValue concatmt(LuaValue rhs)
Perform metatag processing for concatenation operations.

Finds the CONCAT metatag value and invokes it, or throws LuaError if it doesn't exist.

Parameters:
rhs - The right-hand-side value to perform the operation with
Returns:
LuaValue resulting from metatag processing for CONCAT metatag.
Throws:
LuaError - if metatag was not defined for either operand

and

public LuaValue and(LuaValue rhs)
Perform boolean and with another operand, based on lua rules for boolean evaluation. This returns either this or rhs depending on the boolean value for this.

Parameters:
rhs - The right-hand-side value to perform the operation with
Returns:
this if this.toboolean() is false, rhs otherwise.

or

public LuaValue or(LuaValue rhs)
Perform boolean or with another operand, based on lua rules for boolean evaluation. This returns either this or rhs depending on the boolean value for this.

Parameters:
rhs - The right-hand-side value to perform the operation with
Returns:
this if this.toboolean() is true, rhs otherwise.

testfor_b

public boolean testfor_b(LuaValue limit,
                         LuaValue step)
Perform end-condition test in for-loop processing.

Used in lua-bytecode to Java-bytecode conversion.

Parameters:
limit - the numerical limit to complete the for loop
step - the numberical step size to use.
Returns:
true if limit has not been reached, false otherwise.

strvalue

public LuaString strvalue()
Convert this value to a string if it is a LuaString or LuaNumber, or throw a LuaError if it is not

Returns:
LuaString corresponding to the value if a string or number
Throws:
LuaError - if not a string or number

strongvalue

public LuaValue strongvalue()
Return this value as a strong reference, or null if it was weak and is no longer referenced.

Returns:
LuaValue referred to, or null if it was weak and is no longer referenced.
See Also:
WeakTable

valueOf

public static LuaBoolean valueOf(boolean b)
Convert java boolean to a LuaValue.

Parameters:
b - boolean value to convert
Returns:
TRUE if not or FALSE if false

valueOf

public static LuaInteger valueOf(int i)
Convert java int to a LuaValue.

Parameters:
i - int value to convert
Returns:
LuaInteger instance, possibly pooled, whose value is i

valueOf

public static LuaNumber valueOf(double d)
Convert java double to a LuaValue. This may return a LuaInteger or LuaDouble depending on the value supplied.

Parameters:
d - double value to convert
Returns:
LuaNumber instance, possibly pooled, whose value is d

valueOf

public static LuaString valueOf(java.lang.String s)
Convert java string to a LuaValue.

Parameters:
s - String value to convert
Returns:
LuaString instance, possibly pooled, whose value is s

valueOf

public static LuaString valueOf(byte[] bytes)
Convert bytes in an array to a LuaValue.

Parameters:
bytes - byte array to convert
Returns:
LuaString instance, possibly pooled, whose bytes are those in the supplied array

valueOf

public static LuaString valueOf(byte[] bytes,
                                int off,
                                int len)
Convert bytes in an array to a LuaValue.

Parameters:
bytes - byte array to convert
off - offset into the byte array, starting at 0
len - number of bytes to include in the LuaString
Returns:
LuaString instance, possibly pooled, whose bytes are those in the supplied array

tableOf

public static LuaTable tableOf()
Construct an empty LuaTable.

Returns:
new LuaTable instance with no values and no metatable.

tableOf

public static LuaTable tableOf(Varargs varargs,
                               int firstarg)
Construct a LuaTable initialized with supplied array values.

Parameters:
varargs - Varargs containing the values to use in initialization
firstarg - the index of the first argument to use from the varargs, 1 being the first.
Returns:
new LuaTable instance with sequential elements coming from the varargs.

tableOf

public static LuaTable tableOf(int narray,
                               int nhash)
Construct an empty LuaTable preallocated to hold array and hashed elements

Parameters:
narray - Number of array elements to preallocate
nhash - Number of hash elements to preallocate
Returns:
new LuaTable instance with no values and no metatable, but preallocated for array and hashed elements.

listOf

public static LuaTable listOf(LuaValue[] unnamedValues)
Construct a LuaTable initialized with supplied array values.

Parameters:
unnamedValues - array of LuaValue containing the values to use in initialization
Returns:
new LuaTable instance with sequential elements coming from the array.

listOf

public static LuaTable listOf(LuaValue[] unnamedValues,
                              Varargs lastarg)
Construct a LuaTable initialized with supplied array values.

Parameters:
unnamedValues - array of LuaValue containing the first values to use in initialization
lastarg - Varargs containing additional values to use in initialization to be put after the last unnamedValues element
Returns:
new LuaTable instance with sequential elements coming from the array and varargs.

tableOf

public static LuaTable tableOf(LuaValue[] namedValues)
Construct a LuaTable initialized with supplied named values.

Parameters:
namedValues - array of LuaValue containing the keys and values to use in initialization in order {key-a, value-a, key-b, value-b, ...}
Returns:
new LuaTable instance with non-sequential keys coming from the supplied array.

tableOf

public static LuaTable tableOf(LuaValue[] namedValues,
                               LuaValue[] unnamedValues)
Construct a 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.

Parameters:
namedValues - array of LuaValue containing the keys and values to use in initialization in order {key-a, value-a, key-b, value-b, ...}
unnamedValues - array of LuaValue containing the sequenctial elements to use in initialization in order {value-1, value-2, ...} , or null if there are none
Returns:
new LuaTable instance with named and sequential values supplied.

tableOf

public static LuaTable tableOf(LuaValue[] namedValues,
                               LuaValue[] unnamedValues,
                               Varargs lastarg)
Construct a 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.

Parameters:
namedValues - array of LuaValue containing the keys and values to use in initialization in order {key-a, value-a, key-b, value-b, ...}
unnamedValues - array of LuaValue containing the first sequenctial elements to use in initialization in order {value-1, value-2, ...} , or null if there are none
lastarg - Varargs containing additional values to use in the sequential part of the initialization, to be put after the last unnamedValues element
Returns:
new LuaTable instance with named and sequential values supplied.

userdataOf

public static LuaUserdata userdataOf(java.lang.Object o)
Construct a LuaUserdata for an object.

Parameters:
o - The java instance to be wrapped as userdata
Returns:
LuaUserdata value wrapping the java instance.

userdataOf

public static LuaUserdata userdataOf(java.lang.Object o,
                                     LuaValue metatable)
Construct a LuaUserdata for an object with a user supplied metatable.

Parameters:
o - The java instance to be wrapped as userdata
metatable - The metatble to associate with the userdata instance.
Returns:
LuaUserdata value wrapping the java instance.

gettable

protected static LuaValue gettable(LuaValue t,
                                   LuaValue key)
get value from metatable operations, or NIL if not defined by metatables


settable

protected static boolean settable(LuaValue t,
                                  LuaValue key,
                                  LuaValue value)
Perform field assignment including metatag processing.

Parameters:
t - LuaValue on which value is being set, typically a table or something with the metatag NEWINDEX defined
key - LuaValue naming the field to assign
value - LuaValue the new value to assign to key
Returns:
true if assignment or metatag processing succeeded, false otherwise
Throws:
LuaError - if there is a loop in metatag processing

metatag

public LuaValue metatag(LuaValue tag)
Get particular metatag, or return NIL if it doesn't exist

Parameters:
tag - Metatag name to look up, typically a string such as INDEX or NEWINDEX
Returns:
LuaValue for tag reason, or NIL

checkmetatag

protected LuaValue checkmetatag(LuaValue tag,
                                java.lang.String reason)
Get particular metatag, or throw LuaError if it doesn't exist

Parameters:
tag - Metatag name to look up, typically a string such as INDEX or NEWINDEX
reason - Description of error when tag lookup fails.
Returns:
LuaValue that can be called
Throws:
LuaError - when the lookup fails.

metatableOf

protected static org.luaj.vm2.Metatable metatableOf(LuaValue mt)
Construct a Metatable instance from the given LuaValue


varargsOf

public static Varargs varargsOf(LuaValue[] v)
Construct a Varargs around an array of LuaValues.

Parameters:
v - The array of LuaValues
Returns:
Varargs wrapping the supplied values.
See Also:
varargsOf(LuaValue, Varargs), varargsOf(LuaValue[], int, int)

varargsOf

public static Varargs varargsOf(LuaValue[] v,
                                Varargs r)
Construct a Varargs around an array of LuaValues.

Parameters:
v - The array of LuaValues
r - Varargs contain values to include at the end
Returns:
Varargs wrapping the supplied values.
See Also:
varargsOf(LuaValue[]), varargsOf(LuaValue[], int, int, Varargs)

varargsOf

public static Varargs varargsOf(LuaValue[] v,
                                int offset,
                                int length)
Construct a Varargs around an array of LuaValues.

Parameters:
v - The array of LuaValues
offset - number of initial values to skip in the array
length - number of values to include from the array
Returns:
Varargs wrapping the supplied values.
See Also:
varargsOf(LuaValue[]), varargsOf(LuaValue[], int, int, Varargs)

varargsOf

public static Varargs varargsOf(LuaValue[] v,
                                int offset,
                                int length,
                                Varargs more)
Construct a Varargs around an array of LuaValues. Caller must ensure that array contents are not mutated after this call or undefined behavior will result.

Parameters:
v - The array of LuaValues
offset - number of initial values to skip in the array
length - number of values to include from the array
more - Varargs contain values to include at the end
Returns:
Varargs wrapping the supplied values.
See Also:
varargsOf(LuaValue[], Varargs), varargsOf(LuaValue[], int, int)

varargsOf

public static Varargs varargsOf(LuaValue v,
                                Varargs r)
Construct a Varargs around a set of 2 or more LuaValues.

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.

Parameters:
v - First LuaValue in the Varargs
r - LuaValue supplying the 2rd value, or Varargss supplying all values beyond the first
Returns:
Varargs wrapping the supplied values.

varargsOf

public static Varargs varargsOf(LuaValue v1,
                                LuaValue v2,
                                Varargs v3)
Construct a Varargs around a set of 3 or more LuaValues.

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.

Parameters:
v1 - First LuaValue in the Varargs
v2 - Second LuaValue in the Varargs
v3 - LuaValue supplying the 3rd value, or Varargss supplying all values beyond the second
Returns:
Varargs wrapping the supplied values.

tailcallOf

public static Varargs tailcallOf(LuaValue func,
                                 Varargs args)
Construct a TailcallVarargs around a function and arguments.

The tail call is not yet called or processing until the client invokes 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.

Parameters:
func - LuaValue to be called as a tail call
args - Varargs containing the arguments to the call
Returns:
TailcallVarargs to be used in tailcall oprocessing.
See Also:
call(), invoke(), method(LuaValue), invokemethod(LuaValue)

onInvoke

public Varargs onInvoke(Varargs args)
Callback used during tail call processing to invoke the function once.

This may return a TailcallVarargs to be evaluated by the client.

This should not be called directly, instead use one of the call invocation functions.

Parameters:
args - the arguments to the call invocation.
Returns:
Varargs the return values, possible a TailcallVarargs.
See Also:
call(), invoke(), method(LuaValue), invokemethod(LuaValue)

initupvalue1

public void initupvalue1(LuaValue env)
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.

Parameters:
env - The environment to load into the first upvalue, if there is one.

subargs

public Varargs subargs(int start)
Create a Varargs instance containing arguments starting at index start

Specified by:
subargs in class Varargs
Parameters:
start - the index from which to include arguments, where 1 is the first argument.
Returns:
Varargs containing argument { start, start+1, ... , narg-start-1 }


Copyright © 2007-2015 Luaj.org. All Rights Reserved.