1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-01-19 12:07:13 +01:00

Update the Vector2 type to use the new dynamic dispatching system for metamethods.

This commit is contained in:
Sandu Liviu Catalin 2016-08-24 23:18:00 +03:00
parent 1a409b4919
commit ee7880d7f4
2 changed files with 31 additions and 6 deletions

View File

@ -2,6 +2,7 @@
#include "Base/Vector2.hpp" #include "Base/Vector2.hpp"
#include "Base/Vector2i.hpp" #include "Base/Vector2i.hpp"
#include "Base/Shared.hpp" #include "Base/Shared.hpp"
#include "Base/DynArg.hpp"
#include "Library/Numeric/Random.hpp" #include "Library/Numeric/Random.hpp"
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -463,13 +464,13 @@ void Register_Vector2(HSQUIRRELVM vm)
// Core Meta-methods // Core Meta-methods
.Func(_SC("_tostring"), &Vector2::ToString) .Func(_SC("_tostring"), &Vector2::ToString)
.SquirrelFunc(_SC("_typename"), &Vector2::Typename) .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 // Meta-methods
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_add"), &Vector2::operator +) .SquirrelFunc(_SC("_add"), &SqDynArgFwd< SqDynArgAddFn< Vector2 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector2 >)
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_sub"), &Vector2::operator -) .SquirrelFunc(_SC("_sub"), &SqDynArgFwd< SqDynArgSubFn< Vector2 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector2 >)
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_mul"), &Vector2::operator *) .SquirrelFunc(_SC("_mul"), &SqDynArgFwd< SqDynArgMulFn< Vector2 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector2 >)
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_div"), &Vector2::operator /) .SquirrelFunc(_SC("_div"), &SqDynArgFwd< SqDynArgDivFn< Vector2 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector2 >)
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_modulo"), &Vector2::operator %) .SquirrelFunc(_SC("_modulo"), &SqDynArgFwd< SqDynArgModFn< Vector2 >, SQFloat, SQInteger, bool, std::nullptr_t, Vector2 >)
.Func< Vector2 (Vector2::*)(void) const >(_SC("_unm"), &Vector2::operator -) .Func< Vector2 (Vector2::*)(void) const >(_SC("_unm"), &Vector2::operator -)
// Properties // Properties
.Prop(_SC("Abs"), &Vector2::Abs) .Prop(_SC("Abs"), &Vector2::Abs)

View File

@ -254,6 +254,30 @@ struct Vector2
*/ */
Int32 Cmp(const Vector2 & v) const; 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. * Used by the script engine to convert an instance of this type to a string.
*/ */