From b05b6409b8905811cab22294051d2b091b9eb64f Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Wed, 24 Aug 2016 23:17:18 +0300 Subject: [PATCH] Update the Color4 type to use the new dynamic dispatching system for metamethods. --- source/Base/Color4.cpp | 13 +++++++------ source/Base/Color4.hpp | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/source/Base/Color4.cpp b/source/Base/Color4.cpp index 3e058f31..fe2c170d 100644 --- a/source/Base/Color4.cpp +++ b/source/Base/Color4.cpp @@ -2,6 +2,7 @@ #include "Base/Color4.hpp" #include "Base/Color3.hpp" #include "Base/Shared.hpp" +#include "Base/DynArg.hpp" #include "Library/Numeric/Random.hpp" // ------------------------------------------------------------------------------------------------ @@ -779,13 +780,13 @@ void Register_Color4(HSQUIRRELVM vm) // Core Meta-methods .Func(_SC("_tostring"), &Color4::ToString) .SquirrelFunc(_SC("_typename"), &Color4::Typename) - .Func(_SC("_cmp"), &Color4::Cmp) + .SquirrelFunc(_SC("cmp"), &SqDynArgFwd< SqDynArgCmpFn< Color4 >, SQFloat, SQInteger, bool, std::nullptr_t, Color4 >) // Meta-methods - .Func< Color4 (Color4::*)(const Color4 &) const >(_SC("_add"), &Color4::operator +) - .Func< Color4 (Color4::*)(const Color4 &) const >(_SC("_sub"), &Color4::operator -) - .Func< Color4 (Color4::*)(const Color4 &) const >(_SC("_mul"), &Color4::operator *) - .Func< Color4 (Color4::*)(const Color4 &) const >(_SC("_div"), &Color4::operator /) - .Func< Color4 (Color4::*)(const Color4 &) const >(_SC("_modulo"), &Color4::operator %) + .SquirrelFunc(_SC("_add"), &SqDynArgFwd< SqDynArgAddFn< Color4 >, SQFloat, SQInteger, bool, std::nullptr_t, Color4 >) + .SquirrelFunc(_SC("_sub"), &SqDynArgFwd< SqDynArgSubFn< Color4 >, SQFloat, SQInteger, bool, std::nullptr_t, Color4 >) + .SquirrelFunc(_SC("_mul"), &SqDynArgFwd< SqDynArgMulFn< Color4 >, SQFloat, SQInteger, bool, std::nullptr_t, Color4 >) + .SquirrelFunc(_SC("_div"), &SqDynArgFwd< SqDynArgDivFn< Color4 >, SQFloat, SQInteger, bool, std::nullptr_t, Color4 >) + .SquirrelFunc(_SC("_modulo"), &SqDynArgFwd< SqDynArgModFn< Color4 >, SQFloat, SQInteger, bool, std::nullptr_t, Color4 >) .Func< Color4 (Color4::*)(void) const >(_SC("_unm"), &Color4::operator -) // Properties .Prop(_SC("RGB"), &Color4::GetRGB, &Color4::SetRGB) diff --git a/source/Base/Color4.hpp b/source/Base/Color4.hpp index 6568e9b8..5ab00538 100644 --- a/source/Base/Color4.hpp +++ b/source/Base/Color4.hpp @@ -369,6 +369,30 @@ struct Color4 */ Int32 Cmp(const Color4 & c) const; + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with a scalar value. + */ + Int32 Cmp(Int32 s) const + { + return Cmp(Color4(static_cast< Value >(s))); + } + + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with a scalar value. + */ + Int32 Cmp(Float32 s) const + { + return Cmp(Color4(static_cast< Value >(s))); + } + + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with a scalar value. + */ + Int32 Cmp(std::nullptr_t) const + { + return Cmp(Color4(static_cast< Value >(0))); + } + /* -------------------------------------------------------------------------------------------- * Used by the script engine to convert an instance of this type to a string. */