From 77177f7e8b5ca4f43846b5ff4c031d5d7c7bd876 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Fri, 5 May 2023 19:31:06 +0200 Subject: [PATCH] Add: support for std::string parameters in the script API --- cmake/scripts/SquirrelExport.cmake | 2 ++ src/script/squirrel_helper.hpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/cmake/scripts/SquirrelExport.cmake b/cmake/scripts/SquirrelExport.cmake index 6fc6f094e6..76fbdd68ab 100644 --- a/cmake/scripts/SquirrelExport.cmake +++ b/cmake/scripts/SquirrelExport.cmake @@ -631,6 +631,8 @@ foreach(LINE IN LISTS SOURCE_LINES) string(APPEND TYPES "a") elseif("${PARAM}" MATCHES "^Text") string(APPEND TYPES ".") + elseif("${PARAM}" MATCHES "^std::string") + string(APPEND TYPES ".") else() string(APPEND TYPES "x") endif() diff --git a/src/script/squirrel_helper.hpp b/src/script/squirrel_helper.hpp index 02b584fe49..ed220b8b40 100644 --- a/src/script/squirrel_helper.hpp +++ b/src/script/squirrel_helper.hpp @@ -91,6 +91,20 @@ namespace SQConvert { } }; + template <> struct Param { + static inline const std::string Get(HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) + { + /* Convert what-ever there is as parameter to a string */ + sq_tostring(vm, index); + + const SQChar *tmp; + sq_getstring(vm, -1, &tmp); + std::string result = StrMakeValid(tmp); + sq_poptop(vm); + return result; + } + }; + template struct Param> { static inline Array Get(HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr)