#include <Runtime.h>
类 | |
| class | Scope |
| Pushes this Runtime on the current thread's runtime stack. 更多... | |
| struct | ScriptRecord |
| class | StackGuard |
| Restores the native Squirrel stack when a binding operation leaves scope. 更多... | |
Public 类型 | |
| using | ScriptId = uint64_t |
| using | ErrorHandler = std::function< void(const ScriptException &)> |
| using | LifecycleHandler = std::function< void(const ScriptInfo &)> |
Public 成员函数 | |
| Runtime (size_t stackSize=2048, ssq::Libs::Flag libraries=ssq::Libs::ALL) | |
| Creates a script runtime with its own Squirrel VM. | |
| ~Runtime () | |
| Runtime (Runtime &&)=delete | |
| Runtime & | operator= (Runtime &&)=delete |
| Runtime (const Runtime &)=delete | |
| Runtime & | operator= (const Runtime &)=delete |
| void | initialize () |
| Exposes registered engine modules into the script root table. Safe to call more than once. | |
| void | shutdown () noexcept |
| Tears down the VM and detaches the runtime; idempotent and noexcept. | |
| bool | initialized () const noexcept |
| True once initialize() has completed successfully. | |
| ssq::VM & | vm () noexcept |
| Underlying SimpleSquirrel VM (requires a live, initialized runtime). | |
| const ssq::VM & | vm () const noexcept |
| HSQUIRRELVM | handle () const noexcept |
| Raw Squirrel VM handle; nullptr after shutdown. | |
| ssq::Table | root () const |
| Root script table of the VM. | |
| ssq::Table | table (const char *name) const |
| Looks up a named global table. | |
| StackGuard | guard () noexcept |
| RAII guard that restores the Squirrel stack top on scope exit. | |
| Scope | enter () |
| Pushes this runtime on the thread-local runtime stack (RAII pop). | |
| ScriptId | compileSource (std::string source, std::string sourceName="buffer") |
| Compiles script source without running it. | |
| ScriptId | compileFile (const std::string &path) |
| Compiles a script file without running it. | |
| const ScriptInfo & | execute (ScriptId id) |
| Runs a previously compiled script; throws ScriptException on failure. | |
| ScriptId | runSource (std::string source, std::string sourceName="buffer") |
| Convenience: compileSource() then execute(). | |
| ScriptId | runFile (const std::string &path) |
| Convenience: compileFile() then execute(). | |
| ScriptId | reflectFile (const std::string &path) |
| Alias of runFile(); reflects classes declared by the file. | |
| const ReflectedClass & | reflectClass (const std::string &name, const std::string &source={}) |
| Reflects a class by name, storing its inspected members. | |
| ScriptId | reload (ScriptId id) |
| Recompiles and re-runs a script from its original source. | |
| bool | unload (ScriptId id) |
| Unloads a script and removes its declared classes; false if unknown/unloaded. | |
| void | unloadAll () noexcept |
| Unloads every script. | |
| bool | contains (ScriptId id) const noexcept |
| True if a script with the given id is tracked. | |
| const ScriptInfo * | script (ScriptId id) const noexcept |
| Script metadata for an id, or nullptr if unknown. | |
| std::vector< ScriptInfo > | scripts () const |
| Metadata for all tracked scripts, sorted by id. | |
| const ReflectedClass * | reflectedClass (const std::string &name) const noexcept |
| Reflected class by name, or nullptr. | |
| std::vector< ReflectedClass > | reflectedClasses () const |
| All reflected classes, sorted by name. | |
| ssq::Class | findClass (const std::string &name) const |
| Finds a script class by name (throws if it does not exist). | |
| void | setErrorHandler (ErrorHandler handler) |
| Replaces the handler invoked for script errors at the Runtime boundary. | |
| void | setLifecycleHandler (LifecycleHandler handler) |
| Replaces the handler notified on every script lifecycle change. | |
静态 Public 成员函数 | |
| static Runtime * | current () noexcept |
| The runtime currently at the top of this thread's runtime stack, or nullptr. | |
| static size_t | stackDepth () noexcept |
| Depth of the thread-local runtime stack. | |
详细描述
成员类型定义说明
◆ ErrorHandler
| using eve::Runtime::ErrorHandler = std::function<void(const ScriptException&)> |
◆ LifecycleHandler
| using eve::Runtime::LifecycleHandler = std::function<void(const ScriptInfo&)> |
◆ ScriptId
| using eve::Runtime::ScriptId = uint64_t |
构造及析构函数说明
◆ Runtime() [1/3]
|
explicit |
Creates a script runtime with its own Squirrel VM.
- 参数
-
stackSize Initial Squirrel stack size in slots (must be > 0). libraries Squirrel standard libraries to register (default: all).
在文件 Runtime.cpp 第 148 行定义.
◆ ~Runtime()
| eve::Runtime::~Runtime | ( | ) |
在文件 Runtime.cpp 第 153 行定义.
引用了 shutdown().
◆ Runtime() [2/3]
|
delete |
◆ Runtime() [3/3]
|
delete |
成员函数说明
◆ compileFile()
| Runtime::ScriptId eve::Runtime::compileFile | ( | const std::string & | path | ) |
Compiles a script file without running it.
- 参数
-
path File path (must be non-empty).
- 返回
- New script id.
- 异常
-
ScriptException on compile failure.
在文件 Runtime.cpp 第 233 行定义.
引用了 eve::Compile, enter(), error, EV_PARAM_CHECK, guard(), id , 以及 scope.
被这些函数引用 runFile().
◆ compileSource()
| Runtime::ScriptId eve::Runtime::compileSource | ( | std::string | source, |
| std::string | sourceName = "buffer" |
||
| ) |
Compiles script source without running it.
- 参数
-
source Script source text. sourceName Name used in errors and lifecycle events ("buffer" if omitted).
- 返回
- New script id.
- 异常
-
ScriptException on compile failure.
在文件 Runtime.cpp 第 211 行定义.
引用了 eve::Compile, enter(), error, guard(), id , 以及 scope.
被这些函数引用 runSource().
◆ contains()
|
noexcept |
True if a script with the given id is tracked.
在文件 Runtime.cpp 第 399 行定义.
◆ current()
|
staticnoexcept |
The runtime currently at the top of this thread's runtime stack, or nullptr.
在文件 Runtime.cpp 第 205 行定义.
◆ enter()
|
inline |
Pushes this runtime on the thread-local runtime stack (RAII pop).
被这些函数引用 compileFile(), compileSource(), execute(), eve::ModuleManager::expose_pending(), initialize(), reflectClass() , 以及 unload().
◆ execute()
| const ScriptInfo & eve::Runtime::execute | ( | ScriptId | id | ) |
Runs a previously compiled script; throws ScriptException on failure.
在文件 Runtime.cpp 第 257 行定义.
引用了 eve::script::ScriptErrorContext::empty(), enter(), error, eve::Execute, eve::Failed, eve::script::formatScriptError(), guard(), handle(), id, eve::Loaded, eve::script::ScriptErrorContext::message, eve::Running, scope, eve::script::takeLastScriptError(), eve::Unloaded , 以及 vm().
被这些函数引用 runFile() , 以及 runSource().
◆ findClass()
| ssq::Class eve::Runtime::findClass | ( | const std::string & | name | ) | const |
Finds a script class by name (throws if it does not exist).
在文件 Runtime.cpp 第 431 行定义.
引用了 EV_PARAM_CHECK , 以及 name.
◆ guard()
|
inlinenoexcept |
RAII guard that restores the Squirrel stack top on scope exit.
被这些函数引用 compileFile(), compileSource(), execute(), initialize(), reflectClass() , 以及 unload().
◆ handle()
|
noexcept |
Raw Squirrel VM handle; nullptr after shutdown.
在文件 Runtime.cpp 第 197 行定义.
被这些函数引用 execute(), shutdown() , 以及 unload().
◆ initialize()
| void eve::Runtime::initialize | ( | ) |
Exposes registered engine modules into the script root table. Safe to call more than once.
在文件 Runtime.cpp 第 155 行定义.
引用了 eve::ModuleManager::detach(), enter(), error, eve::Execute, eve::ModuleManager::expose(), guard() , 以及 scope.
被这些函数引用 eve::cmd::Cmdline::McpHost() , 以及 eve::cmd::Cmdline::Run().
◆ initialized()
|
noexcept |
True once initialize() has completed successfully.
在文件 Runtime.cpp 第 194 行定义.
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ reflectClass()
| const ReflectedClass & eve::Runtime::reflectClass | ( | const std::string & | name, |
| const std::string & | source = {} |
||
| ) |
Reflects a class by name, storing its inspected members.
- 参数
-
name Class name (must be non-empty). source Optional source label used in errors.
在文件 Runtime.cpp 第 323 行定义.
引用了 cls, enter(), error, EV_PARAM_CHECK, guard(), name, eve::Reflect , 以及 scope.
◆ reflectedClass()
|
noexcept |
◆ reflectedClasses()
| std::vector< ReflectedClass > eve::Runtime::reflectedClasses | ( | ) | const |
◆ reflectFile()
|
inline |
◆ reload()
| Runtime::ScriptId eve::Runtime::reload | ( | ScriptId | id | ) |
Recompiles and re-runs a script from its original source.
在文件 Runtime.cpp 第 337 行定义.
引用了 eve::Compile, id, runFile(), runSource(), eve::ScriptException::source() , 以及 unload().
◆ root()
| ssq::Table eve::Runtime::root | ( | ) | const |
◆ runFile()
| Runtime::ScriptId eve::Runtime::runFile | ( | const std::string & | path | ) |
Convenience: compileFile() then execute().
在文件 Runtime.cpp 第 317 行定义.
引用了 compileFile(), execute() , 以及 id.
被这些函数引用 reload().
◆ runSource()
| Runtime::ScriptId eve::Runtime::runSource | ( | std::string | source, |
| std::string | sourceName = "buffer" |
||
| ) |
Convenience: compileSource() then execute().
在文件 Runtime.cpp 第 311 行定义.
引用了 compileSource(), execute() , 以及 id.
被这些函数引用 reload() , 以及 eve::cmd::Cmdline::Run().
◆ script()
|
noexcept |
Script metadata for an id, or nullptr if unknown.
在文件 Runtime.cpp 第 401 行定义.
◆ scripts()
| std::vector< ScriptInfo > eve::Runtime::scripts | ( | ) | const |
◆ setErrorHandler()
|
inline |
◆ setLifecycleHandler()
|
inline |
◆ shutdown()
|
noexcept |
Tears down the VM and detaches the runtime; idempotent and noexcept.
在文件 Runtime.cpp 第 175 行定义.
引用了 eve::script::clearLastScriptError(), eve::ModuleManager::detach(), handle() , 以及 unloadAll().
被这些函数引用 ~Runtime().
◆ stackDepth()
|
staticnoexcept |
Depth of the thread-local runtime stack.
在文件 Runtime.cpp 第 209 行定义.
◆ table()
| ssq::Table eve::Runtime::table | ( | const char * | name | ) | const |
Looks up a named global table.
- 参数
-
name Name of the global table (must be non-null and non-empty).
在文件 Runtime.cpp 第 199 行定义.
引用了 EV_PARAM_CHECK , 以及 name.
被这些函数引用 eve::cmd::Cmdline::Run().
◆ unload()
| bool eve::Runtime::unload | ( | ScriptId | id | ) |
Unloads a script and removes its declared classes; false if unknown/unloaded.
在文件 Runtime.cpp 第 348 行定义.
引用了 eve::Runtime::ScriptRecord::class_objects, eve::Runtime::ScriptRecord::compiled, enter(), eve::ScriptInfo::error, error, eve::Failed, guard(), handle(), id, eve::Runtime::ScriptRecord::info, scope, eve::ScriptInfo::source, eve::ScriptInfo::state, eve::Unload, eve::Unloaded , 以及 eve::Unloading.
被这些函数引用 reload() , 以及 unloadAll().
◆ unloadAll()
|
noexcept |
◆ vm() [1/2]
|
noexcept |
在文件 Runtime.cpp 第 196 行定义.
◆ vm() [2/2]
|
noexcept |
Underlying SimpleSquirrel VM (requires a live, initialized runtime).
在文件 Runtime.cpp 第 195 行定义.
被这些函数引用 execute(), eve::ModuleManager::expose(), eve::cmd::Cmdline::McpHost() , 以及 eve::cmd::Cmdline::Run().
该类的文档由以下文件生成:
- src/engine/common/Runtime.h
- src/engine/common/Runtime.cpp