载入中...
搜索中...
未找到
eve::ScriptProviderRegistry类 参考

Named script objects that native systems drive through named methods. 更多...

#include <ScriptProvider.h>

类

struct  Impl
 

Public 成员函数

Result< ScriptProviderHandle > publish (std::string name, const ssq::Object &instance)
 Publish one live script instance under a stable name.
 
Result< void > unload (const ScriptProviderHandle &handle)
 Retire exactly one published generation.
 
std::uint64_t generationOf (std::string_view name) const
 Current published generation for name, or 0 when absent.
 
bool contains (std::string_view name) const
 Whether name currently has a published provider.
 
std::size_t size () const
 Number of published providers.
 
std::vector< std::string > capabilities () const
 Names of every capability that has a declared script binding seam.
 
std::vector< ScriptProviderInfo > published () const
 Every currently published provider.
 
void clearAll ()
 Drop every published provider and release its VM reference.
 
Result< void > call (const ScriptProviderHandle &handle, std::string_view method) const
 Call method() on a published provider.
 
Result< void > call (const ScriptProviderHandle &handle, std::string_view method, double dt) const
 Call method(dt) on a published provider.
 
Result< void > call (const ScriptProviderHandle &handle, std::string_view method, std::span< const ScriptArg > args) const
 Call method(...) with explicit arguments.
 
Result< double > callNumber (const ScriptProviderHandle &handle, std::string_view method, double dt) const
 Call method(dt) and read a numeric result.
 
Result< double > callNumber (const ScriptProviderHandle &handle, std::string_view method, std::span< const ScriptArg > args) const
 Call method(...) with explicit scalar arguments and read a numeric result.
 
Result< std::vector< double > > callNumbers (const ScriptProviderHandle &handle, std::string_view method) const
 Call method() and read an array of numbers.
 
Result< std::vector< double > > callNumbers (const ScriptProviderHandle &handle, std::string_view method, std::span< const ScriptArg > args) const
 Call method(...) with explicit scalar arguments and read an array of numbers.
 
Result< Value > callValue (const ScriptProviderHandle &handle, std::string_view method, std::span< const ScriptArg > args) const
 Call method(...) and read the script result as an owning eve::Value.
 
Result< Value > callValue (const ScriptProviderHandle &handle, std::string_view method) const
 No-argument overload of the structured call.
 
void declareCapability (std::string capability, ScriptCapabilityBinder binder, ScriptCapabilityUnbinder unbinder)
 Declare that one native capability may be served by a script provider.
 
bool hasCapabilitySeam (std::string_view capability) const
 Whether capability has a declared script binding seam.
 
Result< void > removeCapability (std::string_view capability)
 Withdraw a declared seam when its owning module goes away.
 
Result< ScriptProviderHandle > publishForCapability (std::string_view capability, std::string name, const ssq::Object &instance)
 Publish one script instance as the provider of a declared capability.
 

静态 Public 成员函数

static ScriptProviderRegistry & instance ()
 Process-lifetime registry; clearAll is the only reset.
 

详细描述

Named script objects that native systems drive through named methods.

A native system needs to call into user script without knowing the script class. This registry is that seam: a script object is published under a stable name, the registry roots it for as long as it is published, and callers invoke a method by name. A method the object does not implement is Unsupported, not a crash and not a silent no-op.

Deliberately minimal: it resolves nothing by itself. A caller that wants to serve a cap:: capability from script publishes the instance here and adapts it; the registry only owns the identity, the rooting and the call.

@ownership The registry owns one VM reference per published provider. Callers hold borrowed handles, never the object. @lifetime A published provider stays valid until unload or clearAll. Handles outlive retirement on purpose and then report StaleHandle. @thread Main/script thread only, like every other Squirrel entry point. There is no internal lock: a lookup and a call both touch the VM. @reentrancy A published method is user script and may re-enter the registry (publish, unload) while it runs. call therefore re-resolves after the call only for its own bookkeeping and never holds a reference to the provider across an invocation it does not own.

在文件 ScriptProvider.h 第 114 行定义.

成员函数说明

◆ call() [1/3]

Result< void > eve::ScriptProviderRegistry::call ( const ScriptProviderHandle &  handle,
std::string_view  method 
) const

Call method() on a published provider.

返回
Success; Unsupported when the instance has no such method; StaleHandle when the generation is no longer published; Failed when the script call raised. @cost One name lookup in the script object's delegate chain plus one script call. Callers on a per-entity path must resolve the handle once and keep it, not re-derive it per entity.

在文件 ScriptProvider.cpp 第 518 行定义.

引用了 eve::Result< T >::failure(), handle, instance(), method , 以及 eve::Result< T >::success().

◆ call() [2/3]

Result< void > eve::ScriptProviderRegistry::call ( const ScriptProviderHandle &  handle,
std::string_view  method,
double  dt 
) const

Call method(dt) on a published provider.

参数
dtSeconds; the caller owns the simulation step, never a wall clock.
返回
As the zero-argument overload.

在文件 ScriptProvider.cpp 第 526 行定义.

引用了 dt, eve::Result< T >::failure(), eve::ScriptArg::fromNumber(), handle, instance(), method , 以及 eve::Result< T >::success().

◆ call() [3/3]

Result< void > eve::ScriptProviderRegistry::call ( const ScriptProviderHandle &  handle,
std::string_view  method,
std::span< const ScriptArg >  args 
) const

Call method(...) with explicit arguments.

参数
argsPositional arguments in call order; may be empty.
返回
As the zero-argument overload, plus InvalidArgument when the script method rejects an argument (wrong arity or type). @cost One script call, plus one VM push per argument: a scalar argument is one push, a Table argument is one eve::Value tree projection (depth and element-count bounded by common/SquirrelBinding.h). Marshalling is the caller's: this is for capability seams that genuinely need several values or one record, not a general-purpose reflection bridge.
备注
Overload resolution is unambiguous in practice because a braced argument list of one or more elements cannot initialize the double overload. Spell an intentionally empty list as the zero-argument overload instead of {}.

在文件 ScriptProvider.cpp 第 536 行定义.

引用了 eve::Result< T >::failure(), handle, instance(), method , 以及 eve::Result< T >::success().

◆ callNumber() [1/2]

Result< double > eve::ScriptProviderRegistry::callNumber ( const ScriptProviderHandle &  handle,
std::string_view  method,
double  dt 
) const

Call method(dt) and read a numeric result.

参数
dtSeconds.
返回
The script result as a double, or the same failures as call, plus InvalidArgument when the method returned a non-numeric value.

在文件 ScriptProvider.cpp 第 545 行定义.

引用了 dt, eve::Result< T >::failure(), eve::ScriptArg::fromNumber(), handle, instance() , 以及 method.

◆ callNumber() [2/2]

Result< double > eve::ScriptProviderRegistry::callNumber ( const ScriptProviderHandle &  handle,
std::string_view  method,
std::span< const ScriptArg >  args 
) const

Call method(...) with explicit scalar arguments and read a numeric result.

参数
argsPositional arguments in call order; may be empty.
返回
As the double overload of callNumber.

在文件 ScriptProvider.cpp 第 553 行定义.

引用了 eve::Result< T >::failure(), handle, instance() , 以及 method.

◆ callNumbers() [1/2]

Result< std::vector< double > > eve::ScriptProviderRegistry::callNumbers ( const ScriptProviderHandle &  handle,
std::string_view  method 
) const

Call method() and read an array of numbers.

返回
The script result as doubles, or the same failures as call, plus InvalidArgument when the method returned a non-array, a non-numeric element, or more than 64 elements. @cost One script call plus one copy per element. For a target that reports a whole transform back, not for streaming data: the result is copied, not viewed.

在文件 ScriptProvider.cpp 第 560 行定义.

引用了 handle, instance() , 以及 method.

◆ callNumbers() [2/2]

Result< std::vector< double > > eve::ScriptProviderRegistry::callNumbers ( const ScriptProviderHandle &  handle,
std::string_view  method,
std::span< const ScriptArg >  args 
) const

Call method(...) with explicit scalar arguments and read an array of numbers.

参数
argsPositional arguments in call order; may be empty.
返回
As the zero-argument overload of callNumbers.

在文件 ScriptProvider.cpp 第 567 行定义.

引用了 handle, instance() , 以及 method.

◆ callValue() [1/2]

Result< Value > eve::ScriptProviderRegistry::callValue ( const ScriptProviderHandle &  handle,
std::string_view  method 
) const

No-argument overload of the structured call.

返回
As callValue.

在文件 ScriptProvider.cpp 第 582 行定义.

引用了 callValue(), handle , 以及 method.

◆ callValue() [2/2]

Result< Value > eve::ScriptProviderRegistry::callValue ( const ScriptProviderHandle &  handle,
std::string_view  method,
std::span< const ScriptArg >  args 
) const

Call method(...) and read the script result as an owning eve::Value.

决定③(2026-09-20)的"结构化返回"这一半:插座可以拿到一个**对象/数组**而不是一个数。 典型用途是 ISensingCandidateProvider / IStateQuery 这类"问一次、答一组"的接口。

参数
handlePublished provider handle.
methodMethod name on the provider object.
argsPositional arguments in call order; may be empty.
返回
The result as an owning Value tree: Null/Bool/Int64/Double/String/ Array/Object,或与 call 相同的失败(Unsupported/StaleHandle/Failed), 外加转换失败时的 InvalidArgument。 @cost One script call plus one whole-tree projection. The result is copied, not viewed: per-frame callers should keep asking for scalars (callNumber) and only reach for a structured return when the payload genuinely is a record.
备注
载荷边界由 common/SquirrelBinding.h 的权威转换负责(默认深度 64、元素 100000, 拒绝环与非有限数)。需要更紧的上限就用 callNumbers(64 个元素)那条路。 @lifetime 返回值拥有自己的存储,脚本 VM 销毁后依然可用。

在文件 ScriptProvider.cpp 第 575 行定义.

引用了 eve::Result< T >::failure(), handle, instance() , 以及 method.

被这些函数引用 callValue().

◆ capabilities()

std::vector< std::string > eve::ScriptProviderRegistry::capabilities ( ) const

Names of every capability that has a declared script binding seam.

返回
Names sorted lexicographically, so script-visible output is stable across runs and hash orders. @cost O(capabilities) with one string copy each. Discovery only.

在文件 ScriptProvider.cpp 第 381 行定义.

引用了 name , 以及 seam.

被这些函数引用 eve::script::exposeProviderBindings().

◆ clearAll()

void eve::ScriptProviderRegistry::clearAll ( )

Drop every published provider and release its VM reference.

备注
Test-only reset, and the hook the runtime uses at shutdown: a rooted ssq::Object must not outlive its VM.

在文件 ScriptProvider.cpp 第 479 行定义.

引用了 name, removed , 以及 retired.

被这些函数引用 eve::Runtime::shutdown().

◆ contains()

bool eve::ScriptProviderRegistry::contains ( std::string_view  name) const

Whether name currently has a published provider.

在文件 ScriptProvider.cpp 第 370 行定义.

引用了 generationOf() , 以及 name.

被这些函数引用 eve::script::exposeProviderBindings().

◆ declareCapability()

void eve::ScriptProviderRegistry::declareCapability ( std::string  capability,
ScriptCapabilityBinder  binder,
ScriptCapabilityUnbinder  unbinder 
)

Declare that one native capability may be served by a script provider.

Called once per capability by the module that owns the interface, at composition time. The module supplies the marshalling because it is the only party that knows its own interface; the registry just routes the binding, so no central table has to enumerate every capability.

参数
capabilityNative capabilityName string, e.g. "IVehicleDamageModifier".
binderInstalls the native adapter for one published provider. Called synchronously during publishForCapability.
unbinderRemoves the adapter again. Called by unload, clearAll and a failed publishForCapability. @cost One map insert. Declare at composition time, never per frame.
备注
Redeclaring the same capability replaces the previous pair. Both callbacks must be callable: a capability with no unbinder would leak its adapter across a hot reload.

在文件 ScriptProvider.cpp 第 404 行定义.

引用了 EV_PARAM_CHECK.

被这些函数引用 eve::climbing::declareScriptClimbingEventSeam(), eve::ui::declareScriptPhotoModeApplySeam(), eve::weapon::declareScriptProjectileSeam(), eve::sensing::declareScriptSensingCandidateSeam(), eve::dialogue::declareScriptStateMutationSeam(), eve::dialogue::declareScriptStateQuerySeam() , 以及 eve::map::declareScriptTileCollisionSinkSeam().

◆ generationOf()

std::uint64_t eve::ScriptProviderRegistry::generationOf ( std::string_view  name) const

Current published generation for name, or 0 when absent.

在文件 ScriptProvider.cpp 第 364 行定义.

引用了 found , 以及 name.

被这些函数引用 contains() , 以及 eve::script::exposeProviderBindings().

◆ hasCapabilitySeam()

bool eve::ScriptProviderRegistry::hasCapabilitySeam ( std::string_view  capability) const

Whether capability has a declared script binding seam.

在文件 ScriptProvider.cpp 第 412 行定义.

◆ instance()

◆ publish()

Result< ScriptProviderHandle > eve::ScriptProviderRegistry::publish ( std::string  name,
const ssq::Object &  instance 
)

Publish one live script instance under a stable name.

参数
nameNon-empty stable provider name; republishing supersedes it.
instanceLive script instance; the registry takes its own VM reference.
返回
The new generation-qualified handle, or a structured failure. @cost One VM reference plus a map insert. Call at load/publish time, never per frame.
备注
Republishing the same name retires the previous generation without destroying it: outstanding handles report StaleHandle afterwards. When the superseded generation was capability-bound, its unbinder runs first and a failure there fails this call – the superseded generation stays retired either way, so the name has no live provider afterwards.

在文件 ScriptProvider.cpp 第 325 行定义.

引用了 eve::Result< T >::failure(), generation, instance(), eve::InvalidArgument, name, previous, retired , 以及 eve::Result< T >::success().

被这些函数引用 publishForCapability().

◆ published()

std::vector< ScriptProviderInfo > eve::ScriptProviderRegistry::published ( ) const

Every currently published provider.

返回
Entries sorted by name for deterministic script-visible output. @cost O(published) with string copies. Discovery/diagnostics only.

在文件 ScriptProvider.cpp 第 392 行定义.

引用了 entries , 以及 name.

被这些函数引用 eve::script::exposeProviderBindings() , 以及 publishForCapability().

◆ publishForCapability()

Result< ScriptProviderHandle > eve::ScriptProviderRegistry::publishForCapability ( std::string_view  capability,
std::string  name,
const ssq::Object &  instance 
)

Publish one script instance as the provider of a declared capability.

参数
capabilityCapability declared through declareCapability.
nameStable provider name; republishing supersedes it.
instanceLive script instance; the registry takes its own VM reference.
返回
The new handle, NotFound when nothing declared capability, or whatever the binder reported. @cost One publish plus one binder invocation. Call at load/publish time.
备注
Atomic: a binder failure unloads the fresh generation again, so a caller never observes a published provider that serves nothing.

在文件 ScriptProvider.cpp 第 425 行定义.

引用了 eve::Failed, eve::Result< T >::failure(), handle, instance(), name, eve::NotFound, pending, publish(), published(), seam, eve::Result< T >::success() , 以及 unload().

◆ removeCapability()

Result< void > eve::ScriptProviderRegistry::removeCapability ( std::string_view  capability)

Withdraw a declared seam when its owning module goes away.

返回
Success, or NotFound when capability was never declared. @cost One map erase.
备注
Only the ability to bind again is withdrawn. A provider that is already published keeps its generation and its installed adapter, so unloading it still runs the unbinder it was published with. A seam that outlived its owner would otherwise advertise a binding that can only fail later, at publish time.

在文件 ScriptProvider.cpp 第 416 行定义.

引用了 eve::Result< T >::failure(), key, eve::NotFound , 以及 eve::Result< T >::success().

被这些函数引用 eve::climbing::withdrawScriptClimbingEventSeam(), eve::ui::withdrawScriptPhotoModeApplySeam(), eve::weapon::withdrawScriptProjectileSeam(), eve::sensing::withdrawScriptSensingCandidateSeam(), eve::dialogue::withdrawScriptStateMutationSeam(), eve::dialogue::withdrawScriptStateQuerySeam() , 以及 eve::map::withdrawScriptTileCollisionSinkSeam().

◆ size()

std::size_t eve::ScriptProviderRegistry::size ( ) const

Number of published providers.

在文件 ScriptProvider.cpp 第 372 行定义.

引用了 count , 以及 key.

被这些函数引用 eve::script::exposeProviderBindings().

◆ unload()

Result< void > eve::ScriptProviderRegistry::unload ( const ScriptProviderHandle &  handle)

Retire exactly one published generation.

返回
Success; StaleHandle when it was already retired or superseded; or whatever a capability unbinder reported, after the generation is already retired. @cost One map erase plus a VM release, plus one unbinder invocation when the provider was published through publishForCapability.

在文件 ScriptProvider.cpp 第 352 行定义.

引用了 eve::Result< T >::failure(), found, handle , 以及 eve::StaleHandle.

被这些函数引用 publishForCapability().


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