From ee7880d7f42fe21846de9ecb54f0692424ecc67b Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Wed, 24 Aug 2016 23:18:00 +0300 Subject: [PATCH] Update the Vector2 type to use the new dynamic dispatching system for metamethods. --- source/Base/Vector2.cpp | 13 +++++++------ source/Base/Vector2.hpp | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/source/Base/Vector2.cpp b/source/Base/Vector2.cpp index 126f8b43..9ee79847 100644 --- a/source/Base/Vector2.cpp +++ b/source/Base/Vector2.cpp @@ -2,6 +2,7 @@ #include "Base/Vector2.hpp" #include "Base/Vector2i.hpp" #include "Base/Shared.hpp" +#include "Base/DynArg.hpp" #include "Library/Numeric/Random.hpp" // ------------------------------------------------------------------------------------------------ @@ -463,13 +464,13 @@ void Register_Vector2(HSQUIRRELVM vm) // Core Meta-methods .Func(_SC("_tostring"), &Vector2::ToString) .SquirrelFunc(_SC("_typename"), &Vector2::Typename) - .Func(_SC("_cmp"), &Vector2::Cmp) + .SquirrelFunc(_SC("cmp"), &SqDynArgFwd< SqDynArgCmpFn< Vector2 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector2 >) // Meta-methods - .Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_add"), &Vector2::operator +) - .Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_sub"), &Vector2::operator -) - .Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_mul"), &Vector2::operator *) - .Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_div"), &Vector2::operator /) - .Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_modulo"), &Vector2::operator %) + .SquirrelFunc(_SC("_add"), &SqDynArgFwd< SqDynArgAddFn< Vector2 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector2 >) + .SquirrelFunc(_SC("_sub"), &SqDynArgFwd< SqDynArgSubFn< Vector2 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector2 >) + .SquirrelFunc(_SC("_mul"), &SqDynArgFwd< SqDynArgMulFn< Vector2 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector2 >) + .SquirrelFunc(_SC("_div"), &SqDynArgFwd< SqDynArgDivFn< Vector2 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector2 >) + .SquirrelFunc(_SC("_modulo"), &SqDynArgFwd< SqDynArgModFn< Vector2 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector2 >) .Func< Vector2 (Vector2::*)(void) const >(_SC("_unm"), &Vector2::operator -) // Properties .Prop(_SC("Abs"), &Vector2::Abs) diff --git a/source/Base/Vector2.hpp b/source/Base/Vector2.hpp index 58087338..9ec3b8a8 100644 --- a/source/Base/Vector2.hpp +++ b/source/Base/Vector2.hpp @@ -254,6 +254,30 @@ struct Vector2 */ Int32 Cmp(const Vector2 & v) const; + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with a scalar value. + */ + Int32 Cmp(Value s) const + { + return Cmp(Vector2(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with a scalar value. + */ + Int32 Cmp(Int32 s) const + { + return Cmp(Vector2(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(Vector2(static_cast< Value >(0))); + } + /* -------------------------------------------------------------------------------------------- * Used by the script engine to convert an instance of this type to a string. */