载入中...
搜索中...
未找到

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.
 

详细描述

EVENGINE_API_FOUNDATION public API.

在文件 Runtime.h 第 189 行定义.

成员类型定义说明

◆ ErrorHandler

using eve::Runtime::ErrorHandler = std::function<void(const ScriptException&)>

在文件 Runtime.h 第 192 行定义.

◆ LifecycleHandler

using eve::Runtime::LifecycleHandler = std::function<void(const ScriptInfo&)>

在文件 Runtime.h 第 193 行定义.

◆ ScriptId

using eve::Runtime::ScriptId = uint64_t

在文件 Runtime.h 第 191 行定义.

构造及析构函数说明

◆ Runtime() [1/3]

eve::Runtime::Runtime ( size_t  stackSize = 2048,
ssq::Libs::Flag  libraries = ssq::Libs::ALL 
)
explicit

Creates a script runtime with its own Squirrel VM.

参数
stackSizeInitial Squirrel stack size in slots (must be > 0).
librariesSquirrel standard libraries to register (default: all).

在文件 Runtime.cpp 第 411 行定义.

引用了 handle().

◆ ~Runtime()

eve::Runtime::~Runtime ( )

在文件 Runtime.cpp 第 419 行定义.

引用了 shutdown().

◆ Runtime() [2/3]

eve::Runtime::Runtime ( Runtime &&  )
delete

◆ Runtime() [3/3]

eve::Runtime::Runtime ( const Runtime &  )
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

Element value of an array member; empty when out of range.

在文件 Runtime.cpp 第 826 行定义.

引用了 enter(), guard(), handle(), index, name, scope , 以及 value.

◆ 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

Replaces one element of an array member.

在文件 Runtime.cpp 第 846 行定义.

引用了 enter(), guard(), handle(), index, name, ok, scope , 以及 value.

被这些函数引用 eve::property_access::ReflectedPropertyModel::write().

◆ 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.

参数
pathFile path (must be non-empty).
返回
New script id.
异常
ScriptExceptionon 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.

参数
sourceScript source text.
sourceNameName used in errors and lifecycle events ("buffer" if omitted).
返回
New script id.
异常
ScriptExceptionon compile failure.

在文件 Runtime.cpp 第 501 行定义.

引用了 eve::Compile, enter(), error, guard(), id, scope , 以及 source.

被这些函数引用 runSource() , 以及 eve::dev::LanguageServer::Impl::update().

◆ contains()

bool eve::Runtime::contains ( ScriptId  id) const
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).

参数
nameClass name (must be non-empty).
sourceOptional source label used in errors.
返回
A rooted instance; the caller's ssq::Object releases it on destruction.
异常
ScriptExceptionwhen 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()

Runtime * eve::Runtime::current ( )
staticnoexcept

The runtime currently at the top of this thread's runtime stack, or nullptr.

在文件 Runtime.cpp 第 495 行定义.

◆ enter()

◆ execute()

◆ 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()

StackGuard eve::Runtime::guard ( )
inlinenoexcept

◆ handle()

◆ 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()

bool eve::Runtime::initialized ( ) const
noexcept

True once initialize() has completed successfully.

在文件 Runtime.cpp 第 478 行定义.

◆ operator=() [1/2]

Runtime & eve::Runtime::operator= ( const Runtime &  )
delete

◆ operator=() [2/2]

Runtime & eve::Runtime::operator= ( Runtime &&  )
delete

◆ readObjectProperty()

ssq::Object eve::Runtime::readObjectProperty ( const ssq::Object &  instance,
const std::string &  name 
) const

Reads a live object-valued property (nested instance).

返回
The rooted nested instance; an empty object when the slot is missing or not an instance.

在文件 Runtime.cpp 第 791 行定义.

引用了 enter(), guard(), handle(), name , 以及 scope.

◆ 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.

参数
nameClass name (must be non-empty).
sourceOptional source label used in errors.

在文件 Runtime.cpp 第 615 行定义.

引用了 cls, enter(), error, EV_PARAM_CHECK, guard(), name, eve::Reflect, scope , 以及 source.

◆ reflectedClass()

const ReflectedClass * eve::Runtime::reflectedClass ( const std::string &  name) const
noexcept

Reflected class by name, or nullptr.

在文件 Runtime.cpp 第 1092 行定义.

引用了 found , 以及 name.

被这些函数引用 eve::ui::Inspector::build().

◆ reflectedClasses()

std::vector< ReflectedClass > eve::Runtime::reflectedClasses ( ) const

All reflected classes, sorted by name.

在文件 Runtime.cpp 第 1097 行定义.

引用了 a , 以及 b.

◆ reflectFile()

ScriptId eve::Runtime::reflectFile ( const std::string &  path)
inline

Alias of runFile(); reflects classes declared by the file.

在文件 Runtime.h 第 307 行定义.

引用了 path.

◆ reflectInstance()

std::vector< ReflectedMember > eve::Runtime::reflectInstance ( const ssq::Object &  instance) const

Inspects a live instance: own + inherited members with current values.

参数
instanceLive script instance.

在文件 Runtime.cpp 第 669 行定义.

引用了 enter(), guard(), handle(), m, member, members, scope , 以及 top.

被这些函数引用 eve::property_access::ReflectedPropertyModel::rebuildSchema().

◆ 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()

const ScriptInfo * eve::Runtime::script ( ScriptId  id) const
noexcept

Script metadata for an id, or nullptr if unknown.

在文件 Runtime.cpp 第 1077 行定义.

引用了 found.

◆ scriptCompiler() [1/2]

const script::ScriptCompiler & eve::Runtime::scriptCompiler ( ) const
noexcept

Const EveScript compiler and metadata store.

在文件 Runtime.cpp 第 487 行定义.

◆ scriptCompiler() [2/2]

script::ScriptCompiler & eve::Runtime::scriptCompiler ( )
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]

const script::ScriptModuleResolver & eve::Runtime::scriptModules ( ) const
noexcept

Const script module resolver for diagnostics and graph inspection.

在文件 Runtime.cpp 第 483 行定义.

◆ scriptModules() [2/2]

script::ScriptModuleResolver & eve::Runtime::scriptModules ( )
noexcept

Script module provider registry and dependency resolver for this VM.

在文件 Runtime.cpp 第 482 行定义.

被这些函数引用 eve::dev::LanguageServer::Impl::Impl().

◆ scripts()

std::vector< ScriptInfo > eve::Runtime::scripts ( ) const

Metadata for all tracked scripts, sorted by id.

在文件 Runtime.cpp 第 1082 行定义.

引用了 a , 以及 b.

◆ setErrorHandler()

void eve::Runtime::setErrorHandler ( ErrorHandler  handler)
inline

Replaces the handler invoked for script errors at the Runtime boundary.

在文件 Runtime.h 第 412 行定义.

引用了 handler.

被这些函数引用 eve::dev::DevTool::detach().

◆ setLifecycleHandler()

void eve::Runtime::setLifecycleHandler ( LifecycleHandler  handler)
inline

Replaces the handler notified on every script lifecycle change.

在文件 Runtime.h 第 414 行定义.

引用了 handler.

◆ shutdown()

void eve::Runtime::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()

size_t eve::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.

参数
nameName 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

Value of a table member key; empty when missing.

在文件 Runtime.cpp 第 936 行定义.

引用了 enter(), guard(), handle(), key, name, scope , 以及 value.

◆ 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

Sets a key of a table member (creates the key when missing).

在文件 Runtime.cpp 第 957 行定义.

引用了 enter(), guard(), handle(), key, name, ok, scope , 以及 value.

被这些函数引用 eve::property_access::ReflectedPropertyModel::write().

◆ unload()

bool eve::Runtime::unload ( ScriptId  id)

◆ unloadAll()

void eve::Runtime::unloadAll ( )
noexcept

Unloads every script.

在文件 Runtime.cpp 第 1061 行定义.

引用了 ids , 以及 unload().

被这些函数引用 shutdown().

◆ vm() [1/2]

const ssq::VM & eve::Runtime::vm ( ) const
noexcept

在文件 Runtime.cpp 第 480 行定义.

◆ vm() [2/2]

ssq::VM & eve::Runtime::vm ( )
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().


该类的文档由以下文件生成: