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) { } }; }