mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-21 17:47:13 +02:00
Initial implementation of the standard math library.
Implemented utilities to convert between fundamental types. Implemented helper functions to retrieve numeric values from the stack at all costs. Implemented various delegates on the long integer types to mimic the standard types. Moved most of the stack utilities in a separate source. Various other fixes and improvements.
This commit is contained in:
@ -173,7 +173,7 @@ extern void Register_ChronoTime(HSQUIRRELVM vm, Table & cns);
|
||||
extern void Register_ChronoTimer(HSQUIRRELVM vm, Table & cns);
|
||||
extern void Register_ChronoTimestamp(HSQUIRRELVM vm, Table & cns);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// ================================================================================================
|
||||
void Register_Chrono(HSQUIRRELVM vm)
|
||||
{
|
||||
Table cns(vm);
|
||||
|
@ -1,6 +1,7 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Crypt.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cstdlib>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,12 @@
|
||||
#ifndef _LIBRARY_MATH_HPP_
|
||||
#define _LIBRARY_MATH_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Base/Shared.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_MATH_HPP_
|
||||
|
@ -54,7 +54,7 @@ LongInt< Uint64 > & LongInt< Uint64 >::operator = (CSStr text)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr LongInt< Uint64 >::ToString()
|
||||
{
|
||||
if (snprintf(m_Text, sizeof(m_Text), "%llu", m_Data) < 0)
|
||||
if (std::snprintf(m_Text, sizeof(m_Text), "%llu", m_Data) < 0)
|
||||
{
|
||||
m_Text[0] = 0;
|
||||
}
|
||||
@ -82,6 +82,12 @@ void Register_Numeric(HSQUIRRELVM vm)
|
||||
.Func(_SC("_tostring"), &SLongInt::ToString)
|
||||
.Func(_SC("_typename"), &SLongInt::Typename)
|
||||
.Func(_SC("_cmp"), &SLongInt::Cmp)
|
||||
/* Core Functions */
|
||||
.Func(_SC("tointeger"), &SLongInt::ToSqInteger)
|
||||
.Func(_SC("tofloat"), &SLongInt::ToSqFloat)
|
||||
.Func(_SC("tostring"), &SLongInt::ToSqString)
|
||||
.Func(_SC("tobool"), &SLongInt::ToSqBool)
|
||||
.Func(_SC("tochar"), &SLongInt::ToSqChar)
|
||||
/* Metamethods */
|
||||
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_add"), &SLongInt::operator +)
|
||||
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_sub"), &SLongInt::operator -)
|
||||
@ -112,6 +118,12 @@ void Register_Numeric(HSQUIRRELVM vm)
|
||||
.Func(_SC("_tostring"), &ULongInt::ToString)
|
||||
.Func(_SC("_typename"), &ULongInt::Typename)
|
||||
.Func(_SC("_cmp"), &ULongInt::Cmp)
|
||||
/* Core Functions */
|
||||
.Func(_SC("tointeger"), &ULongInt::ToSqInteger)
|
||||
.Func(_SC("tofloat"), &ULongInt::ToSqFloat)
|
||||
.Func(_SC("tostring"), &ULongInt::ToSqString)
|
||||
.Func(_SC("tobool"), &ULongInt::ToSqBool)
|
||||
.Func(_SC("tochar"), &ULongInt::ToSqChar)
|
||||
/* Metamethods */
|
||||
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_add"), &ULongInt::operator +)
|
||||
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_sub"), &ULongInt::operator -)
|
||||
|
@ -199,7 +199,7 @@ public:
|
||||
*/
|
||||
SQInteger GetSNum() const
|
||||
{
|
||||
return (SQInteger)(m_Data);
|
||||
return ClampL< Type, SQInteger >(m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -222,6 +222,46 @@ public:
|
||||
void Random(Type n);
|
||||
void Random(Type m, Type n);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel integer.
|
||||
*/
|
||||
SQInteger ToSqInteger() const
|
||||
{
|
||||
return ClampL< Type, SQInteger >(m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel float.
|
||||
*/
|
||||
SQFloat ToSqFloat() const
|
||||
{
|
||||
return ClampL< Float64, SQFloat >(static_cast< Float64 >(m_Data));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel string.
|
||||
*/
|
||||
CSStr ToSqString()
|
||||
{
|
||||
return ToString();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel boolean.
|
||||
*/
|
||||
bool ToSqBool() const
|
||||
{
|
||||
return (m_Data > 0);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel character.
|
||||
*/
|
||||
SQChar ToSqChar() const
|
||||
{
|
||||
return ClampL< Type, SQChar >(m_Data);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
@ -441,6 +481,46 @@ public:
|
||||
void Random(Type n);
|
||||
void Random(Type m, Type n);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel integer.
|
||||
*/
|
||||
SQInteger ToSqInteger() const
|
||||
{
|
||||
return ClampL< Type, SQInteger >(m_Data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel float.
|
||||
*/
|
||||
SQFloat ToSqFloat() const
|
||||
{
|
||||
return ClampL< Float64, SQFloat >(static_cast< Float64 >(m_Data));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel string.
|
||||
*/
|
||||
CSStr ToSqString()
|
||||
{
|
||||
return ToString();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel boolean.
|
||||
*/
|
||||
bool ToSqBool() const
|
||||
{
|
||||
return (m_Data > 0);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel character.
|
||||
*/
|
||||
SQChar ToSqChar() const
|
||||
{
|
||||
return ClampL< Type, SQChar >(m_Data);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "Library/String.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Buffer.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cctype>
|
||||
|
@ -1,5 +1,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/SysEnv.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cctype>
|
||||
|
@ -1,6 +1,7 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/SysPath.hpp"
|
||||
#include "Library/SysEnv.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cctype>
|
||||
|
Reference in New Issue
Block a user