Lua.VM.State (Lua v1.0.0-rc.0)
View SourceRuntime state for the Lua VM.
Summary
Functions
Allocates a fresh table in the state, returning {{:tref, id}, new_state}.
Allocates userdata and returns a reference.
Deletes a private value.
Returns the _G table reference.
Reads a global variable from the VM state. Returns nil if unset.
Retrieves a private value. Raises KeyError if the key doesn't exist.
Fetches a table by reference.
Gets userdata by reference.
Returns the underlying globals data map (read-only convenience).
Creates a new VM state.
Stores a private value not exposed to Lua.
Registers a native Elixir function as a global in the VM state.
Sets a global variable in the VM state.
Updates a table in-place via a function.
Types
@type t() :: %Lua.VM.State{ call_stack: list(), g_ref: nil | {:tref, non_neg_integer()}, metatables: map(), multi_return_count: non_neg_integer(), open_upvalues: term(), private: map(), table_next_id: non_neg_integer(), tables: %{optional(non_neg_integer()) => Lua.VM.Table.t()}, upvalue_cells: map(), userdata: %{optional(non_neg_integer()) => term()}, userdata_next_id: non_neg_integer() }
Functions
@spec alloc_table(t(), map()) :: {{:tref, non_neg_integer()}, t()}
Allocates a fresh table in the state, returning {{:tref, id}, new_state}.
@spec alloc_userdata(t(), term()) :: {{:udref, non_neg_integer()}, t()}
Allocates userdata and returns a reference.
Userdata stores arbitrary Elixir terms that can be passed through Lua but not directly manipulated by Lua code.
Deletes a private value.
@spec g_ref(t()) :: {:tref, non_neg_integer()}
Returns the _G table reference.
Reads a global variable from the VM state. Returns nil if unset.
Retrieves a private value. Raises KeyError if the key doesn't exist.
@spec get_table( t(), {:tref, non_neg_integer()} ) :: Lua.VM.Table.t()
Fetches a table by reference.
@spec get_userdata( t(), {:udref, non_neg_integer()} ) :: term()
Gets userdata by reference.
Returns the underlying globals data map (read-only convenience).
Equivalent to state._G.data. Avoid using this for state mutation —
use set_global/3 instead so that future invariants stay consistent.
@spec new() :: t()
Creates a new VM state.
Allocates an empty _G table to hold globals.
Stores a private value not exposed to Lua.
Registers a native Elixir function as a global in the VM state.
The function should accept (args, state) and return {results, state},
where args is a list of Lua values and results is a list of return values.
Sets a global variable in the VM state.
Writes into the _G table's data map. Globals storage lives entirely
inside the _G table since Plan A16 (Lua 5.3 _ENV semantics).
@spec update_table( t(), {:tref, non_neg_integer()}, (Lua.VM.Table.t() -> Lua.VM.Table.t()) ) :: t()
Updates a table in-place via a function.