LuaState class
Wrapper class for simplifying interaction with Lua states,
LuaState does not contain any state information by itself and is only a wrapper around the Fengari binding's lua_State.
Please note that this wrapper makes many ease of use to performance tradeoffs, interacting with the lua state directly through fengari_api will be significantly more performant.
Constructors
- LuaState({bool openlibs = true})
- Creates a new lua_State and wraps it.
- LuaState.wrap(lua_State lua_state)
- Wraps an existing Lua state.
Properties
Methods
-
at(
[int index = -1]) → dynamic -
Returns the stack value at
index
and converts it to the equivalent Dart type. -
call(
[Iterable args = const [], int results = -1]) → List - Pops a value and calls it, may throw a LuaException.
-
close(
) → void - Closes the Lua state
-
dup(
[int index = -1]) → void -
Pushes the value at
index
. -
isNil(
[int index = -1]) → bool -
Checks if the value at
index
is nil. -
isNone(
[int index = -1]) → bool -
Checks if
index
is a valid stack index. -
isNoneOrNil(
[int index = -1]) → bool -
Checks if the value at
index
is nil or if the index is invalid. -
isNumber(
[int index = -1]) → bool -
Checks if the value at
index
is a number. -
isString(
[int index = -1]) → bool -
Checks if the value at
index
is a string. -
isTable(
[int index = -1]) → bool -
Checks if the value at
index
is a table. -
isThread(
[int index = -1]) → bool -
Checks if the value at
index
is a thread. -
isUserdata(
[int index = -1]) → bool -
Checks if the value at
index
is userdata. -
isYieldable(
) → bool - Checks if the current thread is yieldable.
-
len(
int index) → int -
Returns the length of the value at
index
, equivalent to the # operator. -
load(
List< int> data) → void - Loads code from a buffer whether it be Lua or compiled bytecode and pushes the resulting lua function to the stack.
-
loadString(
String string) → void - Same as LuaState.load but loads from a String instead.
-
newTable(
) → void - Pushes a new, empty table to the stack.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pop(
[int count = 1]) → void - Pops a number of values from the stack, discarding them.
-
popString(
) → String -
Converts the top to a string and pops it, use this instead of
pop().toString()
. -
popStrings(
int n) → List< String> - Same as LuaState.popString but for multiple values.
-
popValue(
) → dynamic - Pops a single value from the stack, returning it.
-
popValues(
int count) → List - Pops a number of values from the stack and returns a list of those values.
-
push(
dynamic value) → void - Pushes a value to the stack, automatically converting Dart types to their equivalent Lua counterparts.
-
pushAll(
Iterable values) → void - Same as LuaState.push but pushes multiple values.
-
pushGlobal(
dynamic key) → void -
Pushes the global variable from a
key
to the stack. -
pushGlobalTable(
) → void - Pushes the global table (_G) to the stack.
-
pushThread(
) → void - Pushes the current thread (coroutine) to the stack.
-
rawLen(
int index) → int -
Returns the raw length of the value at
index
. -
remove(
int index) → void - Removes a value in the stack at a specific index, shifting values above it down to fill the gap.
-
replace(
int index) → void -
Pops a value from the stack and moves it to
index
, replacing the value in its place. -
requiref(
String modname, dynamic fn, [bool global = true]) → void - Loads library if not loaded already and pushes it on the stack.
-
rotate(
int index, int n) → void -
Rotates stack elements between
index
and the top of stackn
positions. -
setGlobal(
dynamic key) → void -
Pops a value from the stack and sets the global at
key
to it. -
tableGet(
[int tableIndex = -2]) → void -
Pops a key and pushes the value in the table at
tableIndex
. -
tableGetRaw(
[int tableIndex = -2]) → void - Same as LuaState.tableGet but does not invoke any metamethods.
-
tableSet(
[int tableIndex = -3]) → void -
Pops a key and value, then adds those to the table at
tableIndex
. -
tableSetMeta(
[int index = -2]) → void -
Pops a table from the stack and sets it as the metatable for
the value at
index
-
tableSetRaw(
[int tableIndex = -3]) → void - Same as LuaState.tableSet but does not invoke any metamethods.
-
toString(
) → String -
A string representation of this object.
inherited
-
tryLoad(
List< int> data) → bool - Similar to LuaState.load but returns false on an error instead of throwing an exception.
-
tryLoadstring(
String string) → bool - Same as LuaState.tryLoad but loads from a String instead.
-
values(
int count, [int? start]) → List -
Gets
count
number of values in the stack, starting atstart
. -
xmove(
LuaState to, int count) → void -
Pops
count
values from current LuaState and pushes them all onto the stack of the target LuaState.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
-
operator [](
int index) → dynamic - Same as LuaState.at.
-
operator []=(
int index, dynamic value) → void -
Sets the value in the stack at
index
tovalue
.