1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-04-25 13:47:12 +02:00

Implement the pure typename meta-methods in chrono types using the standard method.

This commit is contained in:
Sandu Liviu Catalin 2016-11-15 21:20:33 +02:00
parent 27af2cfd3c
commit 60d6a96e07
8 changed files with 23 additions and 45 deletions

View File

@ -9,15 +9,10 @@
namespace SqMod { namespace SqMod {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
SQChar Date::Delimiter = '-'; SQMODE_DECL_TYPENAME(Typename, _SC("SqDate"))
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
SQInteger Date::Typename(HSQUIRRELVM vm) SQChar Date::Delimiter = '-';
{
static const SQChar name[] = _SC("SqDate");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Int32 Date::Compare(const Date & o) const Int32 Date::Compare(const Date & o) const
@ -373,7 +368,7 @@ Timestamp Date::GetTimestamp() const
// ================================================================================================ // ================================================================================================
void Register_ChronoDate(HSQUIRRELVM vm, Table & /*cns*/) void Register_ChronoDate(HSQUIRRELVM vm, Table & /*cns*/)
{ {
RootTable(vm).Bind(_SC("SqDate"), Class< Date >(vm, _SC("SqDate")) RootTable(vm).Bind(Typename::Str, Class< Date >(vm, Typename::Str)
// Constructors // Constructors
.Ctor() .Ctor()
.Ctor< Uint16 >() .Ctor< Uint16 >()
@ -382,8 +377,8 @@ void Register_ChronoDate(HSQUIRRELVM vm, Table & /*cns*/)
// Static Properties // Static Properties
.SetStaticValue(_SC("GlobalDelimiter"), &Date::Delimiter) .SetStaticValue(_SC("GlobalDelimiter"), &Date::Delimiter)
// Core Meta-methods // Core Meta-methods
.SquirrelFunc(_SC("_typename"), &Typename::Fn)
.Func(_SC("_tostring"), &Date::ToString) .Func(_SC("_tostring"), &Date::ToString)
.SquirrelFunc(_SC("_typename"), &Date::Typename)
.Func(_SC("_cmp"), &Date::Cmp) .Func(_SC("_cmp"), &Date::Cmp)
// Meta-methods // Meta-methods
.Func< Date (Date::*)(const Date &) const >(_SC("_add"), &Date::operator +) .Func< Date (Date::*)(const Date &) const >(_SC("_add"), &Date::operator +)

View File

@ -190,11 +190,6 @@ public:
*/ */
CSStr ToString() const; CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to retrieve the name from instances of this type.
*/
static SQInteger Typename(HSQUIRRELVM vm);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Assign the specified values. * Assign the specified values.
*/ */

View File

@ -8,19 +8,14 @@
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
namespace SqMod { namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqDatetime"))
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
SQChar Datetime::Delimiter = ' '; SQChar Datetime::Delimiter = ' ';
SQChar Datetime::DateDelim = '-'; SQChar Datetime::DateDelim = '-';
SQChar Datetime::TimeDelim = ':'; SQChar Datetime::TimeDelim = ':';
// ------------------------------------------------------------------------------------------------
SQInteger Datetime::Typename(HSQUIRRELVM vm)
{
static const SQChar name[] = _SC("SqDatetime");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Int32 Datetime::Compare(const Datetime & o) const Int32 Datetime::Compare(const Datetime & o) const
{ {
@ -753,7 +748,7 @@ Timestamp Datetime::GetTimestamp() const
// ================================================================================================ // ================================================================================================
void Register_ChronoDatetime(HSQUIRRELVM vm, Table & /*cns*/) void Register_ChronoDatetime(HSQUIRRELVM vm, Table & /*cns*/)
{ {
RootTable(vm).Bind(_SC("SqDatetime"), Class< Datetime >(vm, _SC("SqDatetime")) RootTable(vm).Bind(Typename::Str, Class< Datetime >(vm, Typename::Str)
// Constructors // Constructors
.Ctor() .Ctor()
.Ctor< Uint16 >() .Ctor< Uint16 >()
@ -768,8 +763,8 @@ void Register_ChronoDatetime(HSQUIRRELVM vm, Table & /*cns*/)
.SetStaticValue(_SC("GlobalDateDelim"), &Datetime::DateDelim) .SetStaticValue(_SC("GlobalDateDelim"), &Datetime::DateDelim)
.SetStaticValue(_SC("GlobalTimeDelim"), &Datetime::TimeDelim) .SetStaticValue(_SC("GlobalTimeDelim"), &Datetime::TimeDelim)
// Core Meta-methods // Core Meta-methods
.SquirrelFunc(_SC("_typename"), &Typename::Fn)
.Func(_SC("_tostring"), &Datetime::ToString) .Func(_SC("_tostring"), &Datetime::ToString)
.SquirrelFunc(_SC("_typename"), &Datetime::Typename)
.Func(_SC("_cmp"), &Datetime::Cmp) .Func(_SC("_cmp"), &Datetime::Cmp)
// Meta-methods // Meta-methods
.Func< Datetime (Datetime::*)(const Datetime &) const >(_SC("_add"), &Datetime::operator +) .Func< Datetime (Datetime::*)(const Datetime &) const >(_SC("_add"), &Datetime::operator +)

View File

@ -247,11 +247,6 @@ public:
*/ */
CSStr ToString() const; CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to retrieve the name from instances of this type.
*/
static SQInteger Typename(HSQUIRRELVM vm);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Assign the specified values. * Assign the specified values.
*/ */

View File

@ -9,15 +9,10 @@
namespace SqMod { namespace SqMod {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
SQChar Time::Delimiter = ':'; SQMODE_DECL_TYPENAME(Typename, _SC("SqTime"))
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
SQInteger Time::Typename(HSQUIRRELVM vm) SQChar Time::Delimiter = ':';
{
static const SQChar name[] = _SC("SqTime");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Int32 Time::Compare(const Time & o) const Int32 Time::Compare(const Time & o) const
@ -420,7 +415,7 @@ Timestamp Time::GetTimestamp() const
// ================================================================================================ // ================================================================================================
void Register_ChronoTime(HSQUIRRELVM vm, Table & /*cns*/) void Register_ChronoTime(HSQUIRRELVM vm, Table & /*cns*/)
{ {
RootTable(vm).Bind(_SC("SqTime"), Class< Time >(vm, _SC("SqTime")) RootTable(vm).Bind(Typename::Str, Class< Time >(vm, Typename::Str)
// Constructors // Constructors
.Ctor() .Ctor()
.Ctor< Uint8 >() .Ctor< Uint8 >()
@ -430,8 +425,8 @@ void Register_ChronoTime(HSQUIRRELVM vm, Table & /*cns*/)
// Static Properties // Static Properties
.SetStaticValue(_SC("GlobalDelimiter"), &Time::Delimiter) .SetStaticValue(_SC("GlobalDelimiter"), &Time::Delimiter)
// Core Meta-methods // Core Meta-methods
.SquirrelFunc(_SC("_typename"), &Typename::Fn)
.Func(_SC("_tostring"), &Time::ToString) .Func(_SC("_tostring"), &Time::ToString)
.SquirrelFunc(_SC("_typename"), &Time::Typename)
.Func(_SC("_cmp"), &Time::Cmp) .Func(_SC("_cmp"), &Time::Cmp)
// Meta-methods // Meta-methods
.Func< Time (Time::*)(const Time &) const >(_SC("_add"), &Time::operator +) .Func< Time (Time::*)(const Time &) const >(_SC("_add"), &Time::operator +)

View File

@ -201,11 +201,6 @@ public:
*/ */
CSStr ToString() const; CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to retrieve the name from instances of this type.
*/
static SQInteger Typename(HSQUIRRELVM vm);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Assign the specified values. * Assign the specified values.
*/ */

View File

@ -6,6 +6,9 @@
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
namespace SqMod { namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqTimer"))
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Timer::Timer() Timer::Timer()
: m_Timestamp(Chrono::GetCurrentSysTime()) : m_Timestamp(Chrono::GetCurrentSysTime())
@ -67,11 +70,12 @@ Int64 Timer::GetElapsedTimeRaw() const
// ================================================================================================ // ================================================================================================
void Register_ChronoTimer(HSQUIRRELVM vm, Table & /*cns*/) void Register_ChronoTimer(HSQUIRRELVM vm, Table & /*cns*/)
{ {
RootTable(vm).Bind(_SC("SqTimer"), Class< Timer >(vm, _SC("SqChronoTimer")) RootTable(vm).Bind(Typename::Str, Class< Timer >(vm, Typename::Str)
// Constructors // Constructors
.Ctor() .Ctor()
.Ctor< const Timer & >() .Ctor< const Timer & >()
// Core Meta-methods // Core Meta-methods
.SquirrelFunc(_SC("_typename"), &Typename::Fn)
.Func(_SC("_tostring"), &Timer::ToString) .Func(_SC("_tostring"), &Timer::ToString)
.Func(_SC("_cmp"), &Timer::Cmp) .Func(_SC("_cmp"), &Timer::Cmp)
// Properties // Properties

View File

@ -9,6 +9,9 @@
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
namespace SqMod { namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqTimestamp"))
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Timestamp::Timestamp(const SLongInt & t) Timestamp::Timestamp(const SLongInt & t)
: m_Timestamp(t.GetNum()) : m_Timestamp(t.GetNum())
@ -126,11 +129,12 @@ static Timestamp SqGetYears(SQFloat ammount)
// ================================================================================================ // ================================================================================================
void Register_ChronoTimestamp(HSQUIRRELVM vm, Table & /*cns*/) void Register_ChronoTimestamp(HSQUIRRELVM vm, Table & /*cns*/)
{ {
RootTable(vm).Bind(_SC("SqTimestamp"), Class< Timestamp >(vm, _SC("SqTimestamp")) RootTable(vm).Bind(Typename::Str, Class< Timestamp >(vm, Typename::Str)
// Constructors // Constructors
.Ctor() .Ctor()
.Ctor< const Timestamp & >() .Ctor< const Timestamp & >()
// Core Meta-methods // Core Meta-methods
.SquirrelFunc(_SC("_typename"), &Typename::Fn)
.Func(_SC("_tostring"), &Timestamp::ToString) .Func(_SC("_tostring"), &Timestamp::ToString)
.Func(_SC("_cmp"), &Timestamp::Cmp) .Func(_SC("_cmp"), &Timestamp::Cmp)
// Meta-methods // Meta-methods