LuaObject class

Implementers

Constructors

LuaObject(String id, {LuaFieldsMap? fields, Object? value, String? attr})
Default constructor for some lua object. The variable name in scope will become id and can have either fields or value but not both. Adopts the attribute attr.
LuaObject.func(String id, FuncExpr def, Function closure, [Scope? pscope])
Constructs a lua function with id for its function name in scope with some closure to be written to value. A required def is needed to determine the input arguments and other runtime information.
LuaObject.nil(String id, {String? attr})
Constructs a lua object with null values and fields. Adopts attributes attr.
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<Object, Object?>? fields, String? attr])
Constructs a lua object with id for its variable name in scope with some set of fields. These fields are dart Object values which means they can be primitives. Adopts the attribute attr.
LuaObject.tableFrom(String id, List<LuaObject> toFields, {String? attr})
A convenience factory constructor when the fields-to-be share the same exact name as the key in the output table. Calls LuaObject.table with the keys provided by LuaObject.id.
factory
LuaObject.variable(String id, Object? value, [String? attr])
Constructs a lua object with id for its variable name in scope with some initial value. Adopts the attribute attr.

Properties

arity int
Returns the arity of this object. For lua table length, see tableSize;
no setter
asMapEntry MapEntry<String, LuaObject>
Convenience util to project this lua object into a map entry keyed by its own id.
no setter
attr String?
If non-null, this is an attribute given to this variable.
final
doc LuaDoc?
If this object has html content, it may show up in the autodoc generation.
getter/setter pair
fields LuaFieldsMap?
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
isCallable bool
Query if this object's meta table has __call defined.
no setter
isFalsey bool
Query the negation of isTruthy.
no setter
isFunc bool
Query if this lua object has a Function stord in value. For the metamethod __call see isCallable.
no setter
isNil bool
A lua object is nil if both its value and fields are nil.
no setter
isNotCallable bool
Query if this object does not have __call defined in the meta table.
no setter
isNotFunc bool
Query the negation of isFunc.
no setter
isNotNil bool
Query the negation of isNil.
no setter
isNotTable bool
Query the negation of isTable.
no setter
isNotThread bool
Query the negation of isThread.
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
isThread bool
Query if the stored value is of type LuaThread.
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
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
scope Scope?
If this lua object is a function, it will have Scope to evaluate closures correctly.
getter/setter pair
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 key by one 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 internal LuaType based on if the following properties hold. Note that these are internal types and not directly from the lua spec.
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 execute the value closure if isFunction is true. 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>(Object 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.
getMetatable() LuaObject
Returns the _metatable or LuaObject.nil.
hasField(Object key) bool
Internal utility method to determine if this unpacked lua object is a table and has a field with value key.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onRead(dynamic callback(Object)?) → void
Whenever a lua object's fields or value is read, executes callback.
onWrite(dynamic callback(Object, 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(Object key) Object?
If this lua object is a table, then reads _fields by key and returns the value. Otherwise null is returned.
readMetatable(String key) Object?
If this lua object has a meta table then reads _metatable by string key and returns the value.
setMetatable(LuaObject mt) → void
Sets _metatable to mt overwriting any previous table.
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 perform strict type checks as-needed for known types.
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?
If value is int, then returns int. Otherwise, is null.
writeField(Object 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.
writeFieldFrom(LuaObject value) LuaObject
Given a LuaObject, adopt it as a field with the name given by LuaObject.id.
writeFields(LuaFieldsMap map) → void
A convenience utility to write all fields from some input map. This assumes you may need the name of the field to be different from any existing LuaObject.id in the entries.
writeFieldsFrom(List<LuaObject> luaObjects) → void
Given a list of LuaObject, adopt them as fields with their name given by LuaObject.id.

Operators

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