diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index 3ab4a0af4e..04babb9c1d 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -1318,6 +1318,7 @@ int64_t ReadValue(const void *ptr, VarType conv); void WriteValue(void *ptr, VarType conv, int64_t val); void SlSetArrayIndex(uint index); +static void SlSetArrayIndex(const ConvertibleThroughBase auto &index) { SlSetArrayIndex(index.base()); } int SlIterateArray(); void SlSetStructListLength(size_t length); diff --git a/src/script/api/script_list.hpp b/src/script/api/script_list.hpp index 64eb6d821c..0570364e24 100644 --- a/src/script/api/script_list.hpp +++ b/src/script/api/script_list.hpp @@ -43,13 +43,19 @@ private: int modifications; ///< Number of modification that has been done. To prevent changing data while valuating. protected: + /* Temporary helper functions to get the raw index from either strongly and non-strongly typed pool items. */ + template + static auto GetRawIndex(const T &index) { return index; } + template + static auto GetRawIndex(const T &index) { return index.base(); } + template static void FillList(ScriptList *list, ItemValid item_valid, ItemFilter item_filter) { for (const T *item : T::Iterate()) { if (!item_valid(item)) continue; if (!item_filter(item)) continue; - list->AddItem(item->index); + list->AddItem(GetRawIndex(item->index)); } } @@ -99,7 +105,7 @@ protected: /* Push the root table as instance object, this is what squirrel does for meta-functions. */ sq_pushroottable(vm); /* Push all arguments for the valuator function. */ - sq_pushinteger(vm, item->index); + sq_pushinteger(vm, GetRawIndex(item->index)); for (int i = 0; i < nparam - 1; i++) { sq_push(vm, i + 3); } diff --git a/src/script/squirrel.hpp b/src/script/squirrel.hpp index b816f81216..712f40897c 100644 --- a/src/script/squirrel.hpp +++ b/src/script/squirrel.hpp @@ -11,6 +11,7 @@ #define SQUIRREL_HPP #include +#include "../core/convertible_through_base.hpp" /** The type of script we're working with, i.e. for who is it? */ enum class ScriptType : uint8_t { @@ -110,6 +111,8 @@ public: */ void AddConst(const char *var_name, uint value) { this->AddConst(var_name, (int)value); } + void AddConst(const char *var_name, const ConvertibleThroughBase auto &value) { this->AddConst(var_name, static_cast(value.base())); } + /** * Adds a const to the stack. Depending on the current state this means * either a const to a class or to the global space. @@ -152,6 +155,7 @@ public: void InsertResult(bool result); void InsertResult(int result); void InsertResult(uint result) { this->InsertResult((int)result); } + void InsertResult(ConvertibleThroughBase auto result) { this->InsertResult(static_cast(result.base())); } /** * Call a method of an instance, in various flavors.