LuaState abstract
Abstract base class for Lua state operations. Combines basic API, auxiliary library, coroutine support, and debug features.
Inheritance
Object → LuaBasicAPI → LuaState
Implemented types
Available Extensions
Constructors
LuaState()
Properties
hashCode no setter inherited
The hash code for this object.
A hash code is a single integer which represents the state of the object that affects operator == comparisons.
All objects have hash codes. The default hash code implemented by Object represents only the identity of the object, the same way as the default operator == implementation only considers objects equal if they are identical (see identityHashCode).
If operator == is overridden to use the object state instead, the hash code must also be changed to represent that state, otherwise the object cannot be used in hash based data structures like the default Set and Map implementations.
Hash codes must be the same for objects that are equal to each other according to operator ==. The hash code of an object should only change if the object changes in a way that affects equality. There are no further requirements for the hash codes. They need not be consistent between executions of the same program and there are no distribution guarantees.
Objects that are not equal are allowed to have the same hash code. It is even technically allowed that all instances have the same hash code, but if clashes happen too often, it may reduce the efficiency of hash-based data structures like HashSet or HashMap.
If a subclass overrides hashCode, it should override the operator == operator as well to maintain consistency.
Inherited from Object.
Implementation
external int get hashCode;runtimeType no setter inherited
A representation of the runtime type of the object.
Inherited from Object.
Implementation
external Type get runtimeType;Methods
absIndex() inherited
Inherited from LuaBasicAPI.
Implementation
int absIndex(int idx);argCheck() inherited
Inherited from LuaAuxLib.
Implementation
void argCheck(bool? cond, int arg, String extraMsg);argError() inherited
Inherited from LuaAuxLib.
Implementation
int argError(int arg, String extraMsg);arith() inherited
Inherited from LuaBasicAPI.
Implementation
void arith(ArithOp op);call() inherited
Inherited from LuaBasicAPI.
Implementation
void call(int nArgs, int nResults);callAsync() inherited
Asynchronously call a function. Use this when the function being called might be an async Dart function.
Inherited from LuaBasicAPI.
Implementation
Future<void> callAsync(int nArgs, int nResults);callCoroutineAsync() inherited
Async counterpart of call for the first invocation of a coroutine.
Like LuaBasicAPI.callAsync but additionally sets the _insideResumeAsync flag on the coroutine thread so that host async functions called via plain CALL (without await) inside the coroutine body are transparently awaited. Use this at the first resume of a coroutine where resumeAsync cannot be used because the closure has not yet started executing.
Inherited from LuaCoroutineLib.
Implementation
Future<void> callCoroutineAsync(int nArgs);callMeta() inherited
Inherited from LuaAuxLib.
Implementation
bool callMeta(int obj, String e);checkAny() inherited
Inherited from LuaAuxLib.
Implementation
void checkAny(int arg);checkInteger() inherited
Inherited from LuaAuxLib.
Implementation
int? checkInteger(int arg);checkNumber() inherited
Inherited from LuaAuxLib.
Implementation
double? checkNumber(int arg);checkStack() inherited
Inherited from LuaBasicAPI.
Implementation
bool checkStack(int n);checkStack2() inherited
Inherited from LuaAuxLib.
Implementation
void checkStack2(int sz, String msg);checkString() inherited
Inherited from LuaAuxLib.
Implementation
String? checkString(int arg);checkType() inherited
Inherited from LuaAuxLib.
Implementation
void checkType(int arg, LuaType t);clearThreadWeakRef() inherited
Clears weak references to dead threads.
Inherited from LuaCoroutineLib.
Implementation
void clearThreadWeakRef();compare() inherited
Inherited from LuaBasicAPI.
Implementation
bool compare(int idx1, int idx2, CmpOp op);concat() inherited
Inherited from LuaBasicAPI.
Implementation
void concat(int n);copy() inherited
Inherited from LuaBasicAPI.
Implementation
void copy(int fromIdx, int toIdx);createTable() inherited
Inherited from LuaBasicAPI.
Implementation
void createTable(int nArr, int nRec);debugThread() inherited
Returns debug information about all threads.
Inherited from LuaCoroutineLib.
Implementation
String debugThread();doFile() inherited
Inherited from LuaAuxLib.
Implementation
bool doFile(String filename);doFileAsync() inherited
Asynchronously execute a Lua file. Use this when the file might call async Dart functions.
Inherited from LuaAuxLib.
Implementation
Future<bool> doFileAsync(String filename);doString() inherited
Inherited from LuaAuxLib.
Implementation
bool doString(String str);doStringAsync() inherited
Asynchronously execute a Lua string. Use this when the code might call async Dart functions.
Inherited from LuaAuxLib.
Implementation
Future<bool> doStringAsync(String str);emit() inherited
Emit event synchronously, firing all registered listeners from both Dart and Lua sides.
args are passed to each listener. Only Dart-primitive types (null, bool, int, double, String) are automatically converted to Lua stack values when calling Lua listeners.
Normally, listeners must not mutate args. This will affect subsequent listeners.
Inherited from LuaEventAPI.
Implementation
void emit(String event, [List<dynamic> args = const []]);emitAsync() inherited
Emit event asynchronously, firing all registered listeners.
Async listeners (both Dart and Lua) are awaited. Sync listeners are called synchronously within the async flow.
Inherited from LuaEventAPI.
Implementation
Future<void> emitAsync(String event, [List<dynamic> args = const []]);error() inherited
Inherited from LuaBasicAPI.
Implementation
int error();error2() inherited
Inherited from LuaAuxLib.
Implementation
int error2(String fmt, [List<Object?>? a]);getCurrentNResults() inherited
Gets the number of expected results for current closure.
Inherited from LuaCoroutineLib.
Implementation
int getCurrentNResults();getField() inherited
Inherited from LuaBasicAPI.
Implementation
LuaType getField(int idx, String? k);getGlobal() inherited
Inherited from LuaBasicAPI.
Implementation
LuaType getGlobal(String name);getI() inherited
Inherited from LuaBasicAPI.
Implementation
LuaType getI(int idx, int i);getMetafield() inherited
Inherited from LuaAuxLib.
Implementation
LuaType getMetafield(int obj, String e);getMetatable() inherited
Inherited from LuaBasicAPI.
Implementation
bool getMetatable(int idx);getMetatableAux() inherited
Inherited from LuaAuxLib.
Implementation
LuaType getMetatableAux(String tname);getStatus() inherited
Gets the current thread status.
Inherited from LuaCoroutineLib.
Implementation
ThreadStatus getStatus();getSubTable() inherited
Inherited from LuaAuxLib.
Implementation
bool getSubTable(int idx, String fname);getTable() inherited
Inherited from LuaBasicAPI.
Implementation
LuaType getTable(int idx);getTop() inherited
Inherited from LuaBasicAPI.
Implementation
int getTop();insert() inherited
Inherited from LuaBasicAPI.
Implementation
void insert(int idx);isBoolean() inherited
Inherited from LuaBasicAPI.
Implementation
bool isBoolean(int idx);isDartFunction() inherited
Inherited from LuaBasicAPI.
Implementation
bool isDartFunction(int idx);isFunction() inherited
Inherited from LuaBasicAPI.
Implementation
bool isFunction(int idx);isInteger() inherited
Inherited from LuaBasicAPI.
Implementation
bool isInteger(int idx);isNil() inherited
Inherited from LuaBasicAPI.
Implementation
bool isNil(int idx);isNone() inherited
Inherited from LuaBasicAPI.
Implementation
bool isNone(int idx);isNoneOrNil() inherited
Inherited from LuaBasicAPI.
Implementation
bool isNoneOrNil(int idx);isNumber() inherited
Inherited from LuaBasicAPI.
Implementation
bool isNumber(int idx);isString() inherited
Inherited from LuaBasicAPI.
Implementation
bool isString(int idx);isTable() inherited
Inherited from LuaBasicAPI.
Implementation
bool isTable(int idx);isThread() inherited
Inherited from LuaBasicAPI.
Implementation
bool isThread(int idx);isUserdata() inherited
Inherited from LuaBasicAPI.
Implementation
bool isUserdata(int idx);len() inherited
Inherited from LuaBasicAPI.
Implementation
void len(int idx);len2() inherited
Inherited from LuaAuxLib.
Implementation
int? len2(int idx);load() inherited
Inherited from LuaBasicAPI.
Implementation
ThreadStatus load(Uint8List chunk, String chunkName, String? mode);loadFile() inherited
Inherited from LuaAuxLib.
Implementation
ThreadStatus loadFile(String? filename);loadFileX() inherited
Inherited from LuaAuxLib.
Implementation
ThreadStatus loadFileX(String? filename, String? mode);loadString() inherited
Inherited from LuaAuxLib.
Implementation
ThreadStatus loadString(String s);newLib() inherited
Inherited from LuaAuxLib.
Implementation
void newLib(Map<String, DartFunction?> l);newLibTable() inherited
Inherited from LuaAuxLib.
Implementation
void newLibTable(Map<String, DartFunction> l);newMetatable() inherited
Inherited from LuaAuxLib.
Implementation
bool newMetatable(String tname);newTable() inherited
Inherited from LuaBasicAPI.
Implementation
void newTable();newThread() inherited
Creates a new thread (coroutine) that shares the global environment.
Inherited from LuaCoroutineLib.
Implementation
LuaState newThread();newUserdata() inherited
Inherited from LuaBasicAPI.
Implementation
Userdata newUserdata<T>();next() inherited
Inherited from LuaBasicAPI.
Implementation
bool next(int idx);noSuchMethod() inherited
Invoked when a nonexistent method or property is accessed.
A dynamic member invocation can attempt to call a member which doesn't exist on the receiving object. Example:
dynamic object = 1;
object.add(42); // Statically allowed, run-time errorThis invalid code will invoke the noSuchMethod method of the integer 1 with an Invocation representing the .add(42) call and arguments (which then throws).
Classes can override noSuchMethod to provide custom behavior for such invalid dynamic invocations.
A class with a non-default noSuchMethod invocation can also omit implementations for members of its interface. Example:
class MockList<T> implements List<T> {
noSuchMethod(Invocation invocation) {
log(invocation);
super.noSuchMethod(invocation); // Will throw.
}
}
void main() {
MockList().add(42);
}This code has no compile-time warnings or errors even though the MockList class has no concrete implementation of any of the List interface methods. Calls to List methods are forwarded to noSuchMethod, so this code will log an invocation similar to Invocation.method(#add, [42]) and then throw.
If a value is returned from noSuchMethod, it becomes the result of the original invocation. If the value is not of a type that can be returned by the original invocation, a type error occurs at the invocation.
The default behavior is to throw a NoSuchMethodError.
Inherited from Object.
Implementation
@pragma("vm:entry-point")
@pragma("wasm:entry-point")
external dynamic noSuchMethod(Invocation invocation);off() inherited
Remove a listener from event.
If callback is provided, removes the first sync Dart listener whose callback matches by reference equality. If asyncCallback is provided, removes the first async Dart listener whose callback matches by reference equality. If listenerId is provided, removes the listener with that id regardless of event name.
Inherited from LuaEventAPI.
Implementation
void off(String event,
{EventCallback? callback,
EventCallbackAsync? asyncCallback,
int? listenerId});offById() inherited
Remove a listener by its unique id.
Inherited from LuaEventAPI.
Implementation
void offById(int listenerId);on() inherited
Register a synchronous Dart listener for event. Returns a listener id that can be passed to offById.
Inherited from LuaEventAPI.
Implementation
int on(String event, EventCallback callback);onAsync() inherited
Register an asynchronous Dart listener for event. Returns a listener id that can be passed to offById.
Inherited from LuaEventAPI.
Implementation
int onAsync(String event, EventCallbackAsync callback);once() inherited
Register a one-time synchronous Dart listener for event. The listener is automatically removed after its first invocation. Returns a listener id.
Inherited from LuaEventAPI.
Implementation
int once(String event, EventCallback callback);openLibs() inherited
Inherited from LuaAuxLib.
Implementation
void openLibs();optInteger() inherited
Inherited from LuaAuxLib.
Implementation
int? optInteger(int arg, int? d);optNumber() inherited
Inherited from LuaAuxLib.
Implementation
double? optNumber(int arg, double d);optString() inherited
Inherited from LuaAuxLib.
Implementation
String? optString(int arg, String d);pCall() inherited
Inherited from LuaBasicAPI.
Implementation
ThreadStatus pCall(int nArgs, int nResults, int msgh);pCallAsync() inherited
Asynchronously call a function in protected mode. Use this when the function being called might be an async Dart function.
Inherited from LuaBasicAPI.
Implementation
Future<ThreadStatus> pCallAsync(int nArgs, int nResults, int msgh);pop() inherited
Inherited from LuaBasicAPI.
Implementation
void pop(int n);popObject() inherited
Pops and returns the top value from the stack as a Dart object.
Inherited from LuaCoroutineLib.
Implementation
Object? popObject();popStackFrame() inherited
Pops the top stack frame (used after yield is caught).
Inherited from LuaCoroutineLib.
Implementation
void popStackFrame();printStack() extension
Available on LuaState, provided by the LuaStateDebug extension
Implementation
void printStack() {
print(">------ stack top ------<");
var len = getTop();
for (int i = len; i >= 1; i--) {
LuaType t = type(i);
switch (type(i)) {
case LuaType.luaNone:
_print(i, t);
break;
case LuaType.luaNil:
_print(i, t);
break;
case LuaType.luaBoolean:
_print(i, t, toBoolean(i) ? "true" : "false");
break;
case LuaType.luaLightUserdata:
_print(i, t);
break;
case LuaType.luaNumber:
if (isInteger(i)) {
_print(i, t, "(integer)${toInteger(i)}");
} else if (isNumber(i)) {
_print(i, t, "${toNumber(i)}");
}
break;
case LuaType.luaString:
_print(i, t, "${toStr(i)}");
break;
case LuaType.luaTable:
_print(i, t);
break;
case LuaType.luaFunction:
_print(i, t);
break;
case LuaType.luaUserdata:
_print(i, t);
break;
case LuaType.luaThread:
_print(i, t);
break;
// default:
// _print(i, t, typeName(t));
// break;
}
}
print(">------ stack bottom ------<");
}pushBoolean() inherited
Inherited from LuaBasicAPI.
Implementation
void pushBoolean(bool b);pushDartClosure() inherited
Inherited from LuaBasicAPI.
Implementation
void pushDartClosure(DartFunction f, int n);pushDartClosureAsync() inherited
Push an async Dart closure onto the stack with upvalues. name is an optional human-readable name used to format the "attempt to call async function name without await or in non-async context" runtime error message.
Inherited from LuaBasicAPI.
Implementation
void pushDartClosureAsync(DartFunctionAsync f, int n, [String? name]);pushDartFunction() inherited
Inherited from LuaBasicAPI.
Implementation
void pushDartFunction(DartFunction f);pushDartFunctionAsync() inherited
Push an async Dart function onto the stack. name is an optional human-readable name used to format the "attempt to call async function name without await or in non-async context" runtime error message.
Inherited from LuaBasicAPI.
Implementation
void pushDartFunctionAsync(DartFunctionAsync f, [String? name]);pushFString() inherited
Inherited from LuaBasicAPI.
Implementation
void pushFString(String fmt, [List<Object>? a]);pushGlobalTable() inherited
Inherited from LuaBasicAPI.
Implementation
void pushGlobalTable();pushInteger() inherited
Inherited from LuaBasicAPI.
Implementation
void pushInteger(int? n);pushNil() inherited
Inherited from LuaBasicAPI.
Implementation
void pushNil();pushNumber() inherited
Inherited from LuaBasicAPI.
Implementation
void pushNumber(double n);pushString() inherited
Inherited from LuaBasicAPI.
Implementation
void pushString(String? s);pushThread() inherited
Pushes a thread onto the stack.
Inherited from LuaCoroutineLib.
Implementation
void pushThread(LuaState L);pushValue() inherited
Inherited from LuaBasicAPI.
Implementation
void pushValue(int idx);rawEqual() inherited
Inherited from LuaBasicAPI.
Implementation
bool rawEqual(int idx1, int idx2);rawGet() inherited
Inherited from LuaBasicAPI.
Implementation
LuaType rawGet(int idx);rawGetI() inherited
Inherited from LuaBasicAPI.
Implementation
LuaType rawGetI(int idx, int i);rawLen() inherited
Inherited from LuaBasicAPI.
Implementation
int rawLen(int idx);rawSet() inherited
Inherited from LuaBasicAPI.
Implementation
void rawSet(int idx);rawSetI() inherited
Inherited from LuaBasicAPI.
Implementation
void rawSetI(int idx, int i);ref() inherited
Inherited from LuaAuxLib.
Implementation
int ref(int t);register() inherited
Inherited from LuaBasicAPI.
Implementation
void register(String name, DartFunction f);registerAsync() inherited
Register an async Dart function as a global function.
Inherited from LuaAuxLib.
Implementation
void registerAsync(String name, DartFunctionAsync f);remove() inherited
Inherited from LuaBasicAPI.
Implementation
void remove(int idx);removeAllListeners() inherited
Remove all listeners for event, or all listeners for all events if event is null.
WARNING: Removing all listeners is a dangerous operation. Use at your own risk.
Inherited from LuaEventAPI.
Implementation
void removeAllListeners([String? event]);replace() inherited
Inherited from LuaBasicAPI.
Implementation
void replace(int idx);requireF() inherited
Inherited from LuaAuxLib.
Implementation
void requireF(String modname, DartFunction openf, bool glb);resetTopClosureNResults() inherited
Resets the expected number of results for the top closure.
Inherited from LuaCoroutineLib.
Implementation
void resetTopClosureNResults(int nResults);resume() inherited
Resumes a suspended coroutine.
Inherited from LuaCoroutineLib.
Implementation
void resume(int nArgs);resumeAsync() inherited
Asynchronously resumes a suspended coroutine.
Use this when the coroutine body may call host-registered async functions (registered via LuaAuxLib.registerAsync) without the await keyword. The async dispatch in LuaStateImpl treats the coroutine thread as the suspension point, so async calls inside the coroutine body are awaited transparently.
Inherited from LuaCoroutineLib.
Implementation
Future<void> resumeAsync(int nArgs);rotate() inherited
Inherited from LuaBasicAPI.
Implementation
void rotate(int idx, int n);runningId() inherited
Returns the unique ID of this thread.
Inherited from LuaCoroutineLib.
Implementation
int runningId();setField() inherited
Inherited from LuaBasicAPI.
Implementation
void setField(int idx, String? k);setFuncs() inherited
Inherited from LuaAuxLib.
Implementation
void setFuncs(Map<String, DartFunction?> l, int nup);setGlobal() inherited
Inherited from LuaBasicAPI.
Implementation
void setGlobal(String name);setHook() inherited
Sets a debug hook.
Inherited from LuaDebug.
Implementation
void setHook(HookContext context);setI() inherited
Inherited from LuaBasicAPI.
Implementation
void setI(int idx, int? i);setMetatable() inherited
Inherited from LuaBasicAPI.
Implementation
void setMetatable(int idx);setMetatableAux() inherited
Inherited from LuaAuxLib.
Implementation
void setMetatableAux(String tname);setStatus() inherited
Sets the thread status.
Inherited from LuaCoroutineLib.
Implementation
void setStatus(ThreadStatus status);setTable() inherited
Inherited from LuaBasicAPI.
Implementation
void setTable(int idx);setTop() inherited
Inherited from LuaBasicAPI.
Implementation
void setTop(int idx);stringToNumber() inherited
Inherited from LuaBasicAPI.
Implementation
bool stringToNumber(String s);toBoolean() inherited
Inherited from LuaBasicAPI.
Implementation
bool toBoolean(int idx);toDartFunction() inherited
Inherited from LuaBasicAPI.
Implementation
DartFunction? toDartFunction(int idx);toInteger() inherited
Inherited from LuaBasicAPI.
Implementation
int toInteger(int idx);toIntegerX() inherited
Inherited from LuaBasicAPI.
Implementation
int? toIntegerX(int idx);toNumber() inherited
Inherited from LuaBasicAPI.
Implementation
double toNumber(int idx);toNumberX() inherited
Inherited from LuaBasicAPI.
Implementation
double? toNumberX(int idx);toPointer() inherited
Inherited from LuaBasicAPI.
Implementation
Object? toPointer(int idx);toStr() inherited
Inherited from LuaBasicAPI.
Implementation
String? toStr(int idx);toString() inherited
A string representation of this object.
Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.
Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.
Inherited from Object.
Implementation
external String toString();toString2() inherited
Inherited from LuaAuxLib.
Implementation
String? toString2(int idx);toThread() inherited
Converts the value at the given index to a Lua thread (coroutine). Returns null if the value is not a thread.
Inherited from LuaCoroutineLib.
Implementation
LuaState? toThread(int idx);toUserdata() inherited
Inherited from LuaBasicAPI.
Implementation
Userdata? toUserdata<T>(int idx);traceStack() inherited
Returns a stack trace for debugging.
Inherited from LuaCoroutineLib.
Implementation
String traceStack();type() inherited
Inherited from LuaBasicAPI.
Implementation
LuaType type(int idx);typeName() inherited
Inherited from LuaBasicAPI.
Implementation
String typeName(LuaType tp);typeName2() inherited
Inherited from LuaAuxLib.
Implementation
String typeName2(int idx);unRef() inherited
Inherited from LuaAuxLib.
Implementation
void unRef(int t, int ref);xmove() inherited
Moves n values from one state to another. Pops the values from 'from' and pushes them to this state.
Inherited from LuaCoroutineLib.
Implementation
void xmove(LuaState from, int n);Operators
operator ==() inherited
The equality operator.
The default behavior for all Objects is to return true if and only if this object and other are the same object.
Override this method to specify a different equality relation on a class. The overriding method must still be an equivalence relation. That is, it must be:
Total: It must return a boolean for all arguments. It should never throw.
Reflexive: For all objects
o,o == omust be true.Symmetric: For all objects
o1ando2,o1 == o2ando2 == o1must either both be true, or both be false.Transitive: For all objects
o1,o2, ando3, ifo1 == o2ando2 == o3are true, theno1 == o3must be true.
The method should also be consistent over time, so whether two objects are equal should only change if at least one of the objects was modified.
If a subclass overrides the equality operator, it should override the hashCode method as well to maintain consistency.
Inherited from Object.
Implementation
external bool operator ==(Object other);Static Methods
newState()
Implementation
static LuaState newState() {
return LuaStateImpl();
}