EVENGINE_API_FOUNDATION public API. 更多...
#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. | |
| script::ScriptModuleResolver & | scriptModules () noexcept |
| Script module provider registry and dependency resolver for this VM. | |
| const script::ScriptModuleResolver & | scriptModules () const noexcept |
| Const script module resolver for diagnostics and graph inspection. | |
| script::ScriptCompiler & | scriptCompiler () noexcept |
| Unified EveScript compiler, metadata store, and binding contracts. | |
| const script::ScriptCompiler & | scriptCompiler () const noexcept |
| Const EveScript compiler and metadata store. | |
| 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. | |
| ssq::Object | createInstance (const std::string &name, const std::string &source={}) |
| Creates a live instance of a script class (default constructor). | |
| std::vector< ReflectedMember > | reflectInstance (const ssq::Object &instance) const |
| Inspects a live instance: own + inherited members with current values. | |
| ReflectedValue | readProperty (const ssq::Object &instance, const std::string &name) const |
| Reads one property of a live instance. | |
| bool | writeProperty (const ssq::Object &instance, const std::string &name, const ReflectedValue &value) const |
| Writes one property of a live instance. | |
| ssq::Object | readObjectProperty (const ssq::Object &instance, const std::string &name) const |
| Reads a live object-valued property (nested instance). | |
| size_t | arraySize (const ssq::Object &instance, const std::string &name) const |
| Element count of an array member (0 when missing/not an array). | |
| ReflectedValue | arrayGet (const ssq::Object &instance, const std::string &name, size_t index) const |
| Element value of an array member; empty when out of range. | |
| bool | arraySet (const ssq::Object &instance, const std::string &name, size_t index, const ReflectedValue &value) const |
| Replaces one element of an array member. | |
| bool | arrayAppend (const ssq::Object &instance, const std::string &name, const ReflectedValue &value) const |
| Appends an element to an array member. | |
| bool | arrayRemove (const ssq::Object &instance, const std::string &name, size_t index) const |
| Removes one element of an array member (shifts the rest). | |
| std::vector< std::string > | tableKeys (const ssq::Object &instance, const std::string &name) const |
| String keys of a table member. | |
| ReflectedValue | tableGet (const ssq::Object &instance, const std::string &name, const std::string &key) const |
| Value of a table member key; empty when missing. | |
| bool | tableSet (const ssq::Object &instance, const std::string &name, const std::string &key, const ReflectedValue &value) const |
| Sets a key of a table member (creates the key when missing). | |
| bool | tableRemove (const ssq::Object &instance, const std::string &name, const std::string &key) const |
| Removes a key from a table member. | |
| 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. | |
| size_t | scanClasses () |
| Scans the root table for script classes and refreshes reflection. | |
| ssq::Class | findClass (const std::string &name) const |
| Finds a script class by name (throws if it does not exist). | |
| std::string | classNameOf (const ssq::Object &instance) const |
| Name of the script class of a live instance ("" when unknown). | |
| 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 第 411 行定义.
引用了 handle().
◆ ~Runtime()
| eve::Runtime::~Runtime | ( | ) |
在文件 Runtime.cpp 第 419 行定义.
引用了 shutdown().
◆ Runtime() [2/3]
|
delete |
◆ Runtime() [3/3]
|
delete |
成员函数说明
◆ arrayAppend()
| bool eve::Runtime::arrayAppend | ( | const ssq::Object & | instance, |
| const std::string & | name, | ||
| const ReflectedValue & | value | ||
| ) | const |
Appends an element to an array member.
在文件 Runtime.cpp 第 870 行定义.
引用了 enter(), guard(), handle(), name, ok, scope , 以及 value.
被这些函数引用 eve::property_access::ReflectedPropertyModel::write().
◆ arrayGet()
| ReflectedValue eve::Runtime::arrayGet | ( | const ssq::Object & | instance, |
| const std::string & | name, | ||
| size_t | index | ||
| ) | const |
◆ arrayRemove()
| bool eve::Runtime::arrayRemove | ( | const ssq::Object & | instance, |
| const std::string & | name, | ||
| size_t | index | ||
| ) | const |
Removes one element of an array member (shifts the rest).
在文件 Runtime.cpp 第 887 行定义.
引用了 enter(), guard(), handle(), index, name, ok , 以及 scope.
被这些函数引用 eve::property_access::ReflectedPropertyModel::write().
◆ arraySet()
| bool eve::Runtime::arraySet | ( | const ssq::Object & | instance, |
| const std::string & | name, | ||
| size_t | index, | ||
| const ReflectedValue & | value | ||
| ) | const |
◆ arraySize()
| size_t eve::Runtime::arraySize | ( | const ssq::Object & | instance, |
| const std::string & | name | ||
| ) | const |
Element count of an array member (0 when missing/not an array).
在文件 Runtime.cpp 第 810 行定义.
引用了 enter(), guard(), handle(), name , 以及 scope.
被这些函数引用 eve::property_access::ReflectedPropertyModel::write().
◆ classNameOf()
| std::string eve::Runtime::classNameOf | ( | const ssq::Object & | instance | ) | const |
Name of the script class of a live instance ("" when unknown).
在文件 Runtime.cpp 第 1163 行定义.
引用了 enter(), guard(), handle(), scope , 以及 top.
被这些函数引用 eve::ui::Inspector::inspectObject() , 以及 eve::property_access::ReflectedPropertyModel::rebuildSchema().
◆ 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 第 523 行定义.
引用了 eve::Compile, enter(), error, EV_PARAM_CHECK, guard(), id, path , 以及 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 第 501 行定义.
引用了 eve::Compile, enter(), error, guard(), id, scope , 以及 source.
被这些函数引用 runSource() , 以及 eve::dev::LanguageServer::Impl::update().
◆ contains()
|
noexcept |
True if a script with the given id is tracked.
在文件 Runtime.cpp 第 1075 行定义.
◆ createInstance()
| ssq::Object eve::Runtime::createInstance | ( | const std::string & | name, |
| const std::string & | source = {} |
||
| ) |
Creates a live instance of a script class (default constructor).
- 参数
-
name Class name (must be non-empty). source Optional source label used in errors.
- 返回
- A rooted instance; the caller's ssq::Object releases it on destruction.
- 异常
-
ScriptException when the class is missing or the constructor fails.
在文件 Runtime.cpp 第 629 行定义.
引用了 eve::script::ScriptErrorContext::empty(), enter(), EV_PARAM_CHECK, guard(), handle(), label, eve::script::ScriptErrorContext::message, name, eve::Reflect, scope, source, eve::script::takeLastScriptError() , 以及 top.
被这些函数引用 eve::ui::Inspector::addInstance() , 以及 eve::ui::Inspector::selectClass().
◆ current()
|
staticnoexcept |
The runtime currently at the top of this thread's runtime stack, or nullptr.
在文件 Runtime.cpp 第 495 行定义.
◆ enter()
|
inline |
Pushes this runtime on the thread-local runtime stack (RAII pop).
被这些函数引用 arrayAppend(), arrayGet(), arrayRemove(), arraySet(), arraySize(), classNameOf(), compileFile(), compileSource(), createInstance(), execute(), eve::ModuleManager::expose_pending(), initialize(), readObjectProperty(), readProperty(), reflectClass(), reflectInstance(), scanClasses(), tableGet(), tableKeys(), tableRemove(), tableSet(), unload() , 以及 writeProperty().
◆ execute()
| const ScriptInfo & eve::Runtime::execute | ( | ScriptId | id | ) |
Runs a previously compiled script; throws ScriptException on failure.
在文件 Runtime.cpp 第 547 行定义.
引用了 eve::script::ScriptErrorContext::empty(), enter(), error, eve::Execute, eve::Failed, eve::script::formatScriptError(), found, guard(), handle(), id, eve::Loaded, eve::script::ScriptErrorContext::message, eve::script::peekLastScriptError(), pending, eve::Running, scope, 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 第 1157 行定义.
引用了 EV_PARAM_CHECK , 以及 name.
◆ guard()
|
inlinenoexcept |
RAII guard that restores the Squirrel stack top on scope exit.
被这些函数引用 arrayAppend(), arrayGet(), arrayRemove(), arraySet(), arraySize(), classNameOf(), compileFile(), compileSource(), createInstance(), execute(), initialize(), readObjectProperty(), readProperty(), reflectClass(), reflectInstance(), scanClasses(), tableGet(), tableKeys(), tableRemove(), tableSet(), unload() , 以及 writeProperty().
◆ handle()
|
noexcept |
Raw Squirrel VM handle; nullptr after shutdown.
在文件 Runtime.cpp 第 481 行定义.
被这些函数引用 arrayAppend(), arrayGet(), arrayRemove(), arraySet(), arraySize(), classNameOf(), createInstance(), execute(), initialize(), eve::ui::UI::inspectSetPickHandler(), readObjectProperty(), readProperty(), reflectInstance(), Runtime(), scanClasses(), eve::ui::UI::sceneSetPickHandler(), shutdown(), tableGet(), tableKeys(), tableRemove(), tableSet(), unload() , 以及 writeProperty().
◆ initialize()
| void eve::Runtime::initialize | ( | ) |
Exposes registered engine modules into the script root table. Safe to call more than once.
在文件 Runtime.cpp 第 421 行定义.
引用了 eve::ModuleManager::detach(), enter(), error, eve::Execute, eve::ModuleManager::expose(), eve::exposeReflection(), eve::script::formatLastScriptError(), guard(), handle(), scope , 以及 table().
◆ initialized()
|
noexcept |
True once initialize() has completed successfully.
在文件 Runtime.cpp 第 478 行定义.
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ readObjectProperty()
| ssq::Object eve::Runtime::readObjectProperty | ( | const ssq::Object & | instance, |
| const std::string & | name | ||
| ) | const |
◆ readProperty()
| ReflectedValue eve::Runtime::readProperty | ( | const ssq::Object & | instance, |
| const std::string & | name | ||
| ) | const |
Reads one property of a live instance.
- 返回
- Value snapshot; empty when the slot is missing.
在文件 Runtime.cpp 第 716 行定义.
引用了 enter(), guard(), handle(), name, scope , 以及 value.
被这些函数引用 eve::ui::DatabasePanel::build(), eve::ui::Inspector::build(), eve::property_access::ReflectedPropertyModel::read(), eve::ui::DatabasePanel::sync() , 以及 eve::property_access::ReflectedPropertyModel::write().
◆ 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 第 615 行定义.
引用了 cls, enter(), error, EV_PARAM_CHECK, guard(), name, eve::Reflect, scope , 以及 source.
◆ reflectedClass()
|
noexcept |
Reflected class by name, or nullptr.
在文件 Runtime.cpp 第 1092 行定义.
被这些函数引用 eve::ui::Inspector::build().
◆ reflectedClasses()
| std::vector< ReflectedClass > eve::Runtime::reflectedClasses | ( | ) | const |
◆ reflectFile()
|
inline |
◆ reflectInstance()
| std::vector< ReflectedMember > eve::Runtime::reflectInstance | ( | const ssq::Object & | instance | ) | const |
◆ reload()
| Runtime::ScriptId eve::Runtime::reload | ( | ScriptId | id | ) |
Recompiles and re-runs a script from its original source.
在文件 Runtime.cpp 第 1012 行定义.
引用了 eve::Compile, found, id, input, runFile(), runSource(), eve::ScriptException::source(), source , 以及 unload().
◆ root()
| ssq::Table eve::Runtime::root | ( | ) | const |
Root script table of the VM.
在文件 Runtime.cpp 第 488 行定义.
◆ runFile()
| Runtime::ScriptId eve::Runtime::runFile | ( | const std::string & | path | ) |
Convenience: compileFile() then execute().
在文件 Runtime.cpp 第 609 行定义.
引用了 compileFile(), execute(), id , 以及 path.
被这些函数引用 reload().
◆ runSource()
| Runtime::ScriptId eve::Runtime::runSource | ( | std::string | source, |
| std::string | sourceName = "buffer" |
||
| ) |
Convenience: compileSource() then execute().
在文件 Runtime.cpp 第 603 行定义.
引用了 compileSource(), execute(), id , 以及 source.
被这些函数引用 reload().
◆ scanClasses()
| size_t eve::Runtime::scanClasses | ( | ) |
Scans the root table for script classes and refreshes reflection.
Picks up classes defined through dofile()/compilestring() outside the Runtime API and re-inspects classes replaced by hot reload. Returns the number of classes that were (re)scanned.
在文件 Runtime.cpp 第 1107 行定义.
引用了 cls, enter(), guard(), handle(), info, scope , 以及 source.
◆ script()
|
noexcept |
◆ scriptCompiler() [1/2]
|
noexcept |
Const EveScript compiler and metadata store.
在文件 Runtime.cpp 第 487 行定义.
◆ scriptCompiler() [2/2]
|
noexcept |
Unified EveScript compiler, metadata store, and binding contracts.
在文件 Runtime.cpp 第 486 行定义.
被这些函数引用 eve::dev::LanguageServer::Impl::complete(), eve::dev::LanguageServer::Impl::diagnostics(), eve::dev::LanguageServer::Impl::hover() , 以及 eve::dev::LanguageServer::Impl::signatureHelp().
◆ scriptModules() [1/2]
|
noexcept |
Const script module resolver for diagnostics and graph inspection.
在文件 Runtime.cpp 第 483 行定义.
◆ scriptModules() [2/2]
|
noexcept |
Script module provider registry and dependency resolver for this VM.
在文件 Runtime.cpp 第 482 行定义.
◆ scripts()
| std::vector< ScriptInfo > eve::Runtime::scripts | ( | ) | const |
◆ setErrorHandler()
|
inline |
Replaces the handler invoked for script errors at the Runtime boundary.
引用了 handler.
被这些函数引用 eve::dev::DevTool::detach().
◆ setLifecycleHandler()
|
inline |
◆ shutdown()
|
noexcept |
Tears down the VM and detaches the runtime; idempotent and noexcept.
在文件 Runtime.cpp 第 450 行定义.
引用了 eve::script::clearLastScriptError(), eve::ModuleManager::detach(), handle(), eve::script::ISquirrelRootReleaser::releaseSquirrelRoots() , 以及 unloadAll().
被这些函数引用 ~Runtime().
◆ stackDepth()
|
staticnoexcept |
Depth of the thread-local runtime stack.
在文件 Runtime.cpp 第 499 行定义.
◆ 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 第 489 行定义.
引用了 EV_PARAM_CHECK , 以及 name.
被这些函数引用 initialize().
◆ tableGet()
| ReflectedValue eve::Runtime::tableGet | ( | const ssq::Object & | instance, |
| const std::string & | name, | ||
| const std::string & | key | ||
| ) | const |
◆ tableKeys()
| std::vector< std::string > eve::Runtime::tableKeys | ( | const ssq::Object & | instance, |
| const std::string & | name | ||
| ) | const |
String keys of a table member.
在文件 Runtime.cpp 第 910 行定义.
引用了 enter(), guard(), handle(), key, name , 以及 scope.
被这些函数引用 eve::property_access::ReflectedPropertyModel::write().
◆ tableRemove()
| bool eve::Runtime::tableRemove | ( | const ssq::Object & | instance, |
| const std::string & | name, | ||
| const std::string & | key | ||
| ) | const |
Removes a key from a table member.
在文件 Runtime.cpp 第 995 行定义.
引用了 enter(), guard(), handle(), key, name, ok , 以及 scope.
被这些函数引用 eve::property_access::ReflectedPropertyModel::write().
◆ tableSet()
| bool eve::Runtime::tableSet | ( | const ssq::Object & | instance, |
| const std::string & | name, | ||
| const std::string & | key, | ||
| const ReflectedValue & | value | ||
| ) | const |
◆ unload()
| bool eve::Runtime::unload | ( | ScriptId | id | ) |
Unloads a script and removes its declared classes; false if unknown/unloaded.
在文件 Runtime.cpp 第 1023 行定义.
引用了 eve::Runtime::ScriptRecord::class_objects, eve::Runtime::ScriptRecord::compiled, enter(), error, eve::ScriptInfo::error, eve::Failed, found, 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 第 480 行定义.
◆ vm() [2/2]
|
noexcept |
Underlying SimpleSquirrel VM (requires a live, initialized runtime).
在文件 Runtime.cpp 第 479 行定义.
被这些函数引用 execute() , 以及 eve::ModuleManager::expose().
◆ writeProperty()
| bool eve::Runtime::writeProperty | ( | const ssq::Object & | instance, |
| const std::string & | name, | ||
| const ReflectedValue & | value | ||
| ) | const |
Writes one property of a live instance.
The existing slot type is preserved (bool stays bool, integer stays integer, float stays float, string stays string); null slots take the type of the incoming value.
- 返回
- False when the member does not exist or is a method.
在文件 Runtime.cpp 第 732 行定义.
引用了 enter(), guard(), handle(), name, ok, scope, text , 以及 value.
被这些函数引用 eve::property_access::ReflectedPropertyModel::write().
该类的文档由以下文件生成:
- src/engine/common/Runtime.h
- src/engine/common/Runtime.cpp