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
_ENV
TheLuaObject
corresponding to the Lua variable_ENV
static LuaObject
_G
TheLuaObject
corresponding to the Lua variable_G
static LuaObject
FALSE
TheLuaObject
corresponding to the Lua primitivefalse
protected long
handle
static LuaObject
NIL
TheLuaObject
corresponding to Luanil
static LuaObject
TRUE
TheLuaObject
corresponding to the Lua primitivetrue
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description boolean
asBoolean()
Returns this LuaObject as a primitiveboolean
value.double
asDouble()
Returns this LuaObject as a primitivedouble
value.
If the Lua object isn't anumber
, this returns 0.long
asLong()
Returns this LuaObject as a primitivelong
value.
If the Lua object isn't anumber
, this returns 0.
The number is floored if necessary.java.lang.Object
asObject()
Returns this LuaObject as either a String, a Double, a Boolean or anull
value.java.lang.String
asString()
Returns this LuaObject as a String object.
If the Lua object isn't astring
, this returns the result oftostring()
.boolean
equals(java.lang.Object o)
LuaObject
execute()
Execute this Lua Object as a function no arguments and return the first return value.LuaObject
execute(LuaObject arg)
Execute this Lua Object as a function with one argumentarg
and return the first return value.LuaObject
execute(LuaObject[] args)
Execute this Lua Object as a function with argumentsargs
and return the first return value.LuaObject[]
executeAll(LuaObject[] args)
Execute this Lua Object as a function with argumentsargs
and return all of its results as LuaObjects.LuaObject
executeChild(java.lang.String key)
Execute the child with keykey
as a function with zero arguments.LuaObject
executeChild(java.lang.String key, LuaObject[] args)
Execute the child with keykey
as a functionstatic LuaObject
from(java.lang.Object o)
Auto-cast objecto
to a LuaObject.static LuaObject
fromBoolean(boolean b)
static LuaObject
fromDouble(double d)
Cast a primitivedouble
value to a LuaObject.static LuaObject
fromLong(long l)
Cast a primitivelong
value to a LuaObject.static LuaObject
fromString(java.lang.String str)
Cast a String to a LuaObject.LuaObject
get(java.lang.String key)
Returns theLuaObject
corresponding to the child of the lua variable corresponding to this LuaObject.java.lang.String
getType()
boolean
isArray()
Returnstrue
if this object only contains numerical keys.boolean
isNil()
boolean
isTable()
java.util.List<java.lang.String>
keys()
Returns the list of all the keys used in this Luatable
object.void
set(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 Luatable
object.
-
Field Details
-
handle
protected long handle -
_ENV
TheLuaObject
corresponding to the Lua variable_ENV
-
FALSE
TheLuaObject
corresponding to the Lua primitivefalse
-
TRUE
TheLuaObject
corresponding to the Lua primitivetrue
-
_G
TheLuaObject
corresponding to the Lua variable_G
-
NIL
TheLuaObject
corresponding to Luanil
-
-
Constructor Details
-
Method Details
-
fromString
Cast a String to a LuaObject. -
fromLong
Cast a primitivelong
value to a LuaObject. -
fromDouble
Cast a primitivedouble
value to a LuaObject. -
fromBoolean
-
from
Auto-cast objecto
to a LuaObject. Object must be one of:- Double
- Long
- Integer
- String
-
executeAll
Execute this Lua Object as a function with argumentsargs
and return all of its results as LuaObjects. -
getType
public java.lang.String getType() -
asDouble
public double asDouble()Returns this LuaObject as a primitivedouble
value.
If the Lua object isn't anumber
, this returns 0. -
asLong
public long asLong()Returns this LuaObject as a primitivelong
value.
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 primitiveboolean
value. -
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 anull
value. -
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 theLuaObject
corresponding 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 keykey
as 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 keykey
as 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 Luatable
object. -
values
Returns the list of all the values in this Luatable
object. -
isArray
public boolean isArray()Returnstrue
if 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 argumentarg
and return the first return value. -
execute
Execute this Lua Object as a function with argumentsargs
and return the first return value. -
equals
public boolean equals(java.lang.Object o)- Overrides:
equals
in classjava.lang.Object
-