diff --git a/src/3rdparty/squirrel/include/squirrel.h b/src/3rdparty/squirrel/include/squirrel.h index bbda8f72da..cb768cf5cb 100644 --- a/src/3rdparty/squirrel/include/squirrel.h +++ b/src/3rdparty/squirrel/include/squirrel.h @@ -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; diff --git a/src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp b/src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp index a8abf8be79..f5763589c2 100644 --- a/src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp +++ b/src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp @@ -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++; diff --git a/src/3rdparty/squirrel/squirrel/sqdebug.cpp b/src/3rdparty/squirrel/squirrel/sqdebug.cpp index d06696c485..cc5c21316c 100644 --- a/src/3rdparty/squirrel/squirrel/sqdebug.cpp +++ b/src/3rdparty/squirrel/squirrel/sqdebug.cpp @@ -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:{ diff --git a/src/script/squirrel_std.cpp b/src/script/squirrel_std.cpp index a926dcde14..d00c2ca023 100644 --- a/src/script/squirrel_std.cpp +++ b/src/script/squirrel_std.cpp @@ -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);