From 6e3d3c0e7c73a3f5a6d6af05420e0128b79c3057 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Thu, 4 May 2023 23:48:56 +0200 Subject: [PATCH] Codechange: introduce std::string variant of sq_pushstring --- src/3rdparty/squirrel/include/squirrel.h | 1 + src/game/game_text.cpp | 2 +- src/script/script_instance.cpp | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/3rdparty/squirrel/include/squirrel.h b/src/3rdparty/squirrel/include/squirrel.h index 9dd4d7a75d..7dfdaed9ad 100644 --- a/src/3rdparty/squirrel/include/squirrel.h +++ b/src/3rdparty/squirrel/include/squirrel.h @@ -238,6 +238,7 @@ void sq_newclosure(HSQUIRRELVM v,SQFUNCTION func,SQUnsignedInteger nfreevars); SQRESULT sq_setparamscheck(HSQUIRRELVM v,SQInteger nparamscheck,const SQChar *typemask); SQRESULT sq_bindenv(HSQUIRRELVM v,SQInteger idx); void sq_pushstring(HSQUIRRELVM v,const SQChar *s,SQInteger len); +static inline void sq_pushstring(HSQUIRRELVM v, const std::string &str, SQInteger len = -1) { sq_pushstring(v, str.c_str(), len == -1 ? str.size() : len); } void sq_pushfloat(HSQUIRRELVM v,SQFloat f); void sq_pushinteger(HSQUIRRELVM v,SQInteger n); void sq_pushbool(HSQUIRRELVM v,SQBool b); diff --git a/src/game/game_text.cpp b/src/game/game_text.cpp index dc78e6a927..9db7e52ad6 100644 --- a/src/game/game_text.cpp +++ b/src/game/game_text.cpp @@ -369,7 +369,7 @@ void RegisterGameTranslation(Squirrel *engine) int idx = 0; for (const auto &p : _current_data->string_names) { - sq_pushstring(vm, p.c_str(), -1); + sq_pushstring(vm, p, -1); sq_pushinteger(vm, idx); sq_rawset(vm, -3); idx++; diff --git a/src/script/script_instance.cpp b/src/script/script_instance.cpp index b7a4497aae..1383a4540b 100644 --- a/src/script/script_instance.cpp +++ b/src/script/script_instance.cpp @@ -618,7 +618,7 @@ bool ScriptInstance::IsPaused() } if (std::holds_alternative(value)) { - sq_pushstring(vm, std::get(value).c_str(), -1); + sq_pushstring(vm, std::get(value), -1); return true; }