From f18d4c948a90a0e89eb8ec929f590c30dc8207da Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Tue, 15 Nov 2016 21:24:39 +0200 Subject: [PATCH] Implement the pure typename meta-methods in Sphere type using the standard method. --- source/Base/Sphere.cpp | 19 +++++++------------ source/Base/Sphere.hpp | 7 +------ 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/source/Base/Sphere.cpp b/source/Base/Sphere.cpp index b2fe7152..40aa2fbc 100644 --- a/source/Base/Sphere.cpp +++ b/source/Base/Sphere.cpp @@ -10,6 +10,9 @@ // ------------------------------------------------------------------------------------------------ namespace SqMod { +// ------------------------------------------------------------------------------------------------ +SQMODE_DECL_TYPENAME(Typename, _SC("Sphere")) + // ------------------------------------------------------------------------------------------------ const Sphere Sphere::NIL = Sphere(); const Sphere Sphere::MIN = Sphere(0.0); @@ -18,14 +21,6 @@ const Sphere Sphere::MAX = Sphere(std::numeric_limits< Sphere::Value >::max()); // ------------------------------------------------------------------------------------------------ SQChar Sphere::Delim = ','; -// ------------------------------------------------------------------------------------------------ -SQInteger Sphere::Typename(HSQUIRRELVM vm) -{ - static const SQChar name[] = _SC("Sphere"); - sq_pushstring(vm, name, sizeof(name)); - return 1; -} - // ------------------------------------------------------------------------------------------------ Sphere::Sphere() : pos(0.0), rad(0.0) @@ -546,7 +541,7 @@ void Register_Sphere(HSQUIRRELVM vm) { typedef Sphere::Value Val; - RootTable(vm).Bind(_SC("Sphere"), Class< Sphere >(vm, _SC("Sphere")) + RootTable(vm).Bind(Typename::Str, Class< Sphere >(vm, Typename::Str) // Constructors .Ctor() .Ctor< Val >() @@ -558,9 +553,9 @@ void Register_Sphere(HSQUIRRELVM vm) .Var(_SC("Pos"), &Sphere::pos) .Var(_SC("Rad"), &Sphere::rad) // Core Meta-methods - .Func(_SC("_tostring"), &Sphere::ToString) - .SquirrelFunc(_SC("_typename"), &Sphere::Typename) .SquirrelFunc(_SC("cmp"), &SqDynArgFwd< SqDynArgCmpFn< Sphere >, SQFloat, SQInteger, bool, std::nullptr_t, Sphere >) + .SquirrelFunc(_SC("_typename"), &Typename::Fn) + .Func(_SC("_tostring"), &Sphere::ToString) // Meta-methods .SquirrelFunc(_SC("_add"), &SqDynArgFwd< SqDynArgAddFn< Sphere >, SQFloat, SQInteger, bool, std::nullptr_t, Sphere >) .SquirrelFunc(_SC("_sub"), &SqDynArgFwd< SqDynArgSubFn< Sphere >, SQFloat, SQInteger, bool, std::nullptr_t, Sphere >) @@ -636,4 +631,4 @@ void Register_Sphere(HSQUIRRELVM vm) ); } -} // Namespace:: SqMod +} // Namespace:: SqMod \ No newline at end of file diff --git a/source/Base/Sphere.hpp b/source/Base/Sphere.hpp index efa195cb..127330b6 100644 --- a/source/Base/Sphere.hpp +++ b/source/Base/Sphere.hpp @@ -343,11 +343,6 @@ struct Sphere */ CSStr ToString() const; - /* -------------------------------------------------------------------------------------------- - * Used by the script engine to retrieve the name from instances of this type. - */ - static SQInteger Typename(HSQUIRRELVM vm); - /* -------------------------------------------------------------------------------------------- * Set the specified radius. */ @@ -430,4 +425,4 @@ struct Sphere } // Namespace:: SqMod -#endif // _BASE_SPHERE_HPP_ +#endif // _BASE_SPHERE_HPP_ \ No newline at end of file