2016-06-03 20:26:19 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
#include "Core/Common.hpp"
|
|
|
|
#include "Core/Buffer.hpp"
|
|
|
|
#include "Core/Utility.hpp"
|
|
|
|
#include "Library/Numeric/Long.hpp"
|
2016-06-03 20:26:19 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
#include <cerrno>
|
2016-06-03 20:26:19 +02:00
|
|
|
#include <cstdarg>
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#ifdef SQMOD_OS_WINDOWS
|
|
|
|
#include <windows.h>
|
|
|
|
#endif // SQMOD_OS_WINDOWS
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
PluginFuncs * _Func = nullptr; //NOLINT(bugprone-reserved-identifier)
|
|
|
|
PluginCallbacks * _Clbk = nullptr; //NOLINT(bugprone-reserved-identifier)
|
|
|
|
PluginInfo * _Info = nullptr; //NOLINT(bugprone-reserved-identifier)
|
2016-06-03 20:26:19 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Raw console message output.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
static inline void OutputMessageImpl(const char * msg, va_list args)
|
2016-06-03 20:26:19 +02:00
|
|
|
{
|
|
|
|
#ifdef SQMOD_OS_WINDOWS
|
|
|
|
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csb_before;
|
|
|
|
GetConsoleScreenBufferInfo( hstdout, &csb_before);
|
|
|
|
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN);
|
|
|
|
std::printf("[SQMOD] ");
|
|
|
|
|
2020-03-22 08:16:40 +01:00
|
|
|
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY); // NOLINT(hicpp-signed-bitwise)
|
2016-06-03 20:26:19 +02:00
|
|
|
std::vprintf(msg, args);
|
|
|
|
std::puts("");
|
|
|
|
|
|
|
|
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
|
|
|
|
#else
|
|
|
|
std::printf("\033[21;32m[SQMOD]\033[0m");
|
|
|
|
std::vprintf(msg, args);
|
|
|
|
std::puts("");
|
|
|
|
#endif // SQMOD_OS_WINDOWS
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Raw console error output.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
static inline void OutputErrorImpl(const char * msg, va_list args)
|
2016-06-03 20:26:19 +02:00
|
|
|
{
|
|
|
|
#ifdef SQMOD_OS_WINDOWS
|
|
|
|
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csb_before;
|
|
|
|
GetConsoleScreenBufferInfo( hstdout, &csb_before);
|
2020-03-22 08:16:40 +01:00
|
|
|
SetConsoleTextAttribute(hstdout, FOREGROUND_RED | FOREGROUND_INTENSITY); // NOLINT(hicpp-signed-bitwise)
|
2016-06-03 20:26:19 +02:00
|
|
|
std::printf("[SQMOD] ");
|
|
|
|
|
2020-03-22 08:16:40 +01:00
|
|
|
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY); // NOLINT(hicpp-signed-bitwise)
|
2016-06-03 20:26:19 +02:00
|
|
|
std::vprintf(msg, args);
|
|
|
|
std::puts("");
|
|
|
|
|
|
|
|
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
|
|
|
|
#else
|
|
|
|
std::printf("\033[21;91m[SQMOD]\033[0m");
|
|
|
|
std::vprintf(msg, args);
|
|
|
|
std::puts("");
|
|
|
|
#endif // SQMOD_OS_WINDOWS
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
void OutputDebug(const char * msg, ...)
|
2016-06-03 20:26:19 +02:00
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
|
|
|
// Initialize the arguments list
|
|
|
|
va_list args;
|
|
|
|
va_start(args, msg);
|
|
|
|
// Call the output function
|
|
|
|
OutputMessageImpl(msg, args);
|
|
|
|
// Finalize the arguments list
|
|
|
|
va_end(args);
|
|
|
|
#else
|
|
|
|
SQMOD_UNUSED_VAR(msg);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
void OutputMessage(const char * msg, ...)
|
2016-06-03 20:26:19 +02:00
|
|
|
{
|
|
|
|
// Initialize the arguments list
|
|
|
|
va_list args;
|
|
|
|
va_start(args, msg);
|
|
|
|
// Call the output function
|
|
|
|
OutputMessageImpl(msg, args);
|
|
|
|
// Finalize the arguments list
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
void OutputError(const char * msg, ...)
|
2016-06-03 20:26:19 +02:00
|
|
|
{
|
|
|
|
// Initialize the arguments list
|
|
|
|
va_list args;
|
|
|
|
va_start(args, msg);
|
|
|
|
// Call the output function
|
|
|
|
OutputErrorImpl(msg, args);
|
|
|
|
// Finalize the arguments list
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
void SqThrowLastF(const SQChar * msg, ...)
|
2016-06-03 20:26:19 +02:00
|
|
|
{
|
|
|
|
// Acquire a moderately sized buffer
|
|
|
|
Buffer b(128);
|
|
|
|
// Prepare the arguments list
|
|
|
|
va_list args;
|
2021-01-30 07:51:39 +01:00
|
|
|
va_start (args, msg);
|
2016-06-03 20:26:19 +02:00
|
|
|
// Attempt to run the specified format
|
2021-01-30 07:51:39 +01:00
|
|
|
if (b.WriteF(0, msg, args) == 0)
|
2016-06-03 20:26:19 +02:00
|
|
|
{
|
|
|
|
b.At(0) = '\0'; // Make sure the string is null terminated
|
|
|
|
}
|
|
|
|
// Finalize the argument list
|
|
|
|
va_end(args);
|
2021-01-30 07:51:39 +01:00
|
|
|
#ifdef SQMOD_OS_WINDOWS
|
|
|
|
// Get the error message, if any.
|
|
|
|
const DWORD error_num = ::GetLastError();
|
|
|
|
// Was there an error recorded?
|
|
|
|
if(error_num == 0)
|
2016-06-03 20:26:19 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
// Invoker is responsible for making sure this doesn't happen!
|
2021-02-03 16:50:39 +01:00
|
|
|
SqThrowF("{} [Unknown error]", b.Data());
|
2016-06-03 20:26:19 +02:00
|
|
|
}
|
2021-01-30 07:51:39 +01:00
|
|
|
// The resulted message buffer
|
|
|
|
LPSTR msg_buff = nullptr;
|
|
|
|
// Attempt to obtain the error message
|
|
|
|
const std::size_t size = FormatMessageA(
|
|
|
|
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, // NOLINT(hicpp-signed-bitwise)
|
|
|
|
nullptr, error_num, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // NOLINT(hicpp-signed-bitwise)
|
|
|
|
reinterpret_cast< LPSTR >(&msg_buff), 0, nullptr);
|
|
|
|
// Copy the message buffer before freeing it
|
|
|
|
std::string message(msg_buff, size);
|
|
|
|
//Free the message buffer
|
|
|
|
LocalFree(msg_buff);
|
|
|
|
// Now it's safe to throw the error
|
2021-02-03 16:50:39 +01:00
|
|
|
SqThrowF("{} [{}]", b.Data(), message);
|
2021-01-30 07:51:39 +01:00
|
|
|
#else
|
2021-02-03 16:50:39 +01:00
|
|
|
SqThrowF("{} [{}]", b.Data(), std::strerror(errno));
|
2021-01-30 07:51:39 +01:00
|
|
|
#endif // SQMOD_OS_WINDOWS
|
2018-10-23 21:28:34 +02:00
|
|
|
}
|
|
|
|
|
2016-06-03 20:26:19 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Object & NullObject()
|
|
|
|
{
|
|
|
|
static Object o;
|
|
|
|
o.Release();
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2017-02-21 20:24:59 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
LightObj & NullLightObj()
|
|
|
|
{
|
|
|
|
static LightObj o;
|
|
|
|
o.Release();
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2016-06-03 20:26:19 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Table & NullTable()
|
|
|
|
{
|
|
|
|
static Table t;
|
|
|
|
t.Release();
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Array & NullArray()
|
|
|
|
{
|
|
|
|
static Array a;
|
|
|
|
a.Release();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Function & NullFunction()
|
|
|
|
{
|
|
|
|
static Function f;
|
|
|
|
f.Release();
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2016-06-08 15:26:55 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
String & NullString()
|
|
|
|
{
|
|
|
|
static String s;
|
|
|
|
s.resize(0);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2020-05-10 11:56:23 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
const SQChar * SqTypeName(SQObjectType type)
|
2016-06-09 01:05:36 +02:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case OT_NULL: return _SC("null");
|
|
|
|
case OT_INTEGER: return _SC("integer");
|
|
|
|
case OT_FLOAT: return _SC("float");
|
|
|
|
case OT_BOOL: return _SC("bool");
|
|
|
|
case OT_STRING: return _SC("string");
|
|
|
|
case OT_TABLE: return _SC("table");
|
|
|
|
case OT_ARRAY: return _SC("array");
|
|
|
|
case OT_USERDATA: return _SC("userdata");
|
|
|
|
case OT_CLOSURE: return _SC("closure");
|
|
|
|
case OT_NATIVECLOSURE: return _SC("nativeclosure");
|
|
|
|
case OT_GENERATOR: return _SC("generator");
|
|
|
|
case OT_USERPOINTER: return _SC("userpointer");
|
|
|
|
case OT_THREAD: return _SC("thread");
|
|
|
|
case OT_FUNCPROTO: return _SC("funcproto");
|
|
|
|
case OT_CLASS: return _SC("class");
|
|
|
|
case OT_INSTANCE: return _SC("instance");
|
|
|
|
case OT_WEAKREF: return _SC("weakref");
|
|
|
|
case OT_OUTER: return _SC("outer");
|
|
|
|
default: return _SC("unknown");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
String SqTypeName(HSQUIRRELVM vm, SQInteger idx)
|
|
|
|
{
|
|
|
|
// Remember the current stack size
|
|
|
|
const StackGuard sg(vm);
|
|
|
|
// Attempt to retrieve the type name of the specified value
|
|
|
|
if (SQ_FAILED(sq_typeof(vm, idx)))
|
|
|
|
{
|
|
|
|
return _SC("unknown");
|
|
|
|
}
|
|
|
|
// Attempt to convert the obtained value to a string
|
2018-07-29 23:58:27 +02:00
|
|
|
StackStrF val(vm, -1);
|
2016-06-09 01:05:36 +02:00
|
|
|
// Did the conversion failed?
|
2018-07-29 23:58:27 +02:00
|
|
|
if (SQ_FAILED(val.Proc(false)))
|
2016-06-09 01:05:36 +02:00
|
|
|
{
|
|
|
|
return _SC("unknown");
|
|
|
|
}
|
|
|
|
// Return the obtained string value
|
2020-03-22 08:16:40 +01:00
|
|
|
return String(val.mPtr, static_cast< size_t >(val.mLen));
|
2016-06-09 01:05:36 +02:00
|
|
|
}
|
|
|
|
|
2016-06-03 20:26:19 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
LightObj BufferToStrObj(const Buffer & b)
|
2016-06-03 20:26:19 +02:00
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2020-04-27 12:10:54 +02:00
|
|
|
const StackGuard sg(SqVM());
|
2016-06-03 20:26:19 +02:00
|
|
|
// Push the string onto the stack
|
2020-04-27 12:10:54 +02:00
|
|
|
sq_pushstring(SqVM(), b.Data(), b.Position());
|
2016-06-03 20:26:19 +02:00
|
|
|
// Obtain the object from the stack and return it
|
2021-01-30 07:51:39 +01:00
|
|
|
return Var< LightObj >(SqVM(), -1).value;
|
2016-06-03 20:26:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
LightObj BufferToStrObj(const Buffer & b, uint32_t size)
|
2016-06-03 20:26:19 +02:00
|
|
|
{
|
|
|
|
// Perform a range check on the specified buffer
|
|
|
|
if (size > b.Capacity())
|
|
|
|
{
|
2021-02-03 16:50:39 +01:00
|
|
|
STHROWF("The specified buffer size is out of range: {} >= {}", size, b.Capacity());
|
2016-06-03 20:26:19 +02:00
|
|
|
}
|
|
|
|
// Obtain the initial stack size
|
2020-04-27 12:10:54 +02:00
|
|
|
const StackGuard sg(SqVM());
|
2016-06-03 20:26:19 +02:00
|
|
|
// Push the string onto the stack
|
2020-04-27 12:10:54 +02:00
|
|
|
sq_pushstring(SqVM(), b.Data(), size);
|
2016-06-03 20:26:19 +02:00
|
|
|
// Obtain the object from the stack and return it
|
2021-01-30 07:51:39 +01:00
|
|
|
return Var< LightObj >(SqVM(), -1).value;
|
2016-06-03 20:26:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
SQInteger PopStackInteger(HSQUIRRELVM vm, SQInteger idx)
|
|
|
|
{
|
|
|
|
// Identify which type must be extracted
|
|
|
|
switch (sq_gettype(vm, idx))
|
|
|
|
{
|
|
|
|
case OT_INTEGER:
|
|
|
|
{
|
|
|
|
SQInteger val;
|
|
|
|
sq_getinteger(vm, idx, &val);
|
|
|
|
return val;
|
2020-03-22 08:16:40 +01:00
|
|
|
}
|
2016-06-03 20:26:19 +02:00
|
|
|
case OT_FLOAT:
|
|
|
|
{
|
|
|
|
SQFloat val;
|
|
|
|
sq_getfloat(vm, idx, &val);
|
|
|
|
return ConvTo< SQInteger >::From(val);
|
2020-03-22 08:16:40 +01:00
|
|
|
}
|
2016-06-03 20:26:19 +02:00
|
|
|
case OT_BOOL:
|
|
|
|
{
|
|
|
|
SQBool val;
|
|
|
|
sq_getbool(vm, idx, &val);
|
|
|
|
return static_cast< SQInteger >(val);
|
2020-03-22 08:16:40 +01:00
|
|
|
}
|
2016-06-03 20:26:19 +02:00
|
|
|
case OT_STRING:
|
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
const SQChar * val = nullptr;
|
2016-06-03 20:26:19 +02:00
|
|
|
// Attempt to retrieve and convert the string
|
|
|
|
if (SQ_SUCCEEDED(sq_getstring(vm, idx, &val)) && val != nullptr && *val != '\0')
|
|
|
|
{
|
|
|
|
return ConvTo< SQInteger >::From(std::strtoll(val, nullptr, 10));
|
2020-03-22 08:16:40 +01:00
|
|
|
} else break;
|
|
|
|
}
|
2016-06-03 20:26:19 +02:00
|
|
|
case OT_ARRAY:
|
|
|
|
case OT_TABLE:
|
|
|
|
case OT_CLASS:
|
|
|
|
case OT_USERDATA:
|
|
|
|
{
|
|
|
|
return sq_getsize(vm, idx);
|
2020-03-22 08:16:40 +01:00
|
|
|
}
|
2016-06-03 20:26:19 +02:00
|
|
|
case OT_INSTANCE:
|
|
|
|
{
|
|
|
|
// Attempt to treat the value as a signed long instance
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return ConvTo< SQInteger >::From(Var< const SLongInt & >(vm, idx).value.GetNum());
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
// Just ignore it...
|
|
|
|
}
|
|
|
|
// Attempt to treat the value as a unsigned long instance
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return ConvTo< SQInteger >::From(Var< const ULongInt & >(vm, idx).value.GetNum());
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
// Just ignore it...
|
|
|
|
}
|
2016-07-09 20:33:27 +02:00
|
|
|
// Attempt to get the size of the instance as a fall back
|
2016-06-03 20:26:19 +02:00
|
|
|
return sq_getsize(vm, idx);
|
2020-03-22 08:16:40 +01:00
|
|
|
}
|
2016-06-03 20:26:19 +02:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
// Default to 0
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
SQFloat PopStackFloat(HSQUIRRELVM vm, SQInteger idx)
|
|
|
|
{
|
|
|
|
// Identify which type must be extracted
|
|
|
|
switch (sq_gettype(vm, idx))
|
|
|
|
{
|
|
|
|
case OT_FLOAT:
|
|
|
|
{
|
|
|
|
SQFloat val;
|
|
|
|
sq_getfloat(vm, idx, &val);
|
|
|
|
return val;
|
2020-03-22 08:16:40 +01:00
|
|
|
}
|
2016-06-03 20:26:19 +02:00
|
|
|
case OT_INTEGER:
|
|
|
|
{
|
|
|
|
SQInteger val;
|
|
|
|
sq_getinteger(vm, idx, &val);
|
|
|
|
return ConvTo< SQFloat >::From(val);
|
2020-03-22 08:16:40 +01:00
|
|
|
}
|
2016-06-03 20:26:19 +02:00
|
|
|
case OT_BOOL:
|
|
|
|
{
|
|
|
|
SQBool val;
|
|
|
|
sq_getbool(vm, idx, &val);
|
|
|
|
return ConvTo< SQFloat >::From(val);
|
2020-03-22 08:16:40 +01:00
|
|
|
}
|
2016-06-03 20:26:19 +02:00
|
|
|
case OT_STRING:
|
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
const SQChar * val = nullptr;
|
2016-06-03 20:26:19 +02:00
|
|
|
// Attempt to retrieve and convert the string
|
|
|
|
if (SQ_SUCCEEDED(sq_getstring(vm, idx, &val)) && val != nullptr && *val != '\0')
|
|
|
|
{
|
|
|
|
#ifdef SQUSEDOUBLE
|
|
|
|
return std::strtod(val, nullptr);
|
|
|
|
#else
|
|
|
|
return std::strtof(val, nullptr);
|
|
|
|
#endif // SQUSEDOUBLE
|
2020-03-22 08:16:40 +01:00
|
|
|
} else break;
|
|
|
|
}
|
2016-06-03 20:26:19 +02:00
|
|
|
case OT_ARRAY:
|
|
|
|
case OT_TABLE:
|
|
|
|
case OT_CLASS:
|
|
|
|
case OT_USERDATA:
|
|
|
|
{
|
|
|
|
return ConvTo< SQFloat >::From(sq_getsize(vm, idx));
|
2020-03-22 08:16:40 +01:00
|
|
|
}
|
2016-06-03 20:26:19 +02:00
|
|
|
case OT_INSTANCE:
|
|
|
|
{
|
|
|
|
// Attempt to treat the value as a signed long instance
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return ConvTo< SQFloat >::From(Var< const SLongInt & >(vm, idx).value.GetNum());
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
// Just ignore it...
|
|
|
|
}
|
|
|
|
// Attempt to treat the value as a unsigned long instance
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return ConvTo< SQFloat >::From(Var< const ULongInt & >(vm, idx).value.GetNum());
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
// Just ignore it...
|
|
|
|
}
|
2016-07-09 20:33:27 +02:00
|
|
|
// Attempt to get the size of the instance as a fall back
|
2016-06-03 20:26:19 +02:00
|
|
|
return ConvTo< SQFloat >::From(sq_getsize(vm, idx));
|
2020-03-22 08:16:40 +01:00
|
|
|
}
|
2016-06-03 20:26:19 +02:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
// Default to 0
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2021-01-30 07:51:39 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool SToB(const SQChar * str)
|
|
|
|
{
|
|
|
|
// Temporary buffer to store the lowercase string
|
|
|
|
SQChar buffer[8];
|
|
|
|
// The currently processed character
|
|
|
|
unsigned i = 0;
|
|
|
|
// Convert only the necessary characters to lowercase
|
|
|
|
while (i < 7 && *str != '\0')
|
|
|
|
{
|
|
|
|
buffer[i++] = static_cast< SQChar >(std::tolower(*(str++)));
|
|
|
|
}
|
|
|
|
// Add the null terminator
|
|
|
|
buffer[i] = '\0';
|
|
|
|
// Compare the lowercase string and return the result
|
|
|
|
return std::strcmp(buffer, "true") == 0 || std::strcmp(buffer, "yes") == 0 ||
|
|
|
|
std::strcmp(buffer, "on") == 0 || std::strcmp(buffer, "1") == 0;
|
|
|
|
}
|
|
|
|
|
2016-06-03 20:26:19 +02:00
|
|
|
} // Namespace:: SqMod
|