5#include <simplesquirrel/simplesquirrel.hpp>
14#include <unordered_map>
21class ScriptModuleResolver;
22struct ScriptErrorContext;
36 std::snprintf(buf,
sizeof(buf),
"%.*g",
37 std::numeric_limits<double>::max_digits10,
value);
79 const std::string&
source() const noexcept {
return source_; }
81 uint64_t
scriptId() const noexcept {
return script_id_; }
85 int line() const noexcept {
return line_; }
87 int column() const noexcept {
return column_; }
89 const std::string&
function() const noexcept {
return function_; }
91 const std::string&
stackTrace() const noexcept {
return stack_trace_; }
93 bool reported() const noexcept {
return reported_; }
101 std::string function_;
102 std::string stack_trace_;
103 bool reported_ =
false;
109 ssq::Type
type = ssq::Type::NULLPTR;
134 bool boolean =
false;
136 double floating = 0.0;
140 bool empty() const noexcept {
return kind == ReflectedValueKind::None; }
144 int64_t
asInt() const noexcept {
return integer; }
146 double asFloat() const noexcept {
return floating; }
154 ssq::Type
type = ssq::Type::NULLPTR;
162 float attrFloat(
const std::string&
name,
float def = 0.f) const noexcept;
164 bool attrBool(const
std::
string&
name,
bool def = false) const noexcept;
166 std::
string attrString(const
std::
string&
name, const
std::
string& def = {})
const;
168 std::vector<std::string> attrOptions(
const std::string&
name)
const;
210 int top() const noexcept {
return static_cast<int>(top_); }
241 explicit Runtime(
size_t stackSize = 2048, ssq::Libs::Flag libraries = ssq::Libs::ALL);
251 void shutdown() noexcept;
253 bool initialized() const noexcept;
256 ssq::VM&
vm() noexcept;
257 const
ssq::VM&
vm() const noexcept;
261 script::ScriptModuleResolver& scriptModules() noexcept;
263 const
script::ScriptModuleResolver& scriptModules() const noexcept;
265 script::ScriptCompiler& scriptCompiler() noexcept;
267 const
script::ScriptCompiler& scriptCompiler() const noexcept;
274 ssq::Table table(const
char*
name) const;
283 static
size_t stackDepth() noexcept;
299 ScriptId compileFile(const
std::
string&
path);
305 ScriptId runFile(const
std::
string&
path);
314 const std::string&
source = {});
322 ssq::Object createInstance(
const std::string&
name,
const std::string&
source = {});
327 std::vector<ReflectedMember> reflectInstance(
const ssq::Object& instance)
const;
332 ReflectedValue readProperty(
const ssq::Object& instance,
333 const std::string&
name)
const;
342 bool writeProperty(
const ssq::Object& instance,
const std::string&
name,
343 const ReflectedValue&
value)
const;
349 ssq::Object readObjectProperty(
const ssq::Object& instance,
350 const std::string&
name)
const;
354 size_t arraySize(
const ssq::Object& instance,
const std::string&
name)
const;
356 ReflectedValue arrayGet(
const ssq::Object& instance,
const std::string&
name,
359 bool arraySet(
const ssq::Object& instance,
const std::string&
name,
size_t index,
360 const ReflectedValue&
value)
const;
362 bool arrayAppend(
const ssq::Object& instance,
const std::string&
name,
363 const ReflectedValue&
value)
const;
365 bool arrayRemove(
const ssq::Object& instance,
const std::string&
name,
370 std::vector<std::string> tableKeys(
const ssq::Object& instance,
371 const std::string&
name)
const;
373 ReflectedValue tableGet(
const ssq::Object& instance,
const std::string&
name,
374 const std::string&
key)
const;
376 bool tableSet(
const ssq::Object& instance,
const std::string&
name,
377 const std::string&
key,
const ReflectedValue&
value)
const;
379 bool tableRemove(
const ssq::Object& instance,
const std::string&
name,
380 const std::string&
key)
const;
382 ScriptId reload(ScriptId
id);
384 bool unload(ScriptId
id);
386 void unloadAll() noexcept;
389 bool contains(ScriptId
id) const noexcept;
391 const ScriptInfo*
script(ScriptId
id) const noexcept;
393 std::vector<ScriptInfo> scripts() const;
395 const ReflectedClass* reflectedClass(const
std::
string&
name) const noexcept;
397 std::vector<ReflectedClass> reflectedClasses() const;
405 size_t scanClasses();
407 ssq::Class findClass(const
std::
string&
name) const;
409 std::
string classNameOf(const
ssq::Object& instance) const;
420 void installErrorHandler();
422 std::unique_ptr<ssq::VM> vm_;
423 std::unique_ptr<script::ScriptModuleResolver> script_modules_;
424 std::unique_ptr<script::ScriptCompiler> script_compiler_;
425 std::unordered_map<ScriptId, std::unique_ptr<ScriptRecord>> scripts_;
426 std::unordered_map<std::string, ReflectedClass> classes_;
427 std::unordered_map<std::string, ScriptId> class_owners_;
428 std::unordered_map<std::string, SQUserPointer> class_identities_;
429 ScriptId next_script_id_ = 1;
430 bool initialized_ =
false;
431 bool shutting_down_ =
false;
432 bool stopped_ =
false;
433 ErrorHandler error_handler_;
434 LifecycleHandler lifecycle_handler_;
438 const std::string& sourceText);
439 [[noreturn]]
void fail(
ScriptStage stage,
const std::string&
source, ScriptId
id,
440 const std::exception&
error);
441 [[noreturn]]
void fail(
ScriptStage stage,
const std::string&
source, ScriptId
id,
443 void discoverClasses(ScriptRecord& record,
444 const std::unordered_map<std::string, SQUserPointer>& before);
445 std::unordered_map<std::string, SQUserPointer> rootClasses()
const;
447 const std::string&
source)
const;
449 std::vector<ReflectedMember> collectClassMembers(
const ssq::Class&
cls)
const;
struct SQVM * HSQUIRRELVM
#define EVENGINE_API_FOUNDATION_INLINE
仅供"只有内联成员"的类型使用的组宏:拥有者 dllexport,消费方不导入。
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
std::unique_ptr< gpgpu::GpuBuffer > buffer
const UnitySourceAsset & source
const VegetationPresetContext & context
Pushes this Runtime on the current thread's runtime stack.
Scope(const Scope &)=delete
Scope & operator=(Scope &&other)=delete
Scope & operator=(const Scope &)=delete
Restores the native Squirrel stack when a binding operation leaves scope.
StackGuard & operator=(const StackGuard &)=delete
void dismiss() noexcept
Dismiss.
StackGuard(const StackGuard &)=delete
int top() const noexcept
Top.
EVENGINE_API_FOUNDATION public API.
std::function< void(const ScriptInfo &)> LifecycleHandler
Runtime(Runtime &&)=delete
std::function< void(const ScriptException &)> ErrorHandler
Runtime & operator=(Runtime &&)=delete
Runtime(const Runtime &)=delete
Runtime & operator=(const Runtime &)=delete
Scope enter()
Pushes this runtime on the thread-local runtime stack (RAII pop).
void setLifecycleHandler(LifecycleHandler handler)
Replaces the handler notified on every script lifecycle change.
Exception raised at the public Runtime boundary.
bool reported() const noexcept
True when a reporter (e.g. DevTool hook) already handled it.
const std::string & stackTrace() const noexcept
Multi-line call stack captured at the throw site.
bool hasLocation() const noexcept
True when the exception carries a script source line.
int column() const noexcept
1-based compile column; -1 when unknown.
ScriptStage stage() const noexcept
Stage.
const std::string & function() const noexcept
Function name at the throw site; empty when unknown.
const std::string & source() const noexcept
Source.
uint64_t scriptId() const noexcept
Script id.
int line() const noexcept
1-based throw/compile site line; -1 when unknown.
Build metadata (engine git commit, build time, third-party version).
enum EVENGINE_API_FOUNDATION Float
OT_FLOAT.
enum EVENGINE_API_FOUNDATION Other
Any other slot kind.
enum EVENGINE_API_FOUNDATION Instance
Nested script instance (navigate; ObjectRef in property schema).
enum EVENGINE_API_FOUNDATION Bool
OT_BOOL.
ScriptState
ScriptState public API.
enum EVENGINE_API_FOUNDATION Integer
OT_INTEGER.
std::string reflectedFloatString(double value)
Shortest round-trip float formatting (portable).
ScriptStage
ScriptStage public API.
enum EVENGINE_API_FOUNDATION String
OT_STRING.
enum EVENGINE_API_FOUNDATION ReflectedValueKind
Runtime value kind read from a live script instance slot.
enum EVENGINE_API_FOUNDATION Table
OT_TABLE (editable via Runtime table APIs / ReflectedPropertyModel).
enum EVENGINE_API_FOUNDATION Array
OT_ARRAY (editable via Runtime array APIs / ReflectedPropertyModel).
EVEngine ECS 集成层:底层实现使用 sunxfancy/ECS.hpp https://github.com/sunxfancy/ECS.hpp
EVENGINE_API_FOUNDATION_INLINE public API.
EVENGINE_API_FOUNDATION_INLINE public API.
std::vector< ReflectedMember > members
EVENGINE_API_FOUNDATION public API.
ReflectedValue value
Live value; empty for class-level reflection.
std::vector< ReflectedAttribute > attributes
Typed snapshot of one live instance property.
const std::string & asString() const noexcept
As string.
bool empty() const noexcept
True when the slot exists and is non-null.
bool asBool() const noexcept
As bool.
int64_t asInt() const noexcept
As int.
double asFloat() const noexcept
As float.
EVENGINE_API_FOUNDATION_INLINE public API.
std::vector< std::string > classes
Structured snapshot of a script error: message, throw site and stack.