Toast Engine
Loading...
Searching...
No Matches
scripting::ScriptRuntime Class Reference

Public Member Functions

 ScriptRuntime (toast::Box< toast::Node > node, const std::vector< assets::Handle< assets::Script > > &scripts, uint64_t group=0, std::optional< size_t > placed=std::nullopt)
 ScriptRuntime (const ScriptRuntime &)=delete
auto operator= (const ScriptRuntime &) -> ScriptRuntime &=delete
void call (toast::TickFunctionList phase) noexcept
 Dispatch a TickFunctionList phase.
void call (std::string_view fn_name) noexcept
 Call a named function on all instances.
auto hasFunction (std::string_view fn_name) const noexcept -> bool
 True if any attached script instance exposes a callable field with this name.
auto functions () const noexcept -> std::vector< LuaFunctionDesc >
void callWithLuaStack (std::string_view name, lua_State *l, int args_base, int n_args) noexcept
auto callEventMethod (std::string_view name, lua_State *l, int event_index) noexcept -> bool
void callWithAnyArgs (std::string_view name, std::span< const std::any > args) noexcept
 Ccall with args provided as std::any values.
void setVar (std::string_view name, const std::any &value) noexcept
 Writes value to the variable named name.
auto getVar (std::string_view name) const noexcept -> std::any
 Reads the variable named name.
auto luaSignals () const -> std::vector< std::string >
auto luaSignalConnections (std::string_view name) const -> std::vector< signals::ConnectionInfo >
auto luaSignalArgTypes (std::string_view name) const -> std::vector< std::string >
auto connectLuaSignal (std::string_view name, toast::Node &target, std::string_view function, bool forwards_args) -> bool
auto disconnectLuaSignal (std::string_view name, toast::Node &target, std::string_view function) -> bool
void clearLuaSignal (std::string_view name)
auto instanceCount () const noexcept -> size_t
 Number of attached script instances.
auto instanceSchema (size_t index) const noexcept -> const ScriptSchema *
 Schema of one instance.
auto instanceScript (size_t index) const noexcept -> std::string_view
 Script asset path of one instance.
auto getVarByPath (size_t index, std::string_view path) const noexcept -> std::any
 Reads a variable of one instance through its schema path.
auto setVarByPath (size_t index, std::string_view path, const std::any &value) noexcept -> bool
 Writes a variable of one instance through its schema path.
auto schemaVersion () const noexcept -> uint32_t
 Unique for every runtime that was ever built, so it also tells a rebuilt runtime from the one it replaced.
auto hasTick (toast::TickFunctionList mask=toast::TickFunctionList::tick_mask) const noexcept -> bool
 True if any instance defines a function matching the given phases.
auto stateIndex () const noexcept -> size_t
 Index of the pooled Lua state this runtime is bound to.
auto token () const noexcept -> const std::shared_ptr< RuntimeToken > &
 Flips to dead as the runtime is torn down. Everything that calls into the scripts later holds it.
auto executing () const noexcept -> bool
 True while a call into this runtime is on some thread's stack.

Static Public Member Functions

static void retire (std::unique_ptr< ScriptRuntime > runtime) noexcept
 Destroys a runtime that may still be executing.
static void drainRetired () noexcept
 Destroys retired runtimes that finished executing; call from the main thread when no script is running.

Constructor & Destructor Documentation

◆ ScriptRuntime()

scripting::ScriptRuntime::ScriptRuntime ( toast::Box< toast::Node > node,
const std::vector< assets::Handle< assets::Script > > & scripts,
uint64_t group = 0,
std::optional< size_t > placed = std::nullopt )
Parameters
groupPlaces the runtime on the interpreter of its script group, 0 spreads runtimes round robin
placedAn interpreter LuaState::assign() already picked for this runtime, which the runtime takes over and gives back when it goes. It lets the caller know where the runtime will live before it is built
Here is the caller graph for this function:

Member Function Documentation

◆ retire()

void scripting::ScriptRuntime::retire ( std::unique_ptr< ScriptRuntime > runtime)
staticnoexcept

Destroys a runtime that may still be executing.

A runtime replaced from inside one of its own calls would be freed under its own stack frames. It waits in a list instead, and drainRetired() destroys it once nothing runs in it any more


The documentation for this class was generated from the following files:
  • engine/src/toast/scripting/script_runtime.hpp
  • engine/src/toast/scripting/script_runtime.cpp