载入中...
搜索中...
未找到
ScriptError.h
浏览该文件的文档.
1#pragma once
2
3#include "common/Export.h"
4
5#include <squirrel.h>
6
7#include <string>
8#include <vector>
9
10namespace eve::script {
11
14 std::string source;
15 std::string function;
16 int line = -1;
17};
18
26 std::string message;
27 std::string source;
28 std::string function;
29 int line = -1;
30 int column = -1;
31 std::string hint;
32 std::vector<ScriptFrame> stack;
33 bool reported = false;
36 bool empty() const noexcept { return message.empty() && stack.empty(); }
37};
38
45
52
62EVENGINE_API bool parseCompileError(const std::string& text, std::string* source,
63 int* line, int* column, std::string* message);
64
71EVENGINE_API std::string sourceLineText(const std::string& sourceText, int line);
72
78EVENGINE_API std::string formatScriptError(const ScriptErrorContext& ctx);
79
85EVENGINE_API std::string formatStackTrace(const std::vector<ScriptFrame>& frames);
86
92EVENGINE_API void setLastScriptError(HSQUIRRELVM vm, ScriptErrorContext ctx);
93
100
106EVENGINE_API const ScriptErrorContext* peekLastScriptError(HSQUIRRELVM vm);
107
113
114} // namespace eve::script
struct SQVM * HSQUIRRELVM
int line
HSQUIRRELVM vm
Definition ECS.cpp:20
#define EVENGINE_API
宿主(eve / libmain)导出宏;插件从进程导入同一批符号。
Definition Export.h:16
void clearLastScriptError(HSQUIRRELVM vm)
Drops any recorded error for a VM.
const ScriptErrorContext * peekLastScriptError(HSQUIRRELVM vm)
Peeks at the last recorded error for a VM without clearing it.
bool parseCompileError(const std::string &text, std::string *source, int *line, int *column, std::string *message)
Parses the ssq compile message "Compile error at source:line:column msg".
std::string formatStackTrace(const std::vector< ScriptFrame > &frames)
Formats just the call-stack portion of a context.
ScriptErrorContext captureCompileError(HSQUIRRELVM vm)
Captures the last compilation error recorded by the VM.
std::string formatScriptError(const ScriptErrorContext &ctx)
Formats a context into a human-readable multi-line report.
std::string sourceLineText(const std::string &sourceText, int line)
Extracts one 1-based line from script source text.
ScriptErrorContext takeLastScriptError(HSQUIRRELVM vm)
Consumes and clears the last recorded error for a VM.
void setLastScriptError(HSQUIRRELVM vm, ScriptErrorContext ctx)
Records the last error for a VM (thread-local, synchronous consumers).
ScriptErrorContext captureScriptError(HSQUIRRELVM vm)
Captures the pending runtime error from inside the Squirrel error handler.
Structured snapshot of a script error: message, throw site and stack.
Definition ScriptError.h:25
std::string function
Function of the throwing frame.
Definition ScriptError.h:28
bool empty() const noexcept
True when no error payload was captured.
Definition ScriptError.h:36
std::string hint
Optional source snippet shown under the message.
Definition ScriptError.h:31
std::string message
Raw error value ("kaboom", "42", ...).
Definition ScriptError.h:26
std::vector< ScriptFrame > stack
Call stack, innermost frame first.
Definition ScriptError.h:32
std::string source
Source of the throwing frame.
Definition ScriptError.h:27
One call-stack frame captured while the script error is still live.
Definition ScriptError.h:13
std::string function
Function name, when Squirrel debug info knows it.
Definition ScriptError.h:15
std::string source
Source name of the frame ("main.nut", "buffer", ...).
Definition ScriptError.h:14