From 0a44e9cfa44ac44d5042869fa80b2e3daf503865 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Sun, 6 Aug 2023 21:33:04 +0300 Subject: [PATCH] Update dpp::snowflake conversion to script values. This changed in the past to being just a fundamental integer type to a class wrapper. --- module/Library/Discord/Utilities.hpp | 63 ++++++++++++++++++---------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/module/Library/Discord/Utilities.hpp b/module/Library/Discord/Utilities.hpp index 1802c7aa..dc96af87 100644 --- a/module/Library/Discord/Utilities.hpp +++ b/module/Library/Discord/Utilities.hpp @@ -12,32 +12,49 @@ // ------------------------------------------------------------------------------------------------ namespace Sqrat { -// Allow the VM to treat the dpp::snowflake type as a integer. -template<> struct Var -{ - dpp::snowflake value; - Var(HSQUIRRELVM vm, SQInteger idx) - { - sq_getinteger(vm, idx, reinterpret_cast(&static_cast(value))); +// // Allow the VM to treat the dpp::snowflake type as a integer. +// template<> struct Var +// { +// dpp::snowflake value; +// Var(HSQUIRRELVM vm, SQInteger idx) { +// sq_getinteger(vm, idx, reinterpret_cast(&static_cast(value))); +// } +// inline static void push(HSQUIRRELVM vm, const dpp::snowflake& value) noexcept { +// sq_pushinteger(vm, static_cast(static_cast(value))); +// } +// }; + +// // Allow the VM to treat the dpp::snowflake type as a integer. +// template<> struct Var +// { +// dpp::snowflake value; +// Var(HSQUIRRELVM vm, SQInteger idx) { +// sq_getinteger(vm, idx, reinterpret_cast(&static_cast(value))); +// } +// inline static void push(HSQUIRRELVM vm, const dpp::snowflake& value) noexcept { +// sq_pushinteger(vm, static_cast(static_cast(value))); +// } +// }; + + +// ------------------------------------------------------------------------------------------------ +// Used to get and push dpp::snowflake instances to and from the stack +template <> struct Var { + dpp::snowflake value; ///< The actual value of get operations + Var(HSQUIRRELVM vm, SQInteger idx) : value(popAsInt< uint64_t, true >(vm, idx).value) { } + // Push dpp::snowflake instances to the stack as integers + static void push(HSQUIRRELVM vm, const dpp::snowflake& value) noexcept { + sq_pushinteger(vm, static_cast< SQInteger >(static_cast< std::uint64_t >(value))); } - inline static void push(HSQUIRRELVM vm, const dpp::snowflake& value) noexcept - { - sq_pushinteger(vm, static_cast(static_cast(value))); + static void push(HSQUIRRELVM vm, dpp::snowflake& value) noexcept { + sq_pushinteger(vm, static_cast< SQInteger >(static_cast< std::uint64_t & >(value))); } }; - -// Allow the VM to treat the dpp::snowflake type as a integer. -template<> struct Var -{ - dpp::snowflake value; - Var(HSQUIRRELVM vm, SQInteger idx) - { - sq_getinteger(vm, idx, reinterpret_cast(&static_cast(value))); - } - inline static void push(HSQUIRRELVM vm, const dpp::snowflake& value) noexcept - { - sq_pushinteger(vm, static_cast(static_cast(value))); - } +template <> struct Var : public Var { + Var(HSQUIRRELVM vm, SQInteger idx) : Var(vm, idx) { } +}; +template <> struct Var : public Var { + Var(HSQUIRRELVM vm, SQInteger idx) : Var(vm, idx) { } }; }