From f34e04ee48f8ec0b5e72ee530dbe0693f072ee0e Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sun, 19 Jan 2025 14:52:44 +0100 Subject: [PATCH] Codechange: allow mapping enums as parameter and return type from scripts --- src/script/squirrel_helper.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/script/squirrel_helper.hpp b/src/script/squirrel_helper.hpp index 3adf637500..51ce3bf9cb 100644 --- a/src/script/squirrel_helper.hpp +++ b/src/script/squirrel_helper.hpp @@ -44,6 +44,14 @@ namespace SQConvert { template <> struct Return { static inline int Set(HSQUIRRELVM vm, void *res) { sq_pushuserpointer(vm, res); return 1; } }; template <> struct Return { static inline int Set(HSQUIRRELVM vm, HSQOBJECT res) { sq_pushobject(vm, res); return 1; } }; + template requires std::is_enum_v struct Return { + static inline int Set(HSQUIRRELVM vm, T res) + { + sq_pushinteger(vm, to_underlying(res)); + return 1; + } + }; + template <> struct Return> { static inline int Set(HSQUIRRELVM vm, std::optional res) { @@ -75,6 +83,15 @@ namespace SQConvert { template <> struct Param { /* Do not use const char *, use std::string& instead. */ }; template <> struct Param { static inline void *Get(HSQUIRRELVM vm, int index) { SQUserPointer tmp; sq_getuserpointer(vm, index, &tmp); return tmp; } }; + template requires std::is_enum_v struct Param { + static inline T Get(HSQUIRRELVM vm, int index) + { + SQInteger tmp; + sq_getinteger(vm, index, &tmp); + return static_cast(tmp); + } + }; + template <> struct Param { static inline const std::string Get(HSQUIRRELVM vm, int index) {