mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
Codechange: allow mapping enums as parameter and return type from scripts
This commit is contained in:
parent
e39f974d7d
commit
f34e04ee48
@ -44,6 +44,14 @@ namespace SQConvert {
|
||||
template <> struct Return<void *> { static inline int Set(HSQUIRRELVM vm, void *res) { sq_pushuserpointer(vm, res); return 1; } };
|
||||
template <> struct Return<HSQOBJECT> { static inline int Set(HSQUIRRELVM vm, HSQOBJECT res) { sq_pushobject(vm, res); return 1; } };
|
||||
|
||||
template <typename T> requires std::is_enum_v<T> struct Return<T> {
|
||||
static inline int Set(HSQUIRRELVM vm, T res)
|
||||
{
|
||||
sq_pushinteger(vm, to_underlying(res));
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template <> struct Return<std::optional<std::string>> {
|
||||
static inline int Set(HSQUIRRELVM vm, std::optional<std::string> res)
|
||||
{
|
||||
@ -75,6 +83,15 @@ namespace SQConvert {
|
||||
template <> struct Param<const char *> { /* Do not use const char *, use std::string& instead. */ };
|
||||
template <> struct Param<void *> { static inline void *Get(HSQUIRRELVM vm, int index) { SQUserPointer tmp; sq_getuserpointer(vm, index, &tmp); return tmp; } };
|
||||
|
||||
template <typename T> requires std::is_enum_v<T> struct Param<T> {
|
||||
static inline T Get(HSQUIRRELVM vm, int index)
|
||||
{
|
||||
SQInteger tmp;
|
||||
sq_getinteger(vm, index, &tmp);
|
||||
return static_cast<T>(tmp);
|
||||
}
|
||||
};
|
||||
|
||||
template <> struct Param<const std::string &> {
|
||||
static inline const std::string Get(HSQUIRRELVM vm, int index)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user