From 86fcceb6ce53ce555279e68efed369f807e3d903 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Wed, 24 Aug 2016 22:29:00 +0300 Subject: [PATCH] Update the Routine type to use the new dynamic dispatching system for metamethods. --- source/Base/Vector3.cpp | 17 ++++++++++------- source/Base/Vector3.hpp | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/source/Base/Vector3.cpp b/source/Base/Vector3.cpp index 24ece1b9..d55751f1 100644 --- a/source/Base/Vector3.cpp +++ b/source/Base/Vector3.cpp @@ -3,6 +3,7 @@ #include "Base/Vector4.hpp" #include "Base/Quaternion.hpp" #include "Base/Shared.hpp" +#include "Base/DynArg.hpp" #include "Library/Numeric/Random.hpp" // ------------------------------------------------------------------------------------------------ @@ -409,7 +410,7 @@ void Vector3::SetQuaternionEx(Value qx, Value qy, Value qz, Value qw) z = std::atan2((STOVAL(2.0) * qy * qz) - (STOVAL(2.0) * qx * qw), (STOVAL(2.0) * qx * qz) + (STOVAL(2.0) * qy * qw)); x = STOVAL(0.0); - + // If facing down, reverse yaw if (EpsLt(y, STOVAL(0.0))) { @@ -723,13 +724,15 @@ void Register_Vector3(HSQUIRRELVM vm) // Core Meta-methods .Func(_SC("_tostring"), &Vector3::ToString) .SquirrelFunc(_SC("_typename"), &Vector3::Typename) - .Func(_SC("_cmp"), &Vector3::Cmp) + // We cannot set _cmp for c++ classes so we use this instead + .SquirrelFunc(_SC("cmp"), &SqDynArgFwd< SqDynArgCmpFn< Vector3 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector3 >) + //.Func(_SC("_cmp"), &Vector3::Cmp) // Meta-methods - .Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("_add"), &Vector3::operator +) - .Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("_sub"), &Vector3::operator -) - .Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("_mul"), &Vector3::operator *) - .Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("_div"), &Vector3::operator /) - .Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("_modulo"), &Vector3::operator %) + .SquirrelFunc(_SC("_add"), &SqDynArgFwd< SqDynArgAddFn< Vector3 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector3 >) + .SquirrelFunc(_SC("_sub"), &SqDynArgFwd< SqDynArgSubFn< Vector3 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector3 >) + .SquirrelFunc(_SC("_mul"), &SqDynArgFwd< SqDynArgMulFn< Vector3 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector3 >) + .SquirrelFunc(_SC("_div"), &SqDynArgFwd< SqDynArgDivFn< Vector3 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector3 >) + .SquirrelFunc(_SC("_modulo"), &SqDynArgFwd< SqDynArgModFn< Vector3 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector3 >) .Func< Vector3 (Vector3::*)(void) const >(_SC("_unm"), &Vector3::operator -) // Properties .Prop(_SC("Abs"), &Vector3::Abs) diff --git a/source/Base/Vector3.hpp b/source/Base/Vector3.hpp index 367b28fc..6ae3da83 100644 --- a/source/Base/Vector3.hpp +++ b/source/Base/Vector3.hpp @@ -261,6 +261,30 @@ struct Vector3 */ Int32 Cmp(const Vector3 & 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(Vector3(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with a scalar value. + */ + Int32 Cmp(Int32 s) const + { + return Cmp(Vector3(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(static_cast< Value >(0)); + } + /* -------------------------------------------------------------------------------------------- * Used by the script engine to convert an instance of this type to a string. */