Package lukyt
Class LuaObject
java.lang.Object
lukyt.LuaObject
public class LuaObject
extends java.lang.Object
Java class wrapping a Lua value. Can be used for Lua interoptability.
-
Field Summary
Fields Modifier and Type Field Description static LuaObject_ENVTheLuaObjectcorresponding to the Lua variable_ENVstatic LuaObject_GTheLuaObjectcorresponding to the Lua variable_Gstatic LuaObjectFALSETheLuaObjectcorresponding to the Lua primitivefalseprotected longhandlestatic LuaObjectNILTheLuaObjectcorresponding to Luanilstatic LuaObjectTRUETheLuaObjectcorresponding to the Lua primitivetrue -
Constructor Summary
-
Method Summary
Modifier and Type Method Description booleanasBoolean()Returns this LuaObject as a primitivebooleanvalue.doubleasDouble()Returns this LuaObject as a primitivedoublevalue.
If the Lua object isn't anumber, this returns 0.longasLong()Returns this LuaObject as a primitivelongvalue.
If the Lua object isn't anumber, this returns 0.
The number is floored if necessary.java.lang.ObjectasObject()Returns this LuaObject as either a String, a Double, a Boolean or anullvalue.java.lang.StringasString()Returns this LuaObject as a String object.
If the Lua object isn't astring, this returns the result oftostring().booleanequals(java.lang.Object o)LuaObjectexecute()Execute this Lua Object as a function no arguments and return the first return value.LuaObjectexecute(LuaObject arg)Execute this Lua Object as a function with one argumentargand return the first return value.LuaObjectexecute(LuaObject[] args)Execute this Lua Object as a function with argumentsargsand return the first return value.LuaObject[]executeAll(LuaObject[] args)Execute this Lua Object as a function with argumentsargsand return all of its results as LuaObjects.LuaObjectexecuteChild(java.lang.String key)Execute the child with keykeyas a function with zero arguments.LuaObjectexecuteChild(java.lang.String key, LuaObject[] args)Execute the child with keykeyas a functionstatic LuaObjectfrom(java.lang.Object o)Auto-cast objectoto a LuaObject.static LuaObjectfromBoolean(boolean b)static LuaObjectfromDouble(double d)Cast a primitivedoublevalue to a LuaObject.static LuaObjectfromLong(long l)Cast a primitivelongvalue to a LuaObject.static LuaObjectfromString(java.lang.String str)Cast a String to a LuaObject.LuaObjectget(java.lang.String key)Returns theLuaObjectcorresponding to the child of the lua variable corresponding to this LuaObject.java.lang.StringgetType()booleanisArray()Returnstrueif this object only contains numerical keys.booleanisNil()booleanisTable()java.util.List<java.lang.String>keys()Returns the list of all the keys used in this Luatableobject.voidset(java.lang.String key, LuaObject lua)Set the child with this key to the lua variable corresponding to the givenLuaObject.java.util.List<LuaObject>values()Returns the list of all the values in this Luatableobject.
-
Field Details
-
handle
protected long handle -
_ENV
TheLuaObjectcorresponding to the Lua variable_ENV -
FALSE
TheLuaObjectcorresponding to the Lua primitivefalse -
TRUE
TheLuaObjectcorresponding to the Lua primitivetrue -
_G
TheLuaObjectcorresponding to the Lua variable_G -
NIL
TheLuaObjectcorresponding to Luanil
-
-
Constructor Details
-
Method Details
-
fromString
Cast a String to a LuaObject. -
fromLong
Cast a primitivelongvalue to a LuaObject. -
fromDouble
Cast a primitivedoublevalue to a LuaObject. -
fromBoolean
-
from
Auto-cast objectoto a LuaObject. Object must be one of:- Double
- Long
- Integer
- String
-
executeAll
Execute this Lua Object as a function with argumentsargsand return all of its results as LuaObjects. -
getType
public java.lang.String getType() -
asDouble
public double asDouble()Returns this LuaObject as a primitivedoublevalue.
If the Lua object isn't anumber, this returns 0. -
asLong
public long asLong()Returns this LuaObject as a primitivelongvalue.
If the Lua object isn't anumber, this returns 0.
The number is floored if necessary. -
asBoolean
public boolean asBoolean()Returns this LuaObject as a primitivebooleanvalue. -
asString
public java.lang.String asString()Returns this LuaObject as a String object.
If the Lua object isn't astring, this returns the result oftostring(). -
asObject
public java.lang.Object asObject()Returns this LuaObject as either a String, a Double, a Boolean or anullvalue. -
set
Set the child with this key to the lua variable corresponding to the givenLuaObject.- Parameters:
key- the key of the LuaObject to set
-
get
Returns theLuaObjectcorresponding to the child of the lua variable corresponding to this LuaObject.- Parameters:
key- the key of the LuaObject to get- Returns:
- the result
- Throws:
ChildNotFoundException- if the child is not found
-
executeChild
Execute the child with keykeyas a function- Parameters:
key- the key of the function to executeargs- the arguments of the function to execute- Returns:
- the first result of the function, or null if there isn't any
- Throws:
ChildNotFoundException- if the child is not foundjava.lang.TypeNotPresentException- if the child isn't a function
-
executeChild
Execute the child with keykeyas a function with zero arguments.- Parameters:
key- the key of the function to execute- Returns:
- the first result of the function, or null if there isn't any
- Throws:
ChildNotFoundException- if the child is not foundjava.lang.TypeNotPresentException- if the child isn't a function
-
keys
public java.util.List<java.lang.String> keys()Returns the list of all the keys used in this Luatableobject. -
values
Returns the list of all the values in this Luatableobject. -
isArray
public boolean isArray()Returnstrueif this object only contains numerical keys. The keys do not have to be in sequencial.
Example: {1, 2, 3, [5]=4} -> luaObject.isArray() ->true -
isNil
public boolean isNil() -
isTable
public boolean isTable() -
execute
Execute this Lua Object as a function no arguments and return the first return value. -
execute
Execute this Lua Object as a function with one argumentargand return the first return value. -
execute
Execute this Lua Object as a function with argumentsargsand return the first return value. -
equals
public boolean equals(java.lang.Object o)- Overrides:
equalsin classjava.lang.Object
-