Establishes base implementations for all the operations on lua types. This allows Java clients to deal essentially with one type for all Java values, namely {@link LuaValue}.
Constructors are provided as static methods for common Java types, such as {@link LuaValue#valueOf(int)} or {@link LuaValue#valueOf(String)} to allow for instance pooling.
Constants are defined for the lua values {@link #NIL}, {@link #TRUE}, and {@link #FALSE}. A constant {@link #NONE} is defined which is a {@link Varargs} list having no values.
Operations are performed on values directly via their Java methods. For example, the following code divides two numbers:
{@code LuaValue a = LuaValue.valueOf( 5 ); LuaValue b = LuaValue.valueOf( 4 ); LuaValue c = a.div(b);}Note that in this example, c will be a {@link LuaDouble}, but would be a {@link LuaInteger} if the value of a were changed to 8, say. 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:
{@code 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 {@link invoke(Varargs)} or {@link invokemethod(LuaValue, Varargs)} methods:
{@code 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, {@link LoadState} is used:
{@code LoadState.load( new FileInputStream("main.lua"), "main.lua", globals ).call();}
although {@code require} could also be used:
{@code globals.get("require").call(LuaValue.valueOf("main"));}For this to work the file must be in the current directory, or in the class path, dependening on the platform. See {@link JsePlatform} and {@link JmePlatform} for details.
In general a {@link LuaError} may be thrown on any operation when the types supplied to any operation are illegal from a lua perspective. Examples could be attempting to concatenate a NIL value, or attempting arithmetic on values that are not number.
There are several methods for preinitializing tables, such as:
Predefined constants exist for the standard lua type constants {@link TNIL}, {@link TBOOLEAN}, {@link TLIGHTUSERDATA}, {@link TNUMBER}, {@link TSTRING}, {@link TTABLE}, {@link TFUNCTION}, {@link TUSERDATA}, {@link TTHREAD}, and extended lua type constants {@link TINT}, {@link TNONE}, {@link TVALUE}
Predefined constants exist for all strings used as metatags: {@link INDEX}, {@link NEWINDEX}, {@link CALL}, {@link MODE}, {@link METATABLE}, {@link ADD}, {@link SUB}, {@link DIV}, {@link MUL}, {@link POW}, {@link MOD}, {@link UNM}, {@link LEN}, {@link EQ}, {@link LT}, {@link LE}, {@link TOSTRING}, and {@link CONCAT}. @see JsePlatform @see JmePlatform @see LoadState @see Varargs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|