LuaObject class

Implementers

Constructors

LuaObject(String id, {LuaTable? fields, Object? value})
Default constructor for some lua object. The variable name in scope will become id and can have either fields or value but not both.
LuaObject.func(String id, FuncExpr def, Function closure)
Constructs a lua function with id for its function name in scope with some closure to be written to the metamethod '__call'. A required def is needed to determine the input arguments and other runtime information.
LuaObject.nil(String id)
Constructs a lua object with null values and fields.
LuaObject.noSemantics(String id)
Constructs a LuaObjectNoSemantics instance whose variable name in scope is id.
factory
LuaObject.ref(LuaObject src)
See toRef. Note that the runtime id will be prefixed with meta information to assist debugging call stacks.
LuaObject.table(String id, Map<String, Object?> fields)
Constructs a lua object with id for its variable name in scope with some set of fields.
LuaObject.variable(String id, Object? value)
Constructs a lua object with id for its variable name in scope with some initial value.

Properties

asMapEntry MapEntry<String, LuaObject>
Convenience util to project this lua object into a map entry keyed by its own id.
no setter
doc LuaDoc?
If this object has html content, it may show up in the autodoc generation.
getter/setter pair
fields LuaTable?
Returns the stored _fields value
no setter
funcDef FuncExpr?
If this lua object is a function, it will have FuncExpr node with information about its arguments.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
id String
The variable name. Note that if this instance is a value in a table, then the table may know it by a different name. See fields.
final
isFalsey bool
Query the negation of isTruthy.
no setter
isFunc bool
Query if this lua object is a table and has a field named '__call'.
no setter
isNil bool
A lua object is nil if both its value and fields are nil.
no setter
isNotFunc bool
Query the negation of isFunc.
no setter
isNotTable bool
Query the negation of isTable.
no setter
isPrintable bool
Query if std "print" can print the value. This is short for asking if the lua object is a table or a function, which would return the address in the VM at runtime for this lua obejct.
no setter
isRef bool
Query if the stored value is of type LuaObject.
no setter
isTable bool
A lua object is a table if its fields are non null.
no setter
isTruthy bool
In lua, all values have a truthyness which means they can be used in conditional statements. If value is null or false, then the result is false. All other values and the result is true. If this lua object is a table, then the result is true.
no setter
isValue bool
Query if the stored value is not a reference and the value is not null.
no setter
length int
Returns the arity of this object. For lua table length, see tableSize;
no setter
luaTypeInfo String
Returns the lua equivalent runtime type information. The result is the same as what lua type(x) would return. This is useful for quick type checking and printing helpful error messages.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
skipSemanitcs bool
A reference object to a LuaObjectNoSemantics type should be treated transitively as a LuaObjectNoSemantics type.
no setter
tableSize int
Begins at field "1" and increments this string until no field is found with that key. Returns the largest integer field found minus one. This mimics lua's table len (#) behavior.
no setter
type LuaType
Query the LuaType based on if the following properties hold:
no setter
typeinfo String
Returns the lua runtime type information. Unlike vanilla lua, this runtime comes with additional runtime semantics.
no setter
uses int
How often this object was read or written during evaluation. Can be used for optimization and reporting unused variables.
getter/setter pair
value Object?
Bumps uses by one and returns the stored _fields if a table or _value otherwise.
getter/setter pair

Methods

call() Object?
Attempts to find the metamethod '__call' and if found, executes its closure. Otherwise this throws an error.
deref() LuaObject
Unpacks a lua object if it holds a reference to another lua object during runtime. Otherwise if isRef is false, then it returns itself.
fieldValueAs<T>(String key, {T? or}) → T?
Inspects the result of readField with key. If the result's type is LuaObject, then it also inspects its this.value. If the underlying value type is T, then it is returned. If no underlying value type matches T, then or is returned.
hasField(String key) bool
Internal utility method to determine if this unpacked lua object is a table and has a field named key.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onRead(dynamic callback(String)?) → void
Whenever a lua object's fields or value is read, executes callback.
onWrite(dynamic callback(String, Object?)?) → void
Whenever a lua object's fields or value is modified (written), executes callback. If the lua object's storage is value, then the first argument of callback will be 'self'. Otherwise it is the string name of the field's key.
readField(String key) Object?
If this lua object is a table, unpacks _fields and returns the value. Otherwise null is returned.
tableInsert(int index, LuaObject value) LuaObject?
Convenience method to implement std table methods.
tableRemove(int index) LuaObject?
Convenience method to implement std table methods.
toRef() LuaObject
Creates and returns a LuaObject.ref instance of itself.
toString() String
Due to a dart bug, I cannot throw if we're converting a table or some other unknown data type to a string. Instead, unhandled types return their variable name wrapped in angle brackets <>. I'll check for string type conversion as-needed instead.
override
valueAs<T>() → T?
Inspects this.value. If the type is LuaObject, inspects its this.value. If the underlying value type is T, then it is returned. If no underlying value type matches T, the null is returned.
valueAsInt() int?
Tries to cast this.value as num and performs a lossy integer division to obtain the leading part of the double. If the leading part is equal to the double representation, the value must be a whole number and therefore an integer. Otherwise, loss happened and it must be a real number and therefore a double. If the underlying type of this.value is not num then null is returned.
writeField(String key, Object? value) Object?
If this lua object is a table, then it writes value to key and returns the field key. Otherwise if the lua object is not a table, then null is returned.
writeFields(LuaTable table) → void
A convenience utility to write all fields from some input table.

Operators

operator ==(Object other) bool
The equality operator.
inherited