From bf734928a997d7a1a266e57b4c233c35806c6cb7 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Tue, 15 Nov 2016 21:43:02 +0200 Subject: [PATCH] Implement the pure typename meta-methods in Routine type using the standard method. --- source/Routine.cpp | 20 +++++++------------- source/Routine.hpp | 5 ----- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/source/Routine.cpp b/source/Routine.cpp index 7af054d0..af6c44e5 100644 --- a/source/Routine.cpp +++ b/source/Routine.cpp @@ -9,20 +9,15 @@ // ------------------------------------------------------------------------------------------------ namespace SqMod { +// ------------------------------------------------------------------------------------------------ +SQMODE_DECL_TYPENAME(Typename, _SC("SqRoutine")) + // ------------------------------------------------------------------------------------------------ Routine::Time Routine::s_Last = 0; Routine::Time Routine::s_Prev = 0; Routine::Routines Routine::s_Routines; Routine::Objects Routine::s_Objects; -// ------------------------------------------------------------------------------------------------ -SQInteger Routine::Typename(HSQUIRRELVM vm) -{ - static const SQChar name[] = _SC("SqRoutine"); - sq_pushstring(vm, name, sizeof(name)); - return 1; -} - // ------------------------------------------------------------------------------------------------ void Routine::Process() { @@ -983,13 +978,12 @@ void TerminateRoutines() // ================================================================================================ void Register_Routine(HSQUIRRELVM vm) { - RootTable(vm).Bind(_SC("SqRoutine"), - Class< Routine, NoConstructor< Routine > >(vm, _SC("SqRoutine")) + RootTable(vm).Bind(Typename::Str, + Class< Routine, NoConstructor< Routine > >(vm, Typename::Str) // Meta-methods - .Func(_SC("_tostring"), &Routine::ToString) - .SquirrelFunc(_SC("_typename"), &Routine::Typename) - // We cannot set _cmp for c++ classes so we use this instead .SquirrelFunc(_SC("cmp"), &SqDynArgFwd< SqDynArgCmpFn< Routine >, SQInteger, SQFloat, bool, std::nullptr_t, Routine >) + .SquirrelFunc(_SC("_typename"), &Typename::Fn) + .Func(_SC("_tostring"), &Routine::ToString) // Properties .Prop(_SC("Tag"), &Routine::GetTag, &Routine::SetTag) .Prop(_SC("Data"), &Routine::GetData, &Routine::SetData) diff --git a/source/Routine.hpp b/source/Routine.hpp index c3dbd8bf..7b4d1120 100644 --- a/source/Routine.hpp +++ b/source/Routine.hpp @@ -285,11 +285,6 @@ public: */ CSStr ToString() const; - /* -------------------------------------------------------------------------------------------- - * Used by the script engine to retrieve the name from instances of this type. - */ - static SQInteger Typename(HSQUIRRELVM vm); - /* -------------------------------------------------------------------------------------------- * Retrieve the associated user tag. */