mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use std::string_view for SQ stack and function info
parent
0bc773215e
commit
d464961c41
|
@ -164,9 +164,9 @@ typedef struct tagSQObject
|
|||
}SQObject;
|
||||
|
||||
typedef struct tagSQStackInfos{
|
||||
const SQChar* funcname;
|
||||
const SQChar* source;
|
||||
SQInteger line;
|
||||
std::string_view funcname;
|
||||
std::string_view source;
|
||||
SQInteger line = -1;
|
||||
}SQStackInfos;
|
||||
|
||||
typedef struct SQVM* HSQUIRRELVM;
|
||||
|
@ -190,8 +190,8 @@ typedef struct tagSQRegFunction{
|
|||
|
||||
typedef struct tagSQFunctionInfo {
|
||||
SQUserPointer funcid;
|
||||
const SQChar *name;
|
||||
const SQChar *source;
|
||||
std::string_view name;
|
||||
std::string_view source;
|
||||
}SQFunctionInfo;
|
||||
|
||||
|
||||
|
|
|
@ -21,21 +21,17 @@ void sqstd_printcallstack(HSQUIRRELVM v)
|
|||
pf(v,"\nCALLSTACK\n");
|
||||
while(SQ_SUCCEEDED(sq_stackinfos(v,level,&si)))
|
||||
{
|
||||
const SQChar *fn="unknown";
|
||||
const SQChar *src="unknown";
|
||||
if(si.funcname)fn=si.funcname;
|
||||
if(si.source) {
|
||||
std::string_view fn="unknown";
|
||||
std::string_view src="unknown";
|
||||
if(!si.funcname.empty())fn=si.funcname;
|
||||
if(!si.source.empty()) {
|
||||
/* We don't want to bother users with absolute paths to all AI files.
|
||||
* Since the path only reaches NoAI code in a formatted string we have
|
||||
* to strip it here. Let's hope nobody installs openttd in a subdirectory
|
||||
* of a directory named /ai/. */
|
||||
src = strstr(si.source, "\\ai\\");
|
||||
if (!src) src = strstr(si.source, "/ai/");
|
||||
if (src) {
|
||||
src += 4;
|
||||
} else {
|
||||
src = si.source;
|
||||
}
|
||||
auto p = si.source.find("\\ai\\");
|
||||
if (p == std::string_view::npos) p = si.source.find("/ai/");
|
||||
src = (p == std::string_view::npos) ? si.source : si.source.substr(p + 4);
|
||||
}
|
||||
pf(v,fmt::format("*FUNCTION [{}()] {} line [{}]\n",fn,src,si.line));
|
||||
level++;
|
||||
|
|
|
@ -37,7 +37,7 @@ SQRESULT sq_stackinfos(HSQUIRRELVM v, SQInteger level, SQStackInfos *si)
|
|||
{
|
||||
SQInteger cssize = v->_callsstacksize;
|
||||
if (cssize > level) {
|
||||
memset(si, 0, sizeof(SQStackInfos));
|
||||
*si = {};
|
||||
SQVM::CallInfo &ci = v->_callsstack[cssize-level-1];
|
||||
switch (type(ci._closure)) {
|
||||
case OT_CLOSURE:{
|
||||
|
|
|
@ -48,13 +48,9 @@ SQInteger SquirrelStd::require(HSQUIRRELVM vm)
|
|||
/* Get the script-name of the current file, so we can work relative from it */
|
||||
SQStackInfos si;
|
||||
sq_stackinfos(vm, 1, &si);
|
||||
if (si.source == nullptr) {
|
||||
Debug(misc, 0, "[squirrel] Couldn't detect the script-name of the 'require'-caller; this should never happen!");
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
/* Keep the dir, remove the rest */
|
||||
std::string path = si.source;
|
||||
std::string path{si.source};
|
||||
auto p = path.find_last_of(PATHSEPCHAR);
|
||||
/* Keep the PATHSEPCHAR there, remove the rest */
|
||||
if (p != std::string::npos) path.erase(p + 1);
|
||||
|
|
Loading…
Reference in New Issue