载入中...
搜索中...
未找到
SquirrelBinding.cpp
浏览该文件的文档.
48 std::fprintf(stderr, "EVEngine: script call failed (%s): %s\n", what ? what : "?", text.c_str());
54 const std::string text = context.empty() ? std::string("unknown script error") : formatScriptError(context);
62 if (SQ_FAILED(sq_compilebuffer(vm, source, static_cast<SQInteger>(std::strlen(source)), name, SQTrue))) {
64 reportFailureText(name, context.empty() ? std::string("unknown compile error") : formatScriptError(context));
96Diagnostic conversionError(const ConversionContext& context, DiagnosticCode code, std::string message,
106 if (!key.empty() && (std::isalpha(static_cast<unsigned char>(key.front())) != 0 || key.front() == '_') &&
118 conversionError(context, DiagnosticCode::InvalidArgument, "Squirrel stack value is unavailable", path);
136 if (identity && std::find(context.activeContainers.begin(), context.activeContainers.end(), identity) !=
147 if ((object._type != OT_ARRAY && object._type != OT_TABLE) || context.activeContainers.empty()) return;
161bool convertAt(HSQUIRRELVM vm, SQInteger index, ConversionContext& context, const std::string& path, Value& output,
232 conversionError(context, DiagnosticCode::ParseError, "failed to read Squirrel array size", path);
271 conversionError(context, DiagnosticCode::ParseError, "failed to read Squirrel table key", path);
290bool validateValue(const Value& value, const SquirrelValueOptions& options, std::size_t depth, std::size_t& elements,
293 diagnostic = Diagnostic::error(DiagnosticCode::InvalidArgument, "Value exceeds maximum Squirrel element count",
299 diagnostic = Diagnostic::error(DiagnosticCode::InvalidArgument, "non-finite Value cannot be pushed to Squirrel",
311 if (!validateValue(value.at(index), options, depth + 1, elements, childPath(path, index), diagnostic))
317 if (!validateValue(member, options, depth + 1, elements, memberPath(path, key), diagnostic)) return false;
322bool pushImpl(HSQUIRRELVM vm, const Value& value, const SquirrelValueOptions& options, std::size_t depth,
336 diagnostic = Diagnostic::error(DiagnosticCode::InvalidArgument, "Int64 value does not fit Squirrel integer",
360 if (!pushImpl(vm, value.at(index), options, depth + 1, childPath(path, index), diagnostic)) return false;
375 diagnostic = Diagnostic::error(DiagnosticCode::Failed, "failed to add Value object member to Squirrel",
412Result<Value> valueFromSquirrel(HSQUIRRELVM vm, SQInteger index, const SquirrelValueOptions& options) {
414 return Result<Value>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "Squirrel VM must not be null",
426Result<Value> valueFromSquirrel(const ssq::Object& object, const SquirrelValueOptions& options) {
430 Diagnostic::error(DiagnosticCode::InvalidArgument, "Squirrel object is empty", "$", {}, options.source));
439Result<void> pushValue(HSQUIRRELVM vm, const Value& value, const SquirrelValueOptions& options) {
441 return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "Squirrel VM must not be null",
482 for (const Diagnostic& diagnostic : status.diagnostics()) diagnostics.push(projectDiagnostic(vm, diagnostic));
487ssq::Table buildStatusTable(HSQUIRRELVM vm, const Status& status, const ssq::Array& diagnostics) {
524ssq::Table projectStatusResult(HSQUIRRELVM vm, const Status& status) { return buildResultTable(vm, status, false); }
587 result.addFunc("ignore", [](ssq::Object value, const std::string& reason) { return ignoreResult(value, reason); });
599 return projectResult(vm, value.value().toJson(), [](std::string text) { return Value(std::move(text)); });
611 return projectResult(vm, ScriptProviderRegistry::instance().publish(name, instance), providerHandleValue);
616 return projectResult(vm, ScriptProviderRegistry::instance().publishForCapability(capability, name, instance),
626 return projectResult(vm, registry.unload(ScriptProviderHandle{name, registry.generationOf(name)}));
639 provider.addFunc("size", []() { return static_cast<std::int64_t>(ScriptProviderRegistry::instance().size()); });
643 for (const std::string& name : ScriptProviderRegistry::instance().capabilities()) out.push(name);
EVEngine assertion entry point, backed by zeroerr.
const eve::script::BindingContractRegistry & registry
Definition ProjectIndexAutomatic.cpp:24
The single Squirrel projection for common Result, Status and Value.
A structured explanation of a failed, degraded, or noteworthy result.
Definition Diagnostic.h:94
const std::string & path() const noexcept
Optional field, property, URI, or logical path.
Definition Diagnostic.h:149
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
const DiagnosticDetails & details() const noexcept
Structured context in insertion order.
Definition Diagnostic.h:151
const std::string & source() const noexcept
Optional producer or subsystem that emitted the diagnostic.
Definition Diagnostic.h:153
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Named script objects that native systems drive through named methods.
Definition ScriptProvider.h:114
static ScriptProviderRegistry & instance()
Process-lifetime registry; clearAll is the only reset.
Definition ScriptProvider.cpp:318
std::vector< ScriptProviderInfo > published() const
Every currently published provider.
Definition ScriptProvider.cpp:392
bool contains(std::string_view name) const
Whether name currently has a published provider.
Definition ScriptProvider.cpp:370
std::vector< std::string > capabilities() const
Names of every capability that has a declared script binding seam.
Definition ScriptProvider.cpp:381
std::uint64_t generationOf(std::string_view name) const
Current published generation for name, or 0 when absent.
Definition ScriptProvider.cpp:364
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:177
static Value string(std::string value)
Compatibility factory for a string value.
Definition Value.h:121
static Value integer(std::int64_t value)
Compatibility factory for an Int64 value.
Definition Value.h:115
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
Definition BuildingSnapshot.cpp:96
Definition BindingContracts.h:5
SQRESULT callFunction(HSQUIRRELVM vm, const HSQOBJECT &fn, const Receiver &receiver, Args &&... args)
Call a script function, deriving sq_call's parameter count from the pushes.
Definition SquirrelBinding.h:212
bool ignoreResult(const ssq::Object &result, const std::string &reason)
Mark a projected Result table as intentionally ignored by script.
Definition SquirrelBinding.cpp:545
std::string formatScriptError(const ScriptErrorContext &ctx)
Formats a context into a human-readable multi-line report.
Definition ScriptError.cpp:200
int reportedScriptCallFailures()
Count of engine-to-script call failures reported since the last reset.
Definition SquirrelBinding.cpp:75
ScriptErrorContext takeLastScriptError(HSQUIRRELVM vm)
Consumes and clears the last recorded error for a VM.
Definition ScriptError.cpp:222
SQRESULT compileAndRunChunk(HSQUIRRELVM vm, const char *name, const char *source)
Compile and run one embedded script chunk against the root table.
Definition SquirrelBinding.cpp:59
ssq::Table projectDiagnostic(HSQUIRRELVM vm, const Diagnostic &diagnostic)
Project one Diagnostic using the common script table schema.
Definition SquirrelBinding.cpp:456
void resetReportedScriptCallFailures()
Clear the failure count and the deduplication memory (diagnostics and tests).
Definition SquirrelBinding.cpp:81
Result< void > pushValue(HSQUIRRELVM vm, const Value &value, const SquirrelValueOptions &options)
Push a canonical Value into the active Squirrel VM.
Definition SquirrelBinding.cpp:439
void markResultHasValue(ssq::Table &result)
Declare that a projected table received a payload the caller attached itself.
Definition SquirrelBinding.cpp:538
ssq::Table projectStatus(HSQUIRRELVM vm, const Status &status)
Project one Status using the common script table schema.
Definition SquirrelBinding.cpp:520
ssq::Table projectStatusResult(HSQUIRRELVM vm, const Status &status)
Project a checked native status that carries no payload.
Definition SquirrelBinding.cpp:524
ScriptErrorContext captureCompileError(HSQUIRRELVM vm)
Captures the last compilation error recorded by the VM.
Definition ScriptError.cpp:114
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.
Definition SquirrelBinding.cpp:540
void exposeProviderBindings(ssq::Table &eveTable)
Expose eve.provider: script-published providers and capability seams.
Definition SquirrelBinding.cpp:606
std::string reportScriptCallFailure(HSQUIRRELVM vm, const char *what)
Report a failed engine-to-script call, consuming the VM's script error.
Definition SquirrelBinding.cpp:52
void exposeResultBindings(ssq::Table &eveTable)
Expose the common script helpers under eve.result.
Definition SquirrelBinding.cpp:585
Result< Value > valueFromSquirrel(HSQUIRRELVM vm, SQInteger index, const SquirrelValueOptions &options)
Convert one Squirrel value into the canonical owning Value tree.
Definition SquirrelBinding.cpp:412
@ InvalidArgument
@ Unsupported
@ Failed
@ ParseError
@ Object
constexpr std::string_view statusCodeName(StatusCode code) noexcept
Return the stable protocol spelling of a status code.
Definition Status.h:46
constexpr std::string_view diagnosticCodeName(DiagnosticCode code) noexcept
Return a stable, compact spelling useful for logs and diagnostics.
Definition Diagnostic.h:176
Generation-qualified identity of one published script provider.
Definition ScriptProvider.h:27
Read-only view of one published provider, for discovery and diagnostics.
Definition ScriptProvider.h:69
Structured snapshot of a script error: message, throw site and stack.
Definition ScriptError.h:46
Limits and provenance used by the Squirrel ↔ Value adapter.
Definition SquirrelBinding.h:36
std::size_t maxElements
Definition SquirrelBinding.h:38