mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 08:47:17 +01:00
Update the module API and merge shared code between modules and host plugin.
This commit is contained in:
parent
423bdfcdab
commit
0c92601362
@ -431,10 +431,12 @@
|
||||
<Unit filename="../external/Hash/sha256.h" />
|
||||
<Unit filename="../external/Hash/sha3.cpp" />
|
||||
<Unit filename="../external/Hash/sha3.h" />
|
||||
<Unit filename="../shared/Base/Buffer.cpp" />
|
||||
<Unit filename="../shared/Base/Buffer.hpp" />
|
||||
<Unit filename="../shared/Base/Utility.cpp" />
|
||||
<Unit filename="../shared/Base/Utility.hpp" />
|
||||
<Unit filename="../source/Base/AABB.cpp" />
|
||||
<Unit filename="../source/Base/AABB.hpp" />
|
||||
<Unit filename="../source/Base/Buffer.cpp" />
|
||||
<Unit filename="../source/Base/Buffer.hpp" />
|
||||
<Unit filename="../source/Base/Circle.cpp" />
|
||||
<Unit filename="../source/Base/Circle.hpp" />
|
||||
<Unit filename="../source/Base/Color3.cpp" />
|
||||
@ -447,8 +449,6 @@
|
||||
<Unit filename="../source/Base/Shared.hpp" />
|
||||
<Unit filename="../source/Base/Sphere.cpp" />
|
||||
<Unit filename="../source/Base/Sphere.hpp" />
|
||||
<Unit filename="../source/Base/Stack.cpp" />
|
||||
<Unit filename="../source/Base/Stack.hpp" />
|
||||
<Unit filename="../source/Base/Vector2.cpp" />
|
||||
<Unit filename="../source/Base/Vector2.hpp" />
|
||||
<Unit filename="../source/Base/Vector2i.cpp" />
|
||||
|
@ -29,8 +29,8 @@ private:
|
||||
typedef unsigned int Counter;
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Memory* m_Ptr; /* The memory manager instance. */
|
||||
Counter* m_Ref; /* Reference count to the managed instance. */
|
||||
Memory* m_Ptr; // The memory manager instance.
|
||||
Counter* m_Ref; // Reference count to the managed instance.
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Grab a strong reference to a memory manager.
|
981
shared/Base/Utility.cpp
Normal file
981
shared/Base/Utility.cpp
Normal file
@ -0,0 +1,981 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Base/Utility.hpp"
|
||||
#include "Base/Buffer.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <ctime>
|
||||
#include <cfloat>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cstdarg>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#ifdef SQMOD_OS_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif // SQMOD_OS_WINDOWS
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#ifndef SQMOD_PLUGIN_API
|
||||
#include "Library/Numeric.hpp"
|
||||
#include <sqstdstring.h>
|
||||
#endif // SQMOD_PLUGIN_API
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
PluginFuncs* _Func = nullptr;
|
||||
PluginCallbacks* _Clbk = nullptr;
|
||||
PluginInfo* _Info = nullptr;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#ifdef SQMOD_PLUGIN_API
|
||||
|
||||
HSQAPI _SqAPI = nullptr;
|
||||
HSQEXPORTS _SqMod = nullptr;
|
||||
HSQUIRRELVM _SqVM = nullptr;
|
||||
|
||||
#endif // SQMOD_PLUGIN_API
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Common buffers to reduce memory allocations. To be immediately copied upon return!
|
||||
*/
|
||||
static SQChar g_Buffer[4096];
|
||||
static SQChar g_NumBuf[1024];
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SStr GetTempBuff()
|
||||
{
|
||||
return g_Buffer;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 GetTempBuffSize()
|
||||
{
|
||||
return sizeof(g_Buffer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Raw console message output.
|
||||
*/
|
||||
static inline void OutputMessageImpl(CCStr msg, va_list args)
|
||||
{
|
||||
#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] ");
|
||||
|
||||
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
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.
|
||||
*/
|
||||
static inline void OutputErrorImpl(CCStr msg, va_list args)
|
||||
{
|
||||
#ifdef SQMOD_OS_WINDOWS
|
||||
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
CONSOLE_SCREEN_BUFFER_INFO csb_before;
|
||||
GetConsoleScreenBufferInfo( hstdout, &csb_before);
|
||||
SetConsoleTextAttribute(hstdout, FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
std::printf("[SQMOD] ");
|
||||
|
||||
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
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
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void OutputDebug(CCStr msg, ...)
|
||||
{
|
||||
#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
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void OutputMessage(CCStr msg, ...)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void OutputError(CCStr msg, ...)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SqThrowF(CSStr str, ...)
|
||||
{
|
||||
// Initialize the argument list
|
||||
va_list args;
|
||||
va_start (args, str);
|
||||
// Write the requested contents
|
||||
if (std::vsnprintf(g_Buffer, sizeof(g_Buffer), str, args) < 0)
|
||||
{
|
||||
// Write a generic message at least
|
||||
std::strcpy(g_Buffer, "Unknown error has occurred");
|
||||
}
|
||||
// Finalize the argument list
|
||||
va_end(args);
|
||||
// Throw the exception with the resulted message
|
||||
throw Sqrat::Exception(g_Buffer);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr FmtStr(CSStr str, ...)
|
||||
{
|
||||
// Initialize the argument list
|
||||
va_list args;
|
||||
va_start (args, str);
|
||||
// Write the requested contents
|
||||
if (std::vsnprintf(g_Buffer, sizeof(g_Buffer), str, args) < 0)
|
||||
{
|
||||
STHROWF("Failed to run the specified string format");
|
||||
}
|
||||
// Finalize the argument list
|
||||
va_end(args);
|
||||
// Return the data from the buffer
|
||||
return g_Buffer;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ToStrF(CSStr str, ...)
|
||||
{
|
||||
// Prepare the arguments list
|
||||
va_list args;
|
||||
va_start(args, str);
|
||||
// Write the requested contents
|
||||
if (std::vsnprintf(g_Buffer, sizeof(g_Buffer), str, args) < 0)
|
||||
{
|
||||
g_Buffer[0] = '\0'; // Make sure the string is null terminated
|
||||
}
|
||||
// Finalize the argument list
|
||||
va_end(args);
|
||||
// Return the resulted string
|
||||
return g_Buffer;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ToStringF(CSStr str, ...)
|
||||
{
|
||||
// Acquire a moderately sized buffer
|
||||
Buffer b(128);
|
||||
// Prepare the arguments list
|
||||
va_list args;
|
||||
va_start (args, str);
|
||||
// Attempt to run the specified format
|
||||
if (b.WriteF(0, str, args) == 0)
|
||||
{
|
||||
b.At(0) = '\0'; // Make sure the string is null terminated
|
||||
}
|
||||
// Finalize the argument list
|
||||
va_end(args);
|
||||
// Return the resulted string
|
||||
return b.Get< SQChar >();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool SToB(CSStr 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) ? true : false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object & NullObject()
|
||||
{
|
||||
static Object o;
|
||||
o.Release();
|
||||
return o;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
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;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Int8 >::ToStr(Int8 v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%d", v) < 0)
|
||||
{
|
||||
g_NumBuf[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuf;
|
||||
}
|
||||
|
||||
Int8 ConvNum< Int8 >::FromStr(CSStr s)
|
||||
{
|
||||
return ConvTo< Int8 >::From(std::strtol(s, nullptr, 10));
|
||||
}
|
||||
|
||||
Int8 ConvNum< Int8 >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return ConvTo< Int8 >::From(std::strtol(s, nullptr, base));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Uint8 >::ToStr(Uint8 v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%u", v) < 0)
|
||||
{
|
||||
g_NumBuf[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuf;
|
||||
}
|
||||
|
||||
Uint8 ConvNum< Uint8 >::FromStr(CSStr s)
|
||||
{
|
||||
return ConvTo< Uint8 >::From(std::strtoul(s, nullptr, 10));
|
||||
}
|
||||
|
||||
Uint8 ConvNum< Uint8 >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return ConvTo< Uint8 >::From(std::strtoul(s, nullptr, base));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Int16 >::ToStr(Int16 v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%d", v) < 0)
|
||||
{
|
||||
g_NumBuf[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuf;
|
||||
}
|
||||
|
||||
Int16 ConvNum< Int16 >::FromStr(CSStr s)
|
||||
{
|
||||
return ConvTo< Int16 >::From(std::strtol(s, nullptr, 10));
|
||||
}
|
||||
|
||||
Int16 ConvNum< Int16 >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return ConvTo< Int16 >::From(std::strtol(s, nullptr, base));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Uint16 >::ToStr(Uint16 v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%u", v) < 0)
|
||||
{
|
||||
g_NumBuf[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuf;
|
||||
}
|
||||
|
||||
Uint16 ConvNum< Uint16 >::FromStr(CSStr s)
|
||||
{
|
||||
return ConvTo< Uint16 >::From(std::strtoul(s, nullptr, 10));
|
||||
}
|
||||
|
||||
Uint16 ConvNum< Uint16 >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return ConvTo< Uint16 >::From(std::strtoul(s, nullptr, base));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Int32 >::ToStr(Int32 v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%d", v) < 0)
|
||||
{
|
||||
g_NumBuf[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuf;
|
||||
}
|
||||
|
||||
Int32 ConvNum< Int32 >::FromStr(CSStr s)
|
||||
{
|
||||
return ConvTo< Int32 >::From(std::strtol(s, nullptr, 10));
|
||||
}
|
||||
|
||||
Int32 ConvNum< Int32 >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return ConvTo< Int32 >::From(std::strtol(s, nullptr, base));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Uint32 >::ToStr(Uint32 v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%u", v) < 0)
|
||||
{
|
||||
g_NumBuf[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuf;
|
||||
}
|
||||
|
||||
Uint32 ConvNum< Uint32 >::FromStr(CSStr s)
|
||||
{
|
||||
return ConvTo< Uint32 >::From(std::strtoul(s, nullptr, 10));
|
||||
}
|
||||
|
||||
Uint32 ConvNum< Uint32 >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return ConvTo< Uint32 >::From(std::strtoul(s, nullptr, base));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Int64 >::ToStr(Int64 v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%lld", v) < 0)
|
||||
{
|
||||
g_NumBuf[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuf;
|
||||
}
|
||||
|
||||
Int64 ConvNum< Int64 >::FromStr(CSStr s)
|
||||
{
|
||||
return std::strtoll(s, nullptr, 10);
|
||||
}
|
||||
|
||||
Int64 ConvNum< Int64 >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return std::strtoll(s, nullptr, base);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Uint64 >::ToStr(Uint64 v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%llu", v) < 0)
|
||||
{
|
||||
g_NumBuf[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuf;
|
||||
}
|
||||
|
||||
Uint64 ConvNum< Uint64 >::FromStr(CSStr s)
|
||||
{
|
||||
return std::strtoull(s, nullptr, 10);
|
||||
}
|
||||
|
||||
Uint64 ConvNum< Uint64 >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return std::strtoull(s, nullptr, base);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< LongI >::ToStr(LongI v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%ld", v) < 0)
|
||||
{
|
||||
g_NumBuf[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuf;
|
||||
}
|
||||
|
||||
LongI ConvNum< LongI >::FromStr(CSStr s)
|
||||
{
|
||||
return std::strtol(s, nullptr, 10);
|
||||
}
|
||||
|
||||
LongI ConvNum< LongI >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return std::strtol(s, nullptr, base);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Ulong >::ToStr(Ulong v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%lu", v) < 0)
|
||||
{
|
||||
g_NumBuf[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuf;
|
||||
}
|
||||
|
||||
Ulong ConvNum< Ulong >::FromStr(CSStr s)
|
||||
{
|
||||
return std::strtoul(s, nullptr, 10);
|
||||
}
|
||||
|
||||
Ulong ConvNum< Ulong >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return std::strtoul(s, nullptr, base);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Float32 >::ToStr(Float32 v)
|
||||
{
|
||||
// Attempt to convert the value to a string
|
||||
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%f", v) < 0)
|
||||
{
|
||||
g_NumBuf[0] = '\0';
|
||||
}
|
||||
// Return the data from the buffer
|
||||
return g_NumBuf;
|
||||
}
|
||||
|
||||
Float32 ConvNum< Float32 >::FromStr(CSStr s)
|
||||
{
|
||||
return std::strtof(s, nullptr);
|
||||
}
|
||||
|
||||
Float32 ConvNum< Float32 >::FromStr(CSStr s, Int32 /*base*/)
|
||||
{
|
||||
return std::strtof(s, nullptr);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Float64 >::ToStr(Float64 v)
|
||||
{
|
||||
// Attempt to convert the value to a string
|
||||
if (std::snprintf(g_NumBuf, sizeof(g_NumBuf), "%f", v) < 0)
|
||||
{
|
||||
g_NumBuf[0] = '\0';
|
||||
}
|
||||
// Return the data from the buffer
|
||||
return g_NumBuf;
|
||||
}
|
||||
|
||||
Float64 ConvNum< Float64 >::FromStr(CSStr s)
|
||||
{
|
||||
return std::strtod(s, nullptr);
|
||||
}
|
||||
|
||||
Float64 ConvNum< Float64 >::FromStr(CSStr s, Int32 /*base*/)
|
||||
{
|
||||
return std::strtod(s, nullptr);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< bool >::ToStr(bool v)
|
||||
{
|
||||
if (v)
|
||||
{
|
||||
g_NumBuf[0] = 't';
|
||||
g_NumBuf[1] = 'r';
|
||||
g_NumBuf[2] = 'u';
|
||||
g_NumBuf[3] = 'e';
|
||||
g_NumBuf[4] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
g_NumBuf[0] = 'f';
|
||||
g_NumBuf[1] = 'a';
|
||||
g_NumBuf[2] = 'l';
|
||||
g_NumBuf[3] = 's';
|
||||
g_NumBuf[4] = 'e';
|
||||
g_NumBuf[5] = '\0';
|
||||
}
|
||||
return g_NumBuf;
|
||||
}
|
||||
|
||||
bool ConvNum< bool >::FromStr(CSStr s)
|
||||
{
|
||||
return (std::strcmp(s, "true") == 0) ? true : false;
|
||||
}
|
||||
|
||||
bool ConvNum< bool >::FromStr(CSStr s, Int32 /*base*/)
|
||||
{
|
||||
return (std::strcmp(s, "true") == 0) ? true : false;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
StackStrF::StackStrF(HSQUIRRELVM vm, SQInteger idx, bool fmt)
|
||||
: mPtr(nullptr)
|
||||
, mLen(-1)
|
||||
, mRes(SQ_OK)
|
||||
, mObj()
|
||||
, mVM(vm)
|
||||
{
|
||||
const Int32 top = sq_gettop(vm);
|
||||
// Reset the converted value object
|
||||
sq_resetobject(&mObj);
|
||||
// Was the string or value specified?
|
||||
if (top <= (idx - 1))
|
||||
{
|
||||
mRes = sq_throwerror(vm, "Missing string or value");
|
||||
}
|
||||
// Do we have enough values to call the format function and are we allowed to?
|
||||
else if (top > idx && fmt)
|
||||
{
|
||||
// Pointer to the generated string
|
||||
SStr str = nullptr;
|
||||
// Attempt to generate the specified string format
|
||||
mRes = sqstd_format(vm, idx, &mLen, &str);
|
||||
// Did the format succeeded but ended up with a null string pointer?
|
||||
if (SQ_SUCCEEDED(mRes) && !str)
|
||||
{
|
||||
mRes = sq_throwerror(vm, "Unable to generate the string");
|
||||
}
|
||||
else
|
||||
{
|
||||
mPtr = const_cast< CSStr >(str);
|
||||
}
|
||||
}
|
||||
// Is the value on the stack an actual string?
|
||||
else if (sq_gettype(vm, idx) == OT_STRING)
|
||||
{
|
||||
// Obtain a reference to the string object
|
||||
mRes = sq_getstackobj(vm, idx, &mObj);
|
||||
// Could we retrieve the object from the stack?
|
||||
if (SQ_SUCCEEDED(mRes))
|
||||
{
|
||||
// Keep a strong reference to the object
|
||||
sq_addref(vm, &mObj);
|
||||
// Attempt to retrieve the string value from the stack
|
||||
mRes = sq_getstring(vm, idx, &mPtr);
|
||||
}
|
||||
// Did the retrieval succeeded but ended up with a null string pointer?
|
||||
if (SQ_SUCCEEDED(mRes) && !mPtr)
|
||||
{
|
||||
mRes = sq_throwerror(vm, "Unable to retrieve the string");
|
||||
}
|
||||
}
|
||||
// We have to try and convert it to string
|
||||
else
|
||||
{
|
||||
// Attempt to convert the value from the stack to a string
|
||||
mRes = sq_tostring(vm, idx);
|
||||
// Could we convert the specified value to string?
|
||||
if (SQ_SUCCEEDED(mRes))
|
||||
{
|
||||
// Obtain a reference to the resulted object
|
||||
mRes = sq_getstackobj(vm, -1, &mObj);
|
||||
// Could we retrieve the object from the stack?
|
||||
if (SQ_SUCCEEDED(mRes))
|
||||
{
|
||||
// Keep a strong reference to the object
|
||||
sq_addref(vm, &mObj);
|
||||
// Attempt to obtain the string pointer
|
||||
mRes = sq_getstring(vm, -1, &mPtr);
|
||||
}
|
||||
}
|
||||
// Pop a value from the stack regardless of the result
|
||||
sq_pop(vm, 1);
|
||||
// Did the retrieval succeeded but ended up with a null string pointer?
|
||||
if (SQ_SUCCEEDED(mRes) && !mPtr)
|
||||
{
|
||||
mRes = sq_throwerror(vm, "Unable to retrieve the value");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
StackStrF::~StackStrF()
|
||||
{
|
||||
if (mVM && !sq_isnull(mObj))
|
||||
{
|
||||
sq_release(mVM, &mObj);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object BufferToStrObj(const Buffer & b)
|
||||
{
|
||||
// Obtain the initial stack size
|
||||
const StackGuard sg(DefaultVM::Get());
|
||||
// Push the string onto the stack
|
||||
sq_pushstring(DefaultVM::Get(), b.Data(), b.Position());
|
||||
// Obtain the object from the stack and return it
|
||||
return Var< Object >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Object BufferToStrObj(const Buffer & b, Uint32 size)
|
||||
{
|
||||
// Perform a range check on the specified buffer
|
||||
if (size > b.Capacity())
|
||||
{
|
||||
STHROWF("The specified buffer size is out of range: %u >= %u", size, b.Capacity());
|
||||
}
|
||||
// Obtain the initial stack size
|
||||
const StackGuard sg(DefaultVM::Get());
|
||||
// Push the string onto the stack
|
||||
sq_pushstring(DefaultVM::Get(), b.Data(), size);
|
||||
// Obtain the object from the stack and return it
|
||||
return Var< Object >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger PopStackInteger(HSQUIRRELVM vm, SQInteger idx)
|
||||
{
|
||||
#ifdef SQMOD_PLUGIN_API
|
||||
return _SqMod->PopStackInteger(vm, idx);
|
||||
#else
|
||||
// Identify which type must be extracted
|
||||
switch (sq_gettype(vm, idx))
|
||||
{
|
||||
case OT_INTEGER:
|
||||
{
|
||||
SQInteger val;
|
||||
sq_getinteger(vm, idx, &val);
|
||||
return val;
|
||||
} break;
|
||||
case OT_FLOAT:
|
||||
{
|
||||
SQFloat val;
|
||||
sq_getfloat(vm, idx, &val);
|
||||
return ConvTo< SQInteger >::From(val);
|
||||
} break;
|
||||
case OT_BOOL:
|
||||
{
|
||||
SQBool val;
|
||||
sq_getbool(vm, idx, &val);
|
||||
return static_cast< SQInteger >(val);
|
||||
} break;
|
||||
case OT_STRING:
|
||||
{
|
||||
CSStr val = nullptr;
|
||||
// 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));
|
||||
}
|
||||
} break;
|
||||
case OT_ARRAY:
|
||||
case OT_TABLE:
|
||||
case OT_CLASS:
|
||||
case OT_USERDATA:
|
||||
{
|
||||
return sq_getsize(vm, idx);
|
||||
} break;
|
||||
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...
|
||||
}
|
||||
// Attempt to get the size of the instance as a fallback
|
||||
return sq_getsize(vm, idx);
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
// Default to 0
|
||||
return 0;
|
||||
#endif // SQMOD_PLUGIN_API
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQFloat PopStackFloat(HSQUIRRELVM vm, SQInteger idx)
|
||||
{
|
||||
#ifdef SQMOD_PLUGIN_API
|
||||
return _SqMod->PopStackFloat(vm, idx);
|
||||
#else
|
||||
// Identify which type must be extracted
|
||||
switch (sq_gettype(vm, idx))
|
||||
{
|
||||
case OT_FLOAT:
|
||||
{
|
||||
SQFloat val;
|
||||
sq_getfloat(vm, idx, &val);
|
||||
return val;
|
||||
} break;
|
||||
case OT_INTEGER:
|
||||
{
|
||||
SQInteger val;
|
||||
sq_getinteger(vm, idx, &val);
|
||||
return ConvTo< SQFloat >::From(val);
|
||||
} break;
|
||||
case OT_BOOL:
|
||||
{
|
||||
SQBool val;
|
||||
sq_getbool(vm, idx, &val);
|
||||
return ConvTo< SQFloat >::From(val);
|
||||
} break;
|
||||
case OT_STRING:
|
||||
{
|
||||
CSStr val = nullptr;
|
||||
// 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
|
||||
}
|
||||
} break;
|
||||
case OT_ARRAY:
|
||||
case OT_TABLE:
|
||||
case OT_CLASS:
|
||||
case OT_USERDATA:
|
||||
{
|
||||
return ConvTo< SQFloat >::From(sq_getsize(vm, idx));
|
||||
} break;
|
||||
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...
|
||||
}
|
||||
// Attempt to get the size of the instance as a fallback
|
||||
return ConvTo< SQFloat >::From(sq_getsize(vm, idx));
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
// Default to 0
|
||||
return 0.0;
|
||||
#endif // SQMOD_PLUGIN_API
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int64 PopStackSLong(HSQUIRRELVM vm, SQInteger idx)
|
||||
{
|
||||
#ifdef SQMOD_PLUGIN_API
|
||||
return _SqMod->PopStackSLong(vm, idx);
|
||||
#else
|
||||
// Identify which type must be extracted
|
||||
switch (sq_gettype(vm, idx))
|
||||
{
|
||||
case OT_INTEGER:
|
||||
{
|
||||
SQInteger val;
|
||||
sq_getinteger(vm, idx, &val);
|
||||
return static_cast< Int64 >(val);
|
||||
} break;
|
||||
case OT_FLOAT:
|
||||
{
|
||||
SQFloat val;
|
||||
sq_getfloat(vm, idx, &val);
|
||||
return ConvTo< Int64 >::From(val);
|
||||
} break;
|
||||
case OT_BOOL:
|
||||
{
|
||||
SQBool val;
|
||||
sq_getbool(vm, idx, &val);
|
||||
return static_cast< Int64 >(val);
|
||||
} break;
|
||||
case OT_STRING:
|
||||
{
|
||||
CSStr val = nullptr;
|
||||
// Attempt to retrieve and convert the string
|
||||
if (SQ_SUCCEEDED(sq_getstring(vm, idx, &val)) && val != nullptr && *val != '\0')
|
||||
{
|
||||
return std::strtoll(val, nullptr, 10);
|
||||
}
|
||||
} break;
|
||||
case OT_ARRAY:
|
||||
case OT_TABLE:
|
||||
case OT_CLASS:
|
||||
case OT_USERDATA:
|
||||
{
|
||||
return static_cast< Int64 >(sq_getsize(vm, idx));
|
||||
} break;
|
||||
case OT_INSTANCE:
|
||||
{
|
||||
// Attempt to treat the value as a signed long instance
|
||||
try
|
||||
{
|
||||
return Var< const SLongInt & >(vm, idx).value.GetNum();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Just ignore it...
|
||||
}
|
||||
// Attempt to treat the value as a unsigned long instance
|
||||
try
|
||||
{
|
||||
return ConvTo< Int64 >::From(Var< const ULongInt & >(vm, idx).value.GetNum());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Just ignore it...
|
||||
}
|
||||
// Attempt to get the size of the instance as a fallback
|
||||
return static_cast< Int64 >(sq_getsize(vm, idx));
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
// Default to 0
|
||||
return 0;
|
||||
#endif // SQMOD_PLUGIN_API
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint64 PopStackULong(HSQUIRRELVM vm, SQInteger idx)
|
||||
{
|
||||
#ifdef SQMOD_PLUGIN_API
|
||||
return _SqMod->PopStackULong(vm, idx);
|
||||
#else
|
||||
// Identify which type must be extracted
|
||||
switch (sq_gettype(vm, idx))
|
||||
{
|
||||
case OT_INTEGER:
|
||||
{
|
||||
SQInteger val;
|
||||
sq_getinteger(vm, idx, &val);
|
||||
return ConvTo< Uint64 >::From(val);
|
||||
} break;
|
||||
case OT_FLOAT:
|
||||
{
|
||||
SQFloat val;
|
||||
sq_getfloat(vm, idx, &val);
|
||||
return ConvTo< Uint64 >::From(val);
|
||||
} break;
|
||||
case OT_BOOL:
|
||||
{
|
||||
SQBool val;
|
||||
sq_getbool(vm, idx, &val);
|
||||
return ConvTo< Uint64 >::From(val);
|
||||
} break;
|
||||
case OT_STRING:
|
||||
{
|
||||
CSStr val = nullptr;
|
||||
// Attempt to retrieve and convert the string
|
||||
if (SQ_SUCCEEDED(sq_getstring(vm, idx, &val)) && val != nullptr && *val != '\0')
|
||||
{
|
||||
return std::strtoull(val, nullptr, 10);
|
||||
}
|
||||
} break;
|
||||
case OT_ARRAY:
|
||||
case OT_TABLE:
|
||||
case OT_CLASS:
|
||||
case OT_USERDATA:
|
||||
{
|
||||
return ConvTo< Uint64 >::From(sq_getsize(vm, idx));
|
||||
} break;
|
||||
case OT_INSTANCE:
|
||||
{
|
||||
// Attempt to treat the value as a signed long instance
|
||||
try
|
||||
{
|
||||
return ConvTo< Uint64 >::From(Var< const SLongInt & >(vm, idx).value.GetNum());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Just ignore it...
|
||||
}
|
||||
// Attempt to treat the value as a unsigned long instance
|
||||
try
|
||||
{
|
||||
return Var< const ULongInt & >(vm, idx).value.GetNum();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Just ignore it...
|
||||
}
|
||||
// Attempt to get the size of the instance as a fallback
|
||||
return ConvTo< Uint64 >::From(sq_getsize(vm, idx));
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
// Default to 0
|
||||
return 0;
|
||||
#endif // SQMOD_PLUGIN_API
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
1455
shared/Base/Utility.hpp
Normal file
1455
shared/Base/Utility.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -3,7 +3,7 @@
|
||||
//
|
||||
|
||||
//
|
||||
// Copyright (c) 2015 Sandu Liviu Catalin
|
||||
// Copyright (c) 2016 Sandu Liviu Catalin (aka. S.L.C)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
@ -34,7 +34,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*vm*/
|
||||
//vm
|
||||
typedef HSQUIRRELVM (*sqapi_open)(SQInteger initialstacksize);
|
||||
typedef HSQUIRRELVM (*sqapi_newthread)(HSQUIRRELVM friendvm, SQInteger initialstacksize);
|
||||
typedef void (*sqapi_seterrorhandler)(HSQUIRRELVM v);
|
||||
@ -55,14 +55,14 @@ extern "C" {
|
||||
typedef SQInteger (*sqapi_getvmstate)(HSQUIRRELVM v);
|
||||
typedef SQInteger (*sqapi_getversion)();
|
||||
|
||||
/*compiler*/
|
||||
//compiler
|
||||
typedef SQRESULT (*sqapi_compile)(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,const SQChar *sourcename,SQBool raiseerror);
|
||||
typedef SQRESULT (*sqapi_compilebuffer)(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror);
|
||||
typedef void (*sqapi_enabledebuginfo)(HSQUIRRELVM v, SQBool enable);
|
||||
typedef void (*sqapi_notifyallexceptions)(HSQUIRRELVM v, SQBool enable);
|
||||
typedef void (*sqapi_setcompilererrorhandler)(HSQUIRRELVM v,SQCOMPILERERROR f);
|
||||
|
||||
/*stack operations*/
|
||||
//stack operations
|
||||
typedef void (*sqapi_push)(HSQUIRRELVM v,SQInteger idx);
|
||||
typedef void (*sqapi_pop)(HSQUIRRELVM v,SQInteger nelemstopop);
|
||||
typedef void (*sqapi_poptop)(HSQUIRRELVM v);
|
||||
@ -73,7 +73,7 @@ extern "C" {
|
||||
typedef SQInteger (*sqapi_cmp)(HSQUIRRELVM v);
|
||||
typedef void (*sqapi_move)(HSQUIRRELVM dest,HSQUIRRELVM src,SQInteger idx);
|
||||
|
||||
/*object creation handling*/
|
||||
//object creation handling
|
||||
typedef SQUserPointer (*sqapi_newuserdata)(HSQUIRRELVM v,SQUnsignedInteger size);
|
||||
typedef void (*sqapi_newtable)(HSQUIRRELVM v);
|
||||
typedef void (*sqapi_newtableex)(HSQUIRRELVM v,SQInteger initialcapacity);
|
||||
@ -129,7 +129,7 @@ extern "C" {
|
||||
typedef SQRESULT (*sqapi_getbyhandle)(HSQUIRRELVM v,SQInteger idx,const HSQMEMBERHANDLE *handle);
|
||||
typedef SQRESULT (*sqapi_setbyhandle)(HSQUIRRELVM v,SQInteger idx,const HSQMEMBERHANDLE *handle);
|
||||
|
||||
/*object manipulation*/
|
||||
//object manipulation
|
||||
typedef void (*sqapi_pushroottable)(HSQUIRRELVM v);
|
||||
typedef void (*sqapi_pushregistrytable)(HSQUIRRELVM v);
|
||||
typedef void (*sqapi_pushconsttable)(HSQUIRRELVM v);
|
||||
@ -158,7 +158,7 @@ extern "C" {
|
||||
typedef SQRESULT (*sqapi_getweakrefval)(HSQUIRRELVM v,SQInteger idx);
|
||||
typedef SQRESULT (*sqapi_clear)(HSQUIRRELVM v,SQInteger idx);
|
||||
|
||||
/*calls*/
|
||||
//calls
|
||||
typedef SQRESULT (*sqapi_call)(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror);
|
||||
typedef SQRESULT (*sqapi_resume)(HSQUIRRELVM v,SQBool retval,SQBool raiseerror);
|
||||
typedef const SQChar* (*sqapi_getlocal)(HSQUIRRELVM v,SQUnsignedInteger level,SQUnsignedInteger idx);
|
||||
@ -169,7 +169,7 @@ extern "C" {
|
||||
typedef void (*sqapi_reseterror)(HSQUIRRELVM v);
|
||||
typedef void (*sqapi_getlasterror)(HSQUIRRELVM v);
|
||||
|
||||
/*raw object handling*/
|
||||
//raw object handling
|
||||
typedef SQRESULT (*sqapi_getstackobj)(HSQUIRRELVM v,SQInteger idx,HSQOBJECT *po);
|
||||
typedef void (*sqapi_pushobject)(HSQUIRRELVM v,HSQOBJECT obj);
|
||||
typedef void (*sqapi_addref)(HSQUIRRELVM v,HSQOBJECT *po);
|
||||
@ -185,44 +185,44 @@ extern "C" {
|
||||
typedef SQUnsignedInteger (*sqapi_getvmrefcount)(HSQUIRRELVM v, const HSQOBJECT *po);
|
||||
|
||||
|
||||
/*GC*/
|
||||
//GC
|
||||
typedef SQInteger (*sqapi_collectgarbage)(HSQUIRRELVM v);
|
||||
typedef SQRESULT (*sqapi_resurrectunreachable)(HSQUIRRELVM v);
|
||||
|
||||
/*serialization*/
|
||||
//serialization
|
||||
typedef SQRESULT (*sqapi_writeclosure)(HSQUIRRELVM vm,SQWRITEFUNC writef,SQUserPointer up);
|
||||
typedef SQRESULT (*sqapi_readclosure)(HSQUIRRELVM vm,SQREADFUNC readf,SQUserPointer up);
|
||||
|
||||
/*mem allocation*/
|
||||
//mem allocation
|
||||
typedef void* (*sqapi_malloc)(SQUnsignedInteger size);
|
||||
typedef void* (*sqapi_realloc)(void* p,SQUnsignedInteger oldsize,SQUnsignedInteger newsize);
|
||||
typedef void (*sqapi_free)(void *p,SQUnsignedInteger size);
|
||||
|
||||
/*debug*/
|
||||
//debug
|
||||
typedef SQRESULT (*sqapi_stackinfos)(HSQUIRRELVM v,SQInteger level,SQStackInfos *si);
|
||||
typedef void (*sqapi_setdebughook)(HSQUIRRELVM v);
|
||||
typedef void (*sqapi_setnativedebughook)(HSQUIRRELVM v,SQDEBUGHOOK hook);
|
||||
|
||||
/*compiler helpers*/
|
||||
//compiler helpers
|
||||
typedef SQRESULT (*sqapi_loadfile)(HSQUIRRELVM v,const SQChar *filename,SQBool printerror);
|
||||
typedef SQRESULT (*sqapi_dofile)(HSQUIRRELVM v,const SQChar *filename,SQBool retval,SQBool printerror);
|
||||
typedef SQRESULT (*sqapi_writeclosuretofile)(HSQUIRRELVM v,const SQChar *filename);
|
||||
|
||||
/*blob*/
|
||||
//blob
|
||||
typedef SQUserPointer (*sqapi_createblob)(HSQUIRRELVM v, SQInteger size);
|
||||
typedef SQRESULT (*sqapi_getblob)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *ptr);
|
||||
typedef SQInteger (*sqapi_getblobsize)(HSQUIRRELVM v,SQInteger idx);
|
||||
|
||||
/*string*/
|
||||
//string
|
||||
typedef SQRESULT (*sqapi_format)(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen,SQChar **output);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @cond DEV
|
||||
/// Allows modules to interface with Squirrel's C api without linking to the squirrel library
|
||||
/// If new functions are added to the Squirrel API, they should be added here too
|
||||
/// Allows modules to interface with Squirrel's C api without linking to the squirrel library.
|
||||
/// If new functions are added to the Squirrel API, they should be added here too.
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
typedef struct {
|
||||
/*vm*/
|
||||
//vm
|
||||
sqapi_open open;
|
||||
sqapi_newthread newthread;
|
||||
sqapi_seterrorhandler seterrorhandler;
|
||||
@ -243,14 +243,14 @@ extern "C" {
|
||||
sqapi_getvmstate getvmstate;
|
||||
sqapi_getversion getversion;
|
||||
|
||||
/*compiler*/
|
||||
//compiler
|
||||
sqapi_compile compile;
|
||||
sqapi_compilebuffer compilebuffer;
|
||||
sqapi_enabledebuginfo enabledebuginfo;
|
||||
sqapi_notifyallexceptions notifyallexceptions;
|
||||
sqapi_setcompilererrorhandler setcompilererrorhandler;
|
||||
|
||||
/*stack operations*/
|
||||
//stack operations
|
||||
sqapi_push push;
|
||||
sqapi_pop pop;
|
||||
sqapi_poptop poptop;
|
||||
@ -261,7 +261,7 @@ extern "C" {
|
||||
sqapi_cmp cmp;
|
||||
sqapi_move move;
|
||||
|
||||
/*object creation handling*/
|
||||
//object creation handling
|
||||
sqapi_newuserdata newuserdata;
|
||||
sqapi_newtable newtable;
|
||||
sqapi_newtableex newtableex;
|
||||
@ -317,7 +317,7 @@ extern "C" {
|
||||
sqapi_getbyhandle getbyhandle;
|
||||
sqapi_setbyhandle setbyhandle;
|
||||
|
||||
/*object manipulation*/
|
||||
//object manipulation
|
||||
sqapi_pushroottable pushroottable;
|
||||
sqapi_pushregistrytable pushregistrytable;
|
||||
sqapi_pushconsttable pushconsttable;
|
||||
@ -346,7 +346,7 @@ extern "C" {
|
||||
sqapi_getweakrefval getweakrefval;
|
||||
sqapi_clear clear;
|
||||
|
||||
/*calls*/
|
||||
//calls
|
||||
sqapi_call call;
|
||||
sqapi_resume resume;
|
||||
sqapi_getlocal getlocal;
|
||||
@ -357,7 +357,7 @@ extern "C" {
|
||||
sqapi_reseterror reseterror;
|
||||
sqapi_getlasterror getlasterror;
|
||||
|
||||
/*raw object handling*/
|
||||
//raw object handling
|
||||
sqapi_getstackobj getstackobj;
|
||||
sqapi_pushobject pushobject;
|
||||
sqapi_addref addref;
|
||||
@ -372,42 +372,42 @@ extern "C" {
|
||||
sqapi_getobjtypetag getobjtypetag;
|
||||
sqapi_getvmrefcount getvmrefcount;
|
||||
|
||||
/*GC*/
|
||||
//GC
|
||||
sqapi_collectgarbage collectgarbage;
|
||||
sqapi_resurrectunreachable resurrectunreachable;
|
||||
|
||||
/*serialization*/
|
||||
//serialization
|
||||
sqapi_writeclosure writeclosure;
|
||||
sqapi_readclosure readclosure;
|
||||
|
||||
/*mem allocation*/
|
||||
//mem allocation
|
||||
sqapi_malloc malloc;
|
||||
sqapi_realloc realloc;
|
||||
sqapi_free free;
|
||||
|
||||
/*debug*/
|
||||
//debug
|
||||
sqapi_stackinfos stackinfos;
|
||||
sqapi_setdebughook setdebughook;
|
||||
sqapi_setnativedebughook setnativedebughook;
|
||||
|
||||
/*compiler helpers*/
|
||||
//compiler helpers
|
||||
sqapi_loadfile loadfile;
|
||||
sqapi_dofile dofile;
|
||||
sqapi_writeclosuretofile writeclosuretofile;
|
||||
|
||||
/*blob*/
|
||||
//blob
|
||||
sqapi_createblob createblob;
|
||||
sqapi_getblob getblob;
|
||||
sqapi_getblobsize getblobsize;
|
||||
|
||||
/*string*/
|
||||
//string
|
||||
sqapi_format format;
|
||||
} sq_api, SQAPI, *HSQAPI;
|
||||
/// @endcond
|
||||
|
||||
#ifdef SQMOD_PLUGIN_API
|
||||
|
||||
/*vm*/
|
||||
//vm
|
||||
extern sqapi_open sq_open;
|
||||
extern sqapi_newthread sq_newthread;
|
||||
extern sqapi_seterrorhandler sq_seterrorhandler;
|
||||
@ -428,14 +428,14 @@ extern "C" {
|
||||
extern sqapi_getvmstate sq_getvmstate;
|
||||
extern sqapi_getversion sq_getversion;
|
||||
|
||||
/*compiler*/
|
||||
//compiler
|
||||
extern sqapi_compile sq_compile;
|
||||
extern sqapi_compilebuffer sq_compilebuffer;
|
||||
extern sqapi_enabledebuginfo sq_enabledebuginfo;
|
||||
extern sqapi_notifyallexceptions sq_notifyallexceptions;
|
||||
extern sqapi_setcompilererrorhandler sq_setcompilererrorhandler;
|
||||
|
||||
/*stack operations*/
|
||||
//stack operations
|
||||
extern sqapi_push sq_push;
|
||||
extern sqapi_pop sq_pop;
|
||||
extern sqapi_poptop sq_poptop;
|
||||
@ -446,7 +446,7 @@ extern "C" {
|
||||
extern sqapi_cmp sq_cmp;
|
||||
extern sqapi_move sq_move;
|
||||
|
||||
/*object creation handling*/
|
||||
//object creation handling
|
||||
extern sqapi_newuserdata sq_newuserdata;
|
||||
extern sqapi_newtable sq_newtable;
|
||||
extern sqapi_newtableex sq_newtableex;
|
||||
@ -502,7 +502,7 @@ extern "C" {
|
||||
extern sqapi_getbyhandle sq_getbyhandle;
|
||||
extern sqapi_setbyhandle sq_setbyhandle;
|
||||
|
||||
/*object manipulation*/
|
||||
//object manipulation
|
||||
extern sqapi_pushroottable sq_pushroottable;
|
||||
extern sqapi_pushregistrytable sq_pushregistrytable;
|
||||
extern sqapi_pushconsttable sq_pushconsttable;
|
||||
@ -531,7 +531,7 @@ extern "C" {
|
||||
extern sqapi_getweakrefval sq_getweakrefval;
|
||||
extern sqapi_clear sq_clear;
|
||||
|
||||
/*calls*/
|
||||
//calls
|
||||
extern sqapi_call sq_call;
|
||||
extern sqapi_resume sq_resume;
|
||||
extern sqapi_getlocal sq_getlocal;
|
||||
@ -542,7 +542,7 @@ extern "C" {
|
||||
extern sqapi_reseterror sq_reseterror;
|
||||
extern sqapi_getlasterror sq_getlasterror;
|
||||
|
||||
/*raw object handling*/
|
||||
//raw object handling
|
||||
extern sqapi_getstackobj sq_getstackobj;
|
||||
extern sqapi_pushobject sq_pushobject;
|
||||
extern sqapi_addref sq_addref;
|
||||
@ -557,35 +557,35 @@ extern "C" {
|
||||
extern sqapi_getobjtypetag sq_getobjtypetag;
|
||||
extern sqapi_getvmrefcount sq_getvmrefcount;
|
||||
|
||||
/*GC*/
|
||||
//GC
|
||||
extern sqapi_collectgarbage sq_collectgarbage;
|
||||
extern sqapi_resurrectunreachable sq_resurrectunreachable;
|
||||
|
||||
/*serialization*/
|
||||
//serialization
|
||||
extern sqapi_writeclosure sq_writeclosure;
|
||||
extern sqapi_readclosure sq_readclosure;
|
||||
|
||||
/*mem allocation*/
|
||||
//mem allocation
|
||||
extern sqapi_malloc sq_malloc;
|
||||
extern sqapi_realloc sq_realloc;
|
||||
extern sqapi_free sq_free;
|
||||
|
||||
/*debug*/
|
||||
//debug
|
||||
extern sqapi_stackinfos sq_stackinfos;
|
||||
extern sqapi_setdebughook sq_setdebughook;
|
||||
extern sqapi_setnativedebughook sq_setnativedebughook;
|
||||
|
||||
/*compiler helpers*/
|
||||
//compiler helpers
|
||||
extern sqapi_loadfile sqstd_loadfile;
|
||||
extern sqapi_dofile sqstd_dofile;
|
||||
extern sqapi_writeclosuretofile sqstd_writeclosuretofile;
|
||||
|
||||
/*blob*/
|
||||
//blob
|
||||
extern sqapi_createblob sqstd_createblob;
|
||||
extern sqapi_getblob sqstd_getblob;
|
||||
extern sqapi_getblobsize sqstd_getblobsize;
|
||||
|
||||
/*string*/
|
||||
//string
|
||||
extern sqapi_format sqstd_format;
|
||||
|
||||
#endif // SQMOD_PLUGIN_API
|
||||
|
@ -1,4 +1,5 @@
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#include "SqMod.h"
|
||||
|
||||
// This method is used to avoid compilers warning about C++ flags on C files and vice-versa.
|
||||
#include "SqMod.inl"
|
||||
/* This method is used toa void compilers warning about C++ flags on C files and viceversa. */
|
@ -1,4 +1,5 @@
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#include "SqMod.h"
|
||||
|
||||
// This method is used to avoid compilers warning about C++ flags on C files and vice-versa.
|
||||
#include "SqMod.inl"
|
||||
/* This method is used toa void compilers warning about C++ flags on C files and viceversa. */
|
@ -3,7 +3,7 @@
|
||||
//
|
||||
|
||||
//
|
||||
// Copyright (c) 2009 Sandu Liviu Catalin (aka. S.L.C)
|
||||
// Copyright (c) 2016 Sandu Liviu Catalin (aka. S.L.C)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
@ -78,9 +78,14 @@ extern "C" {
|
||||
typedef SqInt64 (*SqEx_GetEpochTimeMilli) (void);
|
||||
typedef SQRESULT (*SqEx_GetTimestamp) (HSQUIRRELVM vm, SQInteger idx, SqInt64 * num);
|
||||
typedef void (*SqEx_PushTimestamp) (HSQUIRRELVM vm, SqInt64 num);
|
||||
//stack utilities
|
||||
typedef SQInteger (*SqEx_PopStackInteger) (HSQUIRRELVM vm, SQInteger idx);
|
||||
typedef SQFloat (*SqEx_PopStackFloat) (HSQUIRRELVM vm, SQInteger idx);
|
||||
typedef SqInt64 (*SqEx_PopStackSLong) (HSQUIRRELVM vm, SQInteger idx);
|
||||
typedef SqUint64 (*SqEx_PopStackULong) (HSQUIRRELVM vm, SQInteger idx);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Allows modules to interface with the plugin API without linking of any sorts
|
||||
* Allows modules to interface with the plug-in API without linking of any sorts
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
@ -105,21 +110,26 @@ extern "C" {
|
||||
SqEx_LogMessage LogSFtl;
|
||||
//script loading
|
||||
SqEx_LoadScript LoadScript;
|
||||
/*long numbers*/
|
||||
//long numbers
|
||||
SqEx_GetSLongValue GetSLongValue;
|
||||
SqEx_PushSLongObject PushSLongObject;
|
||||
SqEx_GetULongValue GetULongValue;
|
||||
SqEx_PushULongObject PushULongObject;
|
||||
/*time utilities*/
|
||||
//time utilities
|
||||
SqEx_GetCurrentSysTime GetCurrentSysTime;
|
||||
SqEx_GetEpochTimeMicro GetEpochTimeMicro;
|
||||
SqEx_GetEpochTimeMilli GetEpochTimeMilli;
|
||||
SqEx_GetTimestamp GetTimestamp;
|
||||
SqEx_PushTimestamp PushTimestamp;
|
||||
//stack utilities
|
||||
SqEx_PopStackInteger PopStackInteger;
|
||||
SqEx_PopStackFloat PopStackFloat;
|
||||
SqEx_PopStackSLong PopStackSLong;
|
||||
SqEx_PopStackULong PopStackULong;
|
||||
} sq_exports, SQEXPORTS, *HSQEXPORTS;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Import the functions from the main squirrel plugin.
|
||||
* Import the functions from the main squirrel plug-in.
|
||||
*/
|
||||
SQUIRREL_API HSQEXPORTS sq_api_import(PluginFuncs * vcapi);
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#ifdef SQMOD_PLUGIN_API
|
||||
|
||||
/*vm*/
|
||||
//vm
|
||||
sqapi_open sq_open = NULL;
|
||||
sqapi_newthread sq_newthread = NULL;
|
||||
sqapi_seterrorhandler sq_seterrorhandler = NULL;
|
||||
@ -22,14 +22,14 @@ sqapi_wakeupvm sq_wakeupvm = NULL;
|
||||
sqapi_getvmstate sq_getvmstate = NULL;
|
||||
sqapi_getversion sq_getversion = NULL;
|
||||
|
||||
/*compiler*/
|
||||
//compiler
|
||||
sqapi_compile sq_compile = NULL;
|
||||
sqapi_compilebuffer sq_compilebuffer = NULL;
|
||||
sqapi_enabledebuginfo sq_enabledebuginfo = NULL;
|
||||
sqapi_notifyallexceptions sq_notifyallexceptions = NULL;
|
||||
sqapi_setcompilererrorhandler sq_setcompilererrorhandler = NULL;
|
||||
|
||||
/*stack operations*/
|
||||
//stack operations
|
||||
sqapi_push sq_push = NULL;
|
||||
sqapi_pop sq_pop = NULL;
|
||||
sqapi_poptop sq_poptop = NULL;
|
||||
@ -40,7 +40,7 @@ sqapi_reservestack sq_reservestack = NULL;
|
||||
sqapi_cmp sq_cmp = NULL;
|
||||
sqapi_move sq_move = NULL;
|
||||
|
||||
/*object creation handling*/
|
||||
//object creation handling
|
||||
sqapi_newuserdata sq_newuserdata = NULL;
|
||||
sqapi_newtable sq_newtable = NULL;
|
||||
sqapi_newtableex sq_newtableex = NULL;
|
||||
@ -96,7 +96,7 @@ sqapi_getmemberhandle sq_getmemberhandle = NULL;
|
||||
sqapi_getbyhandle sq_getbyhandle = NULL;
|
||||
sqapi_setbyhandle sq_setbyhandle = NULL;
|
||||
|
||||
/*object manipulation*/
|
||||
//object manipulation
|
||||
sqapi_pushroottable sq_pushroottable = NULL;
|
||||
sqapi_pushregistrytable sq_pushregistrytable = NULL;
|
||||
sqapi_pushconsttable sq_pushconsttable = NULL;
|
||||
@ -125,7 +125,7 @@ sqapi_next sq_next = NULL;
|
||||
sqapi_getweakrefval sq_getweakrefval = NULL;
|
||||
sqapi_clear sq_clear = NULL;
|
||||
|
||||
/*calls*/
|
||||
//calls
|
||||
sqapi_call sq_call = NULL;
|
||||
sqapi_resume sq_resume = NULL;
|
||||
sqapi_getlocal sq_getlocal = NULL;
|
||||
@ -136,7 +136,7 @@ sqapi_throwobject sq_throwobject = NULL;
|
||||
sqapi_reseterror sq_reseterror = NULL;
|
||||
sqapi_getlasterror sq_getlasterror = NULL;
|
||||
|
||||
/*raw object handling*/
|
||||
//raw object handling
|
||||
sqapi_getstackobj sq_getstackobj = NULL;
|
||||
sqapi_pushobject sq_pushobject = NULL;
|
||||
sqapi_addref sq_addref = NULL;
|
||||
@ -151,35 +151,35 @@ sqapi_objtouserpointer sq_objtouserpointer = NULL;
|
||||
sqapi_getobjtypetag sq_getobjtypetag = NULL;
|
||||
sqapi_getvmrefcount sq_getvmrefcount = NULL;
|
||||
|
||||
/*GC*/
|
||||
//GC
|
||||
sqapi_collectgarbage sq_collectgarbage = NULL;
|
||||
sqapi_resurrectunreachable sq_resurrectunreachable = NULL;
|
||||
|
||||
/*serialization*/
|
||||
//serialization
|
||||
sqapi_writeclosure sq_writeclosure = NULL;
|
||||
sqapi_readclosure sq_readclosure = NULL;
|
||||
|
||||
/*mem allocation*/
|
||||
//mem allocation
|
||||
sqapi_malloc sq_malloc = NULL;
|
||||
sqapi_realloc sq_realloc = NULL;
|
||||
sqapi_free sq_free = NULL;
|
||||
|
||||
/*debug*/
|
||||
//debug
|
||||
sqapi_stackinfos sq_stackinfos = NULL;
|
||||
sqapi_setdebughook sq_setdebughook = NULL;
|
||||
sqapi_setnativedebughook sq_setnativedebughook = NULL;
|
||||
|
||||
/*compiler helpers*/
|
||||
//compiler helpers
|
||||
sqapi_loadfile sqstd_loadfile = NULL;
|
||||
sqapi_dofile sqstd_dofile = NULL;
|
||||
sqapi_writeclosuretofile sqstd_writeclosuretofile = NULL;
|
||||
|
||||
/*blob*/
|
||||
//blob
|
||||
sqapi_createblob sqstd_createblob = NULL;
|
||||
sqapi_getblob sqstd_getblob = NULL;
|
||||
sqapi_getblobsize sqstd_getblobsize = NULL;
|
||||
|
||||
/*string*/
|
||||
//string
|
||||
sqapi_format sqstd_format = NULL;
|
||||
|
||||
#endif // SQMOD_PLUGIN_API
|
||||
@ -187,15 +187,15 @@ sqapi_format sqstd_format = NULL;
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
HSQEXPORTS sq_api_import(PluginFuncs * vcapi)
|
||||
{
|
||||
// Make sure a valid plugin api and reference to exports structure pointer was specified
|
||||
// Make sure a valid plug-in api and reference to exports structure pointer was specified
|
||||
if (!vcapi)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
size_t struct_size;
|
||||
// Attempt to find the main plugin ID
|
||||
// Attempt to find the main plug-in ID
|
||||
int plugin_id = vcapi->FindPlugin((char *)(SQMOD_HOST_NAME));
|
||||
// Attempt to retrieve the plugin exports
|
||||
// Attempt to retrieve the plug-in exports
|
||||
const void ** plugin_exports = vcapi->GetPluginExports(plugin_id, &struct_size);
|
||||
// See if we have any imports from Squirrel
|
||||
if (plugin_exports == NULL || struct_size <= 0)
|
||||
@ -210,11 +210,13 @@ HSQEXPORTS sq_api_import(PluginFuncs * vcapi)
|
||||
SQRESULT sq_api_expand(HSQAPI sqapi)
|
||||
{
|
||||
if (!sqapi)
|
||||
{
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
#ifdef SQMOD_PLUGIN_API
|
||||
|
||||
/*vm*/
|
||||
//vm
|
||||
sq_open = sqapi->open;
|
||||
sq_newthread = sqapi->newthread;
|
||||
sq_seterrorhandler = sqapi->seterrorhandler;
|
||||
@ -235,14 +237,14 @@ SQRESULT sq_api_expand(HSQAPI sqapi)
|
||||
sq_getvmstate = sqapi->getvmstate;
|
||||
sq_getversion = sqapi->getversion;
|
||||
|
||||
/*compiler*/
|
||||
//compiler
|
||||
sq_compile = sqapi->compile;
|
||||
sq_compilebuffer = sqapi->compilebuffer;
|
||||
sq_enabledebuginfo = sqapi->enabledebuginfo;
|
||||
sq_notifyallexceptions = sqapi->notifyallexceptions;
|
||||
sq_setcompilererrorhandler = sqapi->setcompilererrorhandler;
|
||||
|
||||
/*stack operations*/
|
||||
//stack operations
|
||||
sq_push = sqapi->push;
|
||||
sq_pop = sqapi->pop;
|
||||
sq_poptop = sqapi->poptop;
|
||||
@ -253,7 +255,7 @@ SQRESULT sq_api_expand(HSQAPI sqapi)
|
||||
sq_cmp = sqapi->cmp;
|
||||
sq_move = sqapi->move;
|
||||
|
||||
/*object creation handling*/
|
||||
//object creation handling
|
||||
sq_newuserdata = sqapi->newuserdata;
|
||||
sq_newtable = sqapi->newtable;
|
||||
sq_newtableex = sqapi->newtableex;
|
||||
@ -309,7 +311,7 @@ SQRESULT sq_api_expand(HSQAPI sqapi)
|
||||
sq_getbyhandle = sqapi->getbyhandle;
|
||||
sq_setbyhandle = sqapi->setbyhandle;
|
||||
|
||||
/*object manipulation*/
|
||||
//object manipulation
|
||||
sq_pushroottable = sqapi->pushroottable;
|
||||
sq_pushregistrytable = sqapi->pushregistrytable;
|
||||
sq_pushconsttable = sqapi->pushconsttable;
|
||||
@ -338,7 +340,7 @@ SQRESULT sq_api_expand(HSQAPI sqapi)
|
||||
sq_getweakrefval = sqapi->getweakrefval;
|
||||
sq_clear = sqapi->clear;
|
||||
|
||||
/*calls*/
|
||||
//calls
|
||||
sq_call = sqapi->call;
|
||||
sq_resume = sqapi->resume;
|
||||
sq_getlocal = sqapi->getlocal;
|
||||
@ -349,7 +351,7 @@ SQRESULT sq_api_expand(HSQAPI sqapi)
|
||||
sq_reseterror = sqapi->reseterror;
|
||||
sq_getlasterror = sqapi->getlasterror;
|
||||
|
||||
/*raw object handling*/
|
||||
//raw object handling
|
||||
sq_getstackobj = sqapi->getstackobj;
|
||||
sq_pushobject = sqapi->pushobject;
|
||||
sq_addref = sqapi->addref;
|
||||
@ -364,35 +366,35 @@ SQRESULT sq_api_expand(HSQAPI sqapi)
|
||||
sq_getobjtypetag = sqapi->getobjtypetag;
|
||||
sq_getvmrefcount = sqapi->getvmrefcount;
|
||||
|
||||
/*GC*/
|
||||
//GC
|
||||
sq_collectgarbage = sqapi->collectgarbage;
|
||||
sq_resurrectunreachable = sqapi->resurrectunreachable;
|
||||
|
||||
/*serialization*/
|
||||
//serialization
|
||||
sq_writeclosure = sqapi->writeclosure;
|
||||
sq_readclosure = sqapi->readclosure;
|
||||
|
||||
/*mem allocation*/
|
||||
//mem allocation
|
||||
sq_malloc = sqapi->malloc;
|
||||
sq_realloc = sqapi->realloc;
|
||||
sq_free = sqapi->free;
|
||||
|
||||
/*debug*/
|
||||
//debug
|
||||
sq_stackinfos = sqapi->stackinfos;
|
||||
sq_setdebughook = sqapi->setdebughook;
|
||||
sq_setnativedebughook = sqapi->setnativedebughook;
|
||||
|
||||
/*compiler helpers*/
|
||||
//compiler helpers
|
||||
sqstd_loadfile = sqapi->loadfile;
|
||||
sqstd_dofile = sqapi->dofile;
|
||||
sqstd_writeclosuretofile = sqapi->writeclosuretofile;
|
||||
|
||||
/*blob*/
|
||||
//blob
|
||||
sqstd_createblob = sqapi->createblob;
|
||||
sqstd_getblob = sqapi->getblob;
|
||||
sqstd_getblobsize = sqapi->getblobsize;
|
||||
|
||||
/*string*/
|
||||
//string
|
||||
sqstd_format = sqapi->format;
|
||||
|
||||
#endif // SQMOD_PLUGIN_API
|
||||
@ -405,7 +407,7 @@ void sq_api_collapse()
|
||||
{
|
||||
#ifdef SQMOD_PLUGIN_API
|
||||
|
||||
/*vm*/
|
||||
//vm
|
||||
sq_open = NULL;
|
||||
sq_newthread = NULL;
|
||||
sq_seterrorhandler = NULL;
|
||||
@ -426,14 +428,14 @@ void sq_api_collapse()
|
||||
sq_getvmstate = NULL;
|
||||
sq_getversion = NULL;
|
||||
|
||||
/*compiler*/
|
||||
//compiler
|
||||
sq_compile = NULL;
|
||||
sq_compilebuffer = NULL;
|
||||
sq_enabledebuginfo = NULL;
|
||||
sq_notifyallexceptions = NULL;
|
||||
sq_setcompilererrorhandler = NULL;
|
||||
|
||||
/*stack operations*/
|
||||
//stack operations
|
||||
sq_push = NULL;
|
||||
sq_pop = NULL;
|
||||
sq_poptop = NULL;
|
||||
@ -444,7 +446,7 @@ void sq_api_collapse()
|
||||
sq_cmp = NULL;
|
||||
sq_move = NULL;
|
||||
|
||||
/*object creation handling*/
|
||||
//object creation handling
|
||||
sq_newuserdata = NULL;
|
||||
sq_newtable = NULL;
|
||||
sq_newtableex = NULL;
|
||||
@ -500,7 +502,7 @@ void sq_api_collapse()
|
||||
sq_getbyhandle = NULL;
|
||||
sq_setbyhandle = NULL;
|
||||
|
||||
/*object manipulation*/
|
||||
//object manipulation
|
||||
sq_pushroottable = NULL;
|
||||
sq_pushregistrytable = NULL;
|
||||
sq_pushconsttable = NULL;
|
||||
@ -529,7 +531,7 @@ void sq_api_collapse()
|
||||
sq_getweakrefval = NULL;
|
||||
sq_clear = NULL;
|
||||
|
||||
/*calls*/
|
||||
//calls
|
||||
sq_call = NULL;
|
||||
sq_resume = NULL;
|
||||
sq_getlocal = NULL;
|
||||
@ -540,7 +542,7 @@ void sq_api_collapse()
|
||||
sq_reseterror = NULL;
|
||||
sq_getlasterror = NULL;
|
||||
|
||||
/*raw object handling*/
|
||||
//raw object handling
|
||||
sq_getstackobj = NULL;
|
||||
sq_pushobject = NULL;
|
||||
sq_addref = NULL;
|
||||
@ -555,35 +557,35 @@ void sq_api_collapse()
|
||||
sq_getobjtypetag = NULL;
|
||||
sq_getvmrefcount = NULL;
|
||||
|
||||
/*GC*/
|
||||
//GC
|
||||
sq_collectgarbage = NULL;
|
||||
sq_resurrectunreachable = NULL;
|
||||
|
||||
/*serialization*/
|
||||
//serialization
|
||||
sq_writeclosure = NULL;
|
||||
sq_readclosure = NULL;
|
||||
|
||||
/*mem allocation*/
|
||||
//mem allocation
|
||||
sq_malloc = NULL;
|
||||
sq_realloc = NULL;
|
||||
sq_free = NULL;
|
||||
|
||||
/*debug*/
|
||||
//debug
|
||||
sq_stackinfos = NULL;
|
||||
sq_setdebughook = NULL;
|
||||
sq_setnativedebughook = NULL;
|
||||
|
||||
/*compiler helpers*/
|
||||
//compiler helpers
|
||||
sqstd_loadfile = NULL;
|
||||
sqstd_dofile = NULL;
|
||||
sqstd_writeclosuretofile = NULL;
|
||||
|
||||
/*blob*/
|
||||
//blob
|
||||
sqstd_createblob = NULL;
|
||||
sqstd_getblob = NULL;
|
||||
sqstd_getblobsize = NULL;
|
||||
|
||||
/*string*/
|
||||
//string
|
||||
sqstd_format = NULL;
|
||||
|
||||
#endif // SQMOD_PLUGIN_API
|
||||
|
@ -457,11 +457,11 @@ void Register_AABB(HSQUIRRELVM vm)
|
||||
.Var(_SC("Max"), &AABB::max)
|
||||
// Properties
|
||||
.Prop(_SC("Abs"), &AABB::Abs)
|
||||
// Core Metamethods
|
||||
// Core Meta-methods
|
||||
.Func(_SC("_tostring"), &AABB::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &AABB::Typename)
|
||||
.Func(_SC("_cmp"), &AABB::Cmp)
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func< AABB (AABB::*)(const AABB &) const >(_SC("_add"), &AABB::operator +)
|
||||
.Func< AABB (AABB::*)(const AABB &) const >(_SC("_sub"), &AABB::operator -)
|
||||
.Func< AABB (AABB::*)(const AABB &) const >(_SC("_mul"), &AABB::operator *)
|
||||
|
@ -513,11 +513,11 @@ void Register_Circle(HSQUIRRELVM vm)
|
||||
.Var(_SC("Rad"), &Circle::rad)
|
||||
// Properties
|
||||
.Prop(_SC("Abs"), &Circle::Abs)
|
||||
// Core Metamethods
|
||||
// Core Meta-methods
|
||||
.Func(_SC("_tostring"), &Circle::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Circle::Typename)
|
||||
.Func(_SC("_cmp"), &Circle::Cmp)
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func< Circle (Circle::*)(const Circle &) const >(_SC("_add"), &Circle::operator +)
|
||||
.Func< Circle (Circle::*)(const Circle &) const >(_SC("_sub"), &Circle::operator -)
|
||||
.Func< Circle (Circle::*)(const Circle &) const >(_SC("_mul"), &Circle::operator *)
|
||||
|
@ -661,11 +661,11 @@ void Register_Color3(HSQUIRRELVM vm)
|
||||
.Prop(_SC("RGBA"), &Color3::GetRGBA, &Color3::SetRGBA)
|
||||
.Prop(_SC("ARGB"), &Color3::GetARGB, &Color3::SetARGB)
|
||||
.Prop(_SC("Str"), &Color3::SetCol)
|
||||
// Core Metamethods
|
||||
// Core Meta-methods
|
||||
.Func(_SC("_tostring"), &Color3::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Color3::Typename)
|
||||
.Func(_SC("_cmp"), &Color3::Cmp)
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("_add"), &Color3::operator +)
|
||||
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("_sub"), &Color3::operator -)
|
||||
.Func< Color3 (Color3::*)(const Color3 &) const >(_SC("_mul"), &Color3::operator *)
|
||||
|
@ -721,11 +721,11 @@ void Register_Color4(HSQUIRRELVM vm)
|
||||
.Prop(_SC("RGBA"), &Color4::GetRGBA, &Color4::SetRGBA)
|
||||
.Prop(_SC("ARGB"), &Color4::GetARGB, &Color4::SetARGB)
|
||||
.Prop(_SC("Str"), &Color4::SetCol)
|
||||
// Core Metamethods
|
||||
// Core Meta-methods
|
||||
.Func(_SC("_tostring"), &Color4::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Color4::Typename)
|
||||
.Func(_SC("_cmp"), &Color4::Cmp)
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("_add"), &Color4::operator +)
|
||||
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("_sub"), &Color4::operator -)
|
||||
.Func< Color4 (Color4::*)(const Color4 &) const >(_SC("_mul"), &Color4::operator *)
|
||||
|
@ -516,11 +516,11 @@ void Register_Quaternion(HSQUIRRELVM vm)
|
||||
.Var(_SC("W"), &Quaternion::w)
|
||||
// Properties
|
||||
.Prop(_SC("Abs"), &Quaternion::Abs)
|
||||
// Core Metamethods
|
||||
// Core Meta-methods
|
||||
.Func(_SC("_tostring"), &Quaternion::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Quaternion::Typename)
|
||||
.Func(_SC("_cmp"), &Quaternion::Cmp)
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("_add"), &Quaternion::operator +)
|
||||
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("_sub"), &Quaternion::operator -)
|
||||
.Func< Quaternion (Quaternion::*)(const Quaternion &) const >(_SC("_mul"), &Quaternion::operator *)
|
||||
|
@ -7,27 +7,12 @@
|
||||
#include "Library/Numeric.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <ctime>
|
||||
#include <cfloat>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
PluginFuncs* _Func = nullptr;
|
||||
PluginCallbacks* _Clbk = nullptr;
|
||||
PluginInfo* _Info = nullptr;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Common buffer to reduce memory allocations. To be immediately copied upon return!
|
||||
*/
|
||||
static SQChar g_Buffer[4096];
|
||||
static SQChar g_NumBuff[1024];
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const Color3 SQ_Color_List[] =
|
||||
{
|
||||
@ -216,115 +201,6 @@ const ULongInt & GetULongInt(CSStr s)
|
||||
return l;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object & NullObject()
|
||||
{
|
||||
static Object o;
|
||||
o.Release();
|
||||
return o;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
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;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool SToB(CSStr 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) ? true : false;
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SqThrowF(CSStr fmt, ...)
|
||||
{
|
||||
// Acquire a moderately sized buffer
|
||||
Buffer b(128);
|
||||
// Initialize the argument list
|
||||
va_list args;
|
||||
va_start (args, fmt);
|
||||
// Attempt to run the specified format
|
||||
if (b.WriteF(0, fmt, args) == 0)
|
||||
{
|
||||
// Attempt to write a generic message at least
|
||||
b.At(b.WriteS(0, "Unknown error has occurred")) = '\0';
|
||||
}
|
||||
// Release the argument list
|
||||
va_end(args);
|
||||
// Throw the exception with the resulted message
|
||||
throw Sqrat::Exception(b.Get< SQChar >());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ToStrF(CSStr fmt, ...)
|
||||
{
|
||||
// Prepare the arguments list
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
// Attempt to run the specified format
|
||||
int ret = vsnprintf(g_Buffer, sizeof(g_Buffer), fmt, args);
|
||||
// See if the format function failed
|
||||
if (ret < 0)
|
||||
{
|
||||
STHROWF("Failed to run the specified string format");
|
||||
}
|
||||
// Finalized the arguments list
|
||||
va_end(args);
|
||||
// Return the resulted string
|
||||
return g_Buffer;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ToStringF(CSStr fmt, ...)
|
||||
{
|
||||
// Acquire a moderately sized buffer
|
||||
Buffer b(128);
|
||||
// Prepare the arguments list
|
||||
va_list args;
|
||||
va_start (args, fmt);
|
||||
// Attempt to run the specified format
|
||||
if (b.WriteF(0, fmt, args) == 0)
|
||||
{
|
||||
// Make sure the string is null terminated
|
||||
b.At(0) = 0;
|
||||
}
|
||||
// Finalized the arguments list
|
||||
va_end(args);
|
||||
// Return the resulted string
|
||||
return b.Get< SQChar >();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Color3 & GetRandomColor()
|
||||
{
|
||||
@ -937,303 +813,6 @@ Color3 GetColor(CSStr name)
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Int8 >::ToStr(Int8 v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuff, sizeof(g_NumBuff), "%d", v) < 0)
|
||||
{
|
||||
g_NumBuff[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuff;
|
||||
}
|
||||
|
||||
Int8 ConvNum< Int8 >::FromStr(CSStr s)
|
||||
{
|
||||
return ConvTo< Int8 >::From(std::strtol(s, nullptr, 10));
|
||||
}
|
||||
|
||||
Int8 ConvNum< Int8 >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return ConvTo< Int8 >::From(std::strtol(s, nullptr, base));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Uint8 >::ToStr(Uint8 v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuff, sizeof(g_NumBuff), "%u", v) < 0)
|
||||
{
|
||||
g_NumBuff[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuff;
|
||||
}
|
||||
|
||||
Uint8 ConvNum< Uint8 >::FromStr(CSStr s)
|
||||
{
|
||||
return ConvTo< Uint8 >::From(std::strtoul(s, nullptr, 10));
|
||||
}
|
||||
|
||||
Uint8 ConvNum< Uint8 >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return ConvTo< Uint8 >::From(std::strtoul(s, nullptr, base));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Int16 >::ToStr(Int16 v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuff, sizeof(g_NumBuff), "%d", v) < 0)
|
||||
{
|
||||
g_NumBuff[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuff;
|
||||
}
|
||||
|
||||
Int16 ConvNum< Int16 >::FromStr(CSStr s)
|
||||
{
|
||||
return ConvTo< Int16 >::From(std::strtol(s, nullptr, 10));
|
||||
}
|
||||
|
||||
Int16 ConvNum< Int16 >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return ConvTo< Int16 >::From(std::strtol(s, nullptr, base));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Uint16 >::ToStr(Uint16 v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuff, sizeof(g_NumBuff), "%u", v) < 0)
|
||||
{
|
||||
g_NumBuff[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuff;
|
||||
}
|
||||
|
||||
Uint16 ConvNum< Uint16 >::FromStr(CSStr s)
|
||||
{
|
||||
return ConvTo< Uint16 >::From(std::strtoul(s, nullptr, 10));
|
||||
}
|
||||
|
||||
Uint16 ConvNum< Uint16 >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return ConvTo< Uint16 >::From(std::strtoul(s, nullptr, base));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Int32 >::ToStr(Int32 v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuff, sizeof(g_NumBuff), "%d", v) < 0)
|
||||
{
|
||||
g_NumBuff[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuff;
|
||||
}
|
||||
|
||||
Int32 ConvNum< Int32 >::FromStr(CSStr s)
|
||||
{
|
||||
return ConvTo< Int32 >::From(std::strtol(s, nullptr, 10));
|
||||
}
|
||||
|
||||
Int32 ConvNum< Int32 >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return ConvTo< Int32 >::From(std::strtol(s, nullptr, base));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Uint32 >::ToStr(Uint32 v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuff, sizeof(g_NumBuff), "%u", v) < 0)
|
||||
{
|
||||
g_NumBuff[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuff;
|
||||
}
|
||||
|
||||
Uint32 ConvNum< Uint32 >::FromStr(CSStr s)
|
||||
{
|
||||
return ConvTo< Uint32 >::From(std::strtoul(s, nullptr, 10));
|
||||
}
|
||||
|
||||
Uint32 ConvNum< Uint32 >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return ConvTo< Uint32 >::From(std::strtoul(s, nullptr, base));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Int64 >::ToStr(Int64 v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuff, sizeof(g_NumBuff), "%lld", v) < 0)
|
||||
{
|
||||
g_NumBuff[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuff;
|
||||
}
|
||||
|
||||
Int64 ConvNum< Int64 >::FromStr(CSStr s)
|
||||
{
|
||||
return std::strtoll(s, nullptr, 10);
|
||||
}
|
||||
|
||||
Int64 ConvNum< Int64 >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return std::strtoll(s, nullptr, base);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Uint64 >::ToStr(Uint64 v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuff, sizeof(g_NumBuff), "%llu", v) < 0)
|
||||
{
|
||||
g_NumBuff[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuff;
|
||||
}
|
||||
|
||||
Uint64 ConvNum< Uint64 >::FromStr(CSStr s)
|
||||
{
|
||||
return std::strtoull(s, nullptr, 10);
|
||||
}
|
||||
|
||||
Uint64 ConvNum< Uint64 >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return std::strtoull(s, nullptr, base);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< LongI >::ToStr(LongI v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuff, sizeof(g_NumBuff), "%ld", v) < 0)
|
||||
{
|
||||
g_NumBuff[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuff;
|
||||
}
|
||||
|
||||
LongI ConvNum< LongI >::FromStr(CSStr s)
|
||||
{
|
||||
return std::strtol(s, nullptr, 10);
|
||||
}
|
||||
|
||||
LongI ConvNum< LongI >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return std::strtol(s, nullptr, base);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Ulong >::ToStr(Ulong v)
|
||||
{
|
||||
// Write the numeric value to the buffer
|
||||
if (std::snprintf(g_NumBuff, sizeof(g_NumBuff), "%lu", v) < 0)
|
||||
{
|
||||
g_NumBuff[0] = '\0';
|
||||
}
|
||||
// Return the beginning of the buffer
|
||||
return g_NumBuff;
|
||||
}
|
||||
|
||||
Ulong ConvNum< Ulong >::FromStr(CSStr s)
|
||||
{
|
||||
return std::strtoul(s, nullptr, 10);
|
||||
}
|
||||
|
||||
Ulong ConvNum< Ulong >::FromStr(CSStr s, Int32 base)
|
||||
{
|
||||
return std::strtoul(s, nullptr, base);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Float32 >::ToStr(Float32 v)
|
||||
{
|
||||
// Attempt to convert the value to a string
|
||||
if (std::snprintf(g_NumBuff, sizeof(g_NumBuff), "%f", v) < 0)
|
||||
{
|
||||
g_NumBuff[0] = '\0';
|
||||
}
|
||||
// Return the data from the buffer
|
||||
return g_NumBuff;
|
||||
}
|
||||
|
||||
Float32 ConvNum< Float32 >::FromStr(CSStr s)
|
||||
{
|
||||
return std::strtof(s, nullptr);
|
||||
}
|
||||
|
||||
Float32 ConvNum< Float32 >::FromStr(CSStr s, Int32 /*base*/)
|
||||
{
|
||||
return std::strtof(s, nullptr);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< Float64 >::ToStr(Float64 v)
|
||||
{
|
||||
// Attempt to convert the value to a string
|
||||
if (std::snprintf(g_NumBuff, sizeof(g_NumBuff), "%f", v) < 0)
|
||||
{
|
||||
g_NumBuff[0] = '\0';
|
||||
}
|
||||
// Return the data from the buffer
|
||||
return g_NumBuff;
|
||||
}
|
||||
|
||||
Float64 ConvNum< Float64 >::FromStr(CSStr s)
|
||||
{
|
||||
return std::strtod(s, nullptr);
|
||||
}
|
||||
|
||||
Float64 ConvNum< Float64 >::FromStr(CSStr s, Int32 /*base*/)
|
||||
{
|
||||
return std::strtod(s, nullptr);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr ConvNum< bool >::ToStr(bool v)
|
||||
{
|
||||
if (v)
|
||||
{
|
||||
g_NumBuff[0] = 't';
|
||||
g_NumBuff[1] = 'r';
|
||||
g_NumBuff[2] = 'u';
|
||||
g_NumBuff[3] = 'e';
|
||||
g_NumBuff[4] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
g_NumBuff[0] = 'f';
|
||||
g_NumBuff[1] = 'a';
|
||||
g_NumBuff[2] = 'l';
|
||||
g_NumBuff[3] = 's';
|
||||
g_NumBuff[4] = 'e';
|
||||
g_NumBuff[5] = '\0';
|
||||
}
|
||||
return g_NumBuff;
|
||||
}
|
||||
|
||||
bool ConvNum< bool >::FromStr(CSStr s)
|
||||
{
|
||||
return (std::strcmp(s, "true") == 0) ? true : false;
|
||||
}
|
||||
|
||||
bool ConvNum< bool >::FromStr(CSStr s, Int32 /*base*/)
|
||||
{
|
||||
return (std::strcmp(s, "true") == 0) ? true : false;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Base(HSQUIRRELVM vm)
|
||||
{
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -514,11 +514,11 @@ void Register_Sphere(HSQUIRRELVM vm)
|
||||
.Var(_SC("Rad"), &Sphere::rad)
|
||||
// Properties
|
||||
.Prop(_SC("Abs"), &Sphere::Abs)
|
||||
// Core Metamethods
|
||||
// Core Meta-methods
|
||||
.Func(_SC("_tostring"), &Sphere::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Sphere::Typename)
|
||||
.Func(_SC("_cmp"), &Sphere::Cmp)
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("_add"), &Sphere::operator +)
|
||||
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("_sub"), &Sphere::operator -)
|
||||
.Func< Sphere (Sphere::*)(const Sphere &) const >(_SC("_mul"), &Sphere::operator *)
|
||||
|
@ -1,413 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Base/Stack.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Buffer.hpp"
|
||||
#include "Library/Numeric.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sqstdstring.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
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;
|
||||
} break;
|
||||
case OT_FLOAT:
|
||||
{
|
||||
SQFloat val;
|
||||
sq_getfloat(vm, idx, &val);
|
||||
return ConvTo< SQInteger >::From(val);
|
||||
} break;
|
||||
case OT_BOOL:
|
||||
{
|
||||
SQBool val;
|
||||
sq_getbool(vm, idx, &val);
|
||||
return static_cast< SQInteger >(val);
|
||||
} break;
|
||||
case OT_STRING:
|
||||
{
|
||||
CSStr val = nullptr;
|
||||
// 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));
|
||||
}
|
||||
} break;
|
||||
case OT_ARRAY:
|
||||
case OT_TABLE:
|
||||
case OT_CLASS:
|
||||
case OT_USERDATA:
|
||||
{
|
||||
return sq_getsize(vm, idx);
|
||||
} break;
|
||||
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...
|
||||
}
|
||||
// Attempt to get the size of the instance as a fallback
|
||||
return sq_getsize(vm, idx);
|
||||
} break;
|
||||
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;
|
||||
} break;
|
||||
case OT_INTEGER:
|
||||
{
|
||||
SQInteger val;
|
||||
sq_getinteger(vm, idx, &val);
|
||||
return ConvTo< SQFloat >::From(val);
|
||||
} break;
|
||||
case OT_BOOL:
|
||||
{
|
||||
SQBool val;
|
||||
sq_getbool(vm, idx, &val);
|
||||
return ConvTo< SQFloat >::From(val);
|
||||
} break;
|
||||
case OT_STRING:
|
||||
{
|
||||
CSStr val = nullptr;
|
||||
// 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
|
||||
}
|
||||
} break;
|
||||
case OT_ARRAY:
|
||||
case OT_TABLE:
|
||||
case OT_CLASS:
|
||||
case OT_USERDATA:
|
||||
{
|
||||
return ConvTo< SQFloat >::From(sq_getsize(vm, idx));
|
||||
} break;
|
||||
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...
|
||||
}
|
||||
// Attempt to get the size of the instance as a fallback
|
||||
return ConvTo< SQFloat >::From(sq_getsize(vm, idx));
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
// Default to 0
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int64 PopStackLong(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 static_cast< Int64 >(val);
|
||||
} break;
|
||||
case OT_FLOAT:
|
||||
{
|
||||
SQFloat val;
|
||||
sq_getfloat(vm, idx, &val);
|
||||
return ConvTo< Int64 >::From(val);
|
||||
} break;
|
||||
case OT_BOOL:
|
||||
{
|
||||
SQBool val;
|
||||
sq_getbool(vm, idx, &val);
|
||||
return static_cast< Int64 >(val);
|
||||
} break;
|
||||
case OT_STRING:
|
||||
{
|
||||
CSStr val = nullptr;
|
||||
// Attempt to retrieve and convert the string
|
||||
if (SQ_SUCCEEDED(sq_getstring(vm, idx, &val)) && val != nullptr && *val != '\0')
|
||||
{
|
||||
return std::strtoll(val, nullptr, 10);
|
||||
}
|
||||
} break;
|
||||
case OT_ARRAY:
|
||||
case OT_TABLE:
|
||||
case OT_CLASS:
|
||||
case OT_USERDATA:
|
||||
{
|
||||
return static_cast< Int64 >(sq_getsize(vm, idx));
|
||||
} break;
|
||||
case OT_INSTANCE:
|
||||
{
|
||||
// Attempt to treat the value as a signed long instance
|
||||
try
|
||||
{
|
||||
return Var< const SLongInt & >(vm, idx).value.GetNum();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Just ignore it...
|
||||
}
|
||||
// Attempt to treat the value as a unsigned long instance
|
||||
try
|
||||
{
|
||||
return ConvTo< Int64 >::From(Var< const ULongInt & >(vm, idx).value.GetNum());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Just ignore it...
|
||||
}
|
||||
// Attempt to get the size of the instance as a fallback
|
||||
return static_cast< Int64 >(sq_getsize(vm, idx));
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
// Default to 0
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint64 PopStackULong(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 ConvTo< Uint64 >::From(val);
|
||||
} break;
|
||||
case OT_FLOAT:
|
||||
{
|
||||
SQFloat val;
|
||||
sq_getfloat(vm, idx, &val);
|
||||
return ConvTo< Uint64 >::From(val);
|
||||
} break;
|
||||
case OT_BOOL:
|
||||
{
|
||||
SQBool val;
|
||||
sq_getbool(vm, idx, &val);
|
||||
return ConvTo< Uint64 >::From(val);
|
||||
} break;
|
||||
case OT_STRING:
|
||||
{
|
||||
CSStr val = nullptr;
|
||||
// Attempt to retrieve and convert the string
|
||||
if (SQ_SUCCEEDED(sq_getstring(vm, idx, &val)) && val != nullptr && *val != '\0')
|
||||
{
|
||||
return std::strtoull(val, nullptr, 10);
|
||||
}
|
||||
} break;
|
||||
case OT_ARRAY:
|
||||
case OT_TABLE:
|
||||
case OT_CLASS:
|
||||
case OT_USERDATA:
|
||||
{
|
||||
return ConvTo< Uint64 >::From(sq_getsize(vm, idx));
|
||||
} break;
|
||||
case OT_INSTANCE:
|
||||
{
|
||||
// Attempt to treat the value as a signed long instance
|
||||
try
|
||||
{
|
||||
return ConvTo< Uint64 >::From(Var< const SLongInt & >(vm, idx).value.GetNum());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Just ignore it...
|
||||
}
|
||||
// Attempt to treat the value as a unsigned long instance
|
||||
try
|
||||
{
|
||||
return Var< const ULongInt & >(vm, idx).value.GetNum();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Just ignore it...
|
||||
}
|
||||
// Attempt to get the size of the instance as a fallback
|
||||
return ConvTo< Uint64 >::From(sq_getsize(vm, idx));
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
// Default to 0
|
||||
return 0;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
StackStrF::StackStrF(HSQUIRRELVM vm, SQInteger idx, bool fmt)
|
||||
: mPtr(nullptr)
|
||||
, mLen(-1)
|
||||
, mRes(SQ_OK)
|
||||
, mObj()
|
||||
, mVM(vm)
|
||||
{
|
||||
const Int32 top = sq_gettop(vm);
|
||||
// Reset the converted value object
|
||||
sq_resetobject(&mObj);
|
||||
// Was the string or value specified?
|
||||
if (top <= (idx - 1))
|
||||
{
|
||||
mRes = sq_throwerror(vm, "Missing string or value");
|
||||
}
|
||||
// Do we have enough values to call the format function and are we allowed to?
|
||||
else if (top > idx && fmt)
|
||||
{
|
||||
// Pointer to the generated string
|
||||
SStr str = nullptr;
|
||||
// Attempt to generate the specified string format
|
||||
mRes = sqstd_format(vm, idx, &mLen, &str);
|
||||
// Did the format succeeded but ended up with a null string pointer?
|
||||
if (SQ_SUCCEEDED(mRes) && !str)
|
||||
{
|
||||
mRes = sq_throwerror(vm, "Unable to generate the string");
|
||||
}
|
||||
else
|
||||
{
|
||||
mPtr = const_cast< CSStr >(str);
|
||||
}
|
||||
}
|
||||
// Is the value on the stack an actual string?
|
||||
else if (sq_gettype(vm, idx) == OT_STRING)
|
||||
{
|
||||
// Obtain a reference to the string object
|
||||
mRes = sq_getstackobj(vm, idx, &mObj);
|
||||
// Could we retrieve the object from the stack?
|
||||
if (SQ_SUCCEEDED(mRes))
|
||||
{
|
||||
// Keep a strong reference to the object
|
||||
sq_addref(vm, &mObj);
|
||||
// Attempt to retrieve the string value from the stack
|
||||
mRes = sq_getstring(vm, idx, &mPtr);
|
||||
}
|
||||
// Did the retrieval succeeded but ended up with a null string pointer?
|
||||
if (SQ_SUCCEEDED(mRes) && !mPtr)
|
||||
{
|
||||
mRes = sq_throwerror(vm, "Unable to retrieve the string");
|
||||
}
|
||||
}
|
||||
// We have to try and convert it to string
|
||||
else
|
||||
{
|
||||
// Attempt to convert the value from the stack to a string
|
||||
mRes = sq_tostring(vm, idx);
|
||||
// Could we convert the specified value to string?
|
||||
if (SQ_SUCCEEDED(mRes))
|
||||
{
|
||||
// Obtain a reference to the resulted object
|
||||
mRes = sq_getstackobj(vm, -1, &mObj);
|
||||
// Could we retrieve the object from the stack?
|
||||
if (SQ_SUCCEEDED(mRes))
|
||||
{
|
||||
// Keep a strong reference to the object
|
||||
sq_addref(vm, &mObj);
|
||||
// Attempt to obtain the string pointer
|
||||
mRes = sq_getstring(vm, -1, &mPtr);
|
||||
}
|
||||
}
|
||||
// Pop a value from the stack regardless of the result
|
||||
sq_pop(vm, 1);
|
||||
// Did the retrieval succeeded but ended up with a null string pointer?
|
||||
if (SQ_SUCCEEDED(mRes) && !mPtr)
|
||||
{
|
||||
mRes = sq_throwerror(vm, "Unable to retrieve the value");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
StackStrF::~StackStrF()
|
||||
{
|
||||
if (mVM && !sq_isnull(mObj))
|
||||
{
|
||||
sq_release(mVM, &mObj);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object BufferToStrObj(const Buffer & b)
|
||||
{
|
||||
// Obtain the initial stack size
|
||||
const StackGuard sg(DefaultVM::Get());
|
||||
// Push the string onto the stack
|
||||
sq_pushstring(DefaultVM::Get(), b.Data(), b.Position());
|
||||
// Obtain the object from the stack and return it
|
||||
return Var< Object >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Object BufferToStrObj(const Buffer & b, Uint32 size)
|
||||
{
|
||||
// Perform a range check on the specified buffer
|
||||
if (size > b.Capacity())
|
||||
{
|
||||
STHROWF("The specified buffer size is out of range: %u >= %u", size, b.Capacity());
|
||||
}
|
||||
// Obtain the initial stack size
|
||||
const StackGuard sg(DefaultVM::Get());
|
||||
// Push the string onto the stack
|
||||
sq_pushstring(DefaultVM::Get(), b.Data(), size);
|
||||
// Obtain the object from the stack and return it
|
||||
return Var< Object >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,172 +0,0 @@
|
||||
#ifndef _BASE_STACK_HPP_
|
||||
#define _BASE_STACK_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "SqBase.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sqrat.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Attempt to pop the value at the specified index on the stack as a native integer.
|
||||
*/
|
||||
SQInteger PopStackInteger(HSQUIRRELVM vm, SQInteger idx);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Attempt to pop the value at the specified index on the stack as a native float.
|
||||
*/
|
||||
SQFloat PopStackFloat(HSQUIRRELVM vm, SQInteger idx);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Attempt to pop the value at the specified index on the stack as a signed long integer.
|
||||
*/
|
||||
Int64 PopStackLong(HSQUIRRELVM vm, SQInteger idx);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Attempt to pop the value at the specified index on the stack as an unsigned long integer.
|
||||
*/
|
||||
Uint64 PopStackULong(HSQUIRRELVM vm, SQInteger idx);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Create a script string object from a buffer.
|
||||
*/
|
||||
Object BufferToStrObj(const Buffer & b);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Create a script string object from a portion of a buffer.
|
||||
*/
|
||||
Object BufferToStrObj(const Buffer & b, Uint32 size);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Implements RAII to restore the VM stack to it's initial size on function exit.
|
||||
*/
|
||||
struct StackGuard
|
||||
{
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
StackGuard()
|
||||
: m_VM(DefaultVM::Get()), m_Top(sq_gettop(m_VM))
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
StackGuard(HSQUIRRELVM vm)
|
||||
: m_VM(vm), m_Top(sq_gettop(vm))
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
StackGuard(const StackGuard &) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor. (disabled)
|
||||
*/
|
||||
StackGuard(StackGuard &&) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~StackGuard()
|
||||
{
|
||||
sq_pop(m_VM, sq_gettop(m_VM) - m_Top);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator. (disabled)
|
||||
*/
|
||||
StackGuard & operator = (const StackGuard &) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator. (disabled)
|
||||
*/
|
||||
StackGuard & operator = (StackGuard &&) = delete;
|
||||
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
HSQUIRRELVM m_VM; // The VM where the stack should be restored.
|
||||
Int32 m_Top; // The top of the stack when this instance was created.
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Helper structure for retrieving a value from the stack as a string or a formatted string.
|
||||
*/
|
||||
struct StackStrF
|
||||
{
|
||||
// --------------------------------------------------------------------------------------------
|
||||
CSStr mPtr; // Pointer to the C string that was retrieved.
|
||||
SQInteger mLen; // The string length if it could be retrieved.
|
||||
SQRESULT mRes; // The result of the retrieval attempts.
|
||||
HSQOBJECT mObj; // Strong reference to the string object.
|
||||
HSQUIRRELVM mVM; // The associated virtual machine.
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
StackStrF(HSQUIRRELVM vm, SQInteger idx, bool fmt = true);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
StackStrF(const StackStrF & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
StackStrF(StackStrF && o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~StackStrF();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
StackStrF & operator = (const StackStrF & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
StackStrF & operator = (StackStrF && o) = delete;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Create a script object from the specified value on the default VM.
|
||||
*/
|
||||
template < typename T > Object MakeObject(const T & v)
|
||||
{
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Transform the specified value into a script object
|
||||
PushVar< T >(DefaultVM::Get(), v);
|
||||
// Get the object from the stack and return it
|
||||
return Var< Object >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Create a script object from the specified value on the specified VM.
|
||||
*/
|
||||
template < typename T > Object MakeObject(HSQUIRRELVM vm, const T & v)
|
||||
{
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Transform the specified value into a script object
|
||||
PushVar< T >(vm, v);
|
||||
// Get the object from the stack and return it
|
||||
return Var< Object >(vm, -1).value;
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _BASE_STACK_HPP_
|
@ -429,11 +429,11 @@ void Register_Vector2(HSQUIRRELVM vm)
|
||||
.Var(_SC("Y"), &Vector2::y)
|
||||
// Properties
|
||||
.Prop(_SC("Abs"), &Vector2::Abs)
|
||||
// Core Metamethods
|
||||
// Core Meta-methods
|
||||
.Func(_SC("_tostring"), &Vector2::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Vector2::Typename)
|
||||
.Func(_SC("_cmp"), &Vector2::Cmp)
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_add"), &Vector2::operator +)
|
||||
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_sub"), &Vector2::operator -)
|
||||
.Func< Vector2 (Vector2::*)(const Vector2 &) const >(_SC("_mul"), &Vector2::operator *)
|
||||
|
@ -555,11 +555,11 @@ void Register_Vector2i(HSQUIRRELVM vm)
|
||||
.Var(_SC("Y"), &Vector2i::y)
|
||||
// Properties
|
||||
.Prop(_SC("Abs"), &Vector2i::Abs)
|
||||
// Core Metamethods
|
||||
// Core Meta-methods
|
||||
.Func(_SC("_tostring"), &Vector2i::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Vector2i::Typename)
|
||||
.Func(_SC("_cmp"), &Vector2i::Cmp)
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("_add"), &Vector2i::operator +)
|
||||
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("_sub"), &Vector2i::operator -)
|
||||
.Func< Vector2i (Vector2i::*)(const Vector2i &) const >(_SC("_mul"), &Vector2i::operator *)
|
||||
|
@ -464,11 +464,11 @@ void Register_Vector3(HSQUIRRELVM vm)
|
||||
.Var(_SC("Z"), &Vector3::z)
|
||||
// Properties
|
||||
.Prop(_SC("Abs"), &Vector3::Abs)
|
||||
// Core Metamethods
|
||||
// Core Meta-methods
|
||||
.Func(_SC("_tostring"), &Vector3::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Vector3::Typename)
|
||||
.Func(_SC("_cmp"), &Vector3::Cmp)
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("_add"), &Vector3::operator +)
|
||||
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("_sub"), &Vector3::operator -)
|
||||
.Func< Vector3 (Vector3::*)(const Vector3 &) const >(_SC("_mul"), &Vector3::operator *)
|
||||
|
@ -513,11 +513,11 @@ void Register_Vector4(HSQUIRRELVM vm)
|
||||
.Var(_SC("w"), &Vector4::w)
|
||||
// Properties
|
||||
.Prop(_SC("Abs"), &Vector4::Abs)
|
||||
// Core Metamethods
|
||||
// Core Meta-methods
|
||||
.Func(_SC("_tostring"), &Vector4::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Vector4::Typename)
|
||||
.Func(_SC("_cmp"), &Vector4::Cmp)
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("_add"), &Vector4::operator +)
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("_sub"), &Vector4::operator -)
|
||||
.Func< Vector4 (Vector4::*)(const Vector4 &) const >(_SC("_mul"), &Vector4::operator *)
|
||||
|
@ -1,7 +1,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Command.hpp"
|
||||
#include "Core.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
#include "Entity/Player.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -1789,7 +1788,7 @@ void Register_Command(HSQUIRRELVM vm)
|
||||
Table cmdns(vm);
|
||||
|
||||
cmdns.Bind(_SC("Listener"), Class< CmdListener, NoConstructor< CmdListener > >(vm, _SC("SqCmdListener"))
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func(_SC("_cmp"), &CmdListener::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &CmdListener::Typename)
|
||||
.Func(_SC("_tostring"), &CmdListener::ToString)
|
||||
|
@ -368,7 +368,7 @@ bool Core::Reload()
|
||||
{
|
||||
return false; // Already reloading!
|
||||
}
|
||||
// Prevent circular reloads when we send plugin commands
|
||||
// Prevent circular reloads when we send plug-in commands
|
||||
const BitGuardU32 bg(m_CircularLocks, static_cast< Uint32 >(CCL_RELOAD_SCRIPTS));
|
||||
// Allow reloading by default
|
||||
Core::Get().SetState(1);
|
||||
|
@ -355,7 +355,7 @@ public:
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Int32 m_State; // Current plugin state.
|
||||
Int32 m_State; // Current plug-in state.
|
||||
HSQUIRRELVM m_VM; // Script virtual machine.
|
||||
Scripts m_Scripts; // Loaded scripts objects.
|
||||
Options m_Options; // Custom configuration options.
|
||||
|
@ -1,7 +1,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
#include "Base/Buffer.hpp"
|
||||
#include "Library/Utils/BufferWrapper.hpp"
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
@ -1,6 +1,5 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Entity/Blip.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
#include "Core.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -390,7 +389,7 @@ void Register_CBlip(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable(vm).Bind(_SC("SqBlip"),
|
||||
Class< CBlip, NoConstructor< CBlip > >(vm, _SC("SqBlip"))
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func(_SC("_cmp"), &CBlip::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &CBlip::Typename)
|
||||
.Func(_SC("_tostring"), &CBlip::ToString)
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include "Entity/Player.hpp"
|
||||
#include "Base/Color4.hpp"
|
||||
#include "Base/Vector3.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
#include "Core.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -564,7 +563,7 @@ void Register_CCheckpoint(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable(vm).Bind(_SC("SqCheckpoint"),
|
||||
Class< CCheckpoint, NoConstructor< CCheckpoint > >(vm, _SC("SqCheckpoint"))
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func(_SC("_cmp"), &CCheckpoint::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &CCheckpoint::Typename)
|
||||
.Func(_SC("_tostring"), &CCheckpoint::ToString)
|
||||
|
@ -1,6 +1,5 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Entity/Keybind.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
#include "Core.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -262,7 +261,7 @@ void Register_CKeybind(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable(vm).Bind(_SC("SqKeybind"),
|
||||
Class< CKeybind, NoConstructor< CKeybind > >(vm, _SC("SqKeybind"))
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func(_SC("_cmp"), &CKeybind::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &CKeybind::Typename)
|
||||
.Func(_SC("_tostring"), &CKeybind::ToString)
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include "Entity/Player.hpp"
|
||||
#include "Base/Quaternion.hpp"
|
||||
#include "Base/Vector3.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
#include "Core.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -888,7 +887,7 @@ void Register_CObject(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable(vm).Bind(_SC("SqObject"),
|
||||
Class< CObject, NoConstructor< CObject > >(vm, _SC("SqObject"))
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func(_SC("_cmp"), &CObject::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &CObject::Typename)
|
||||
.Func(_SC("_tostring"), &CObject::ToString)
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include "Entity/Pickup.hpp"
|
||||
#include "Entity/Player.hpp"
|
||||
#include "Base/Vector3.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
#include "Core.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -450,7 +449,7 @@ void Register_CPickup(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable(vm).Bind(_SC("SqPickup"),
|
||||
Class< CPickup, NoConstructor< CPickup > >(vm, _SC("SqPickup"))
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func(_SC("_cmp"), &CPickup::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &CPickup::Typename)
|
||||
.Func(_SC("_tostring"), &CPickup::ToString)
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include "Entity/Vehicle.hpp"
|
||||
#include "Base/Color3.hpp"
|
||||
#include "Base/Vector3.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
#include "Library/Utils/BufferWrapper.hpp"
|
||||
#include "Core.hpp"
|
||||
|
||||
@ -1997,7 +1996,7 @@ void Register_CPlayer(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable(vm).Bind(_SC("SqPlayer"),
|
||||
Class< CPlayer, NoConstructor< CPlayer > >(vm, _SC("SqPlayer"))
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func(_SC("_cmp"), &CPlayer::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &CPlayer::Typename)
|
||||
.Func(_SC("_tostring"), &CPlayer::ToString)
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "Base/Quaternion.hpp"
|
||||
#include "Base/Vector2.hpp"
|
||||
#include "Base/Vector3.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
#include "Core.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -1626,7 +1625,7 @@ void Register_CVehicle(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable(vm).Bind(_SC("SqVehicle"),
|
||||
Class< CVehicle, NoConstructor< CVehicle > >(vm, _SC("SqVehicle"))
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func(_SC("_cmp"), &CVehicle::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &CVehicle::Typename)
|
||||
.Func(_SC("_tostring"), &CVehicle::ToString)
|
||||
|
@ -279,6 +279,12 @@ void InitExports()
|
||||
g_SqExports.GetTimestamp = SqEx_GetTimestamp;
|
||||
g_SqExports.PushTimestamp = SqEx_PushTimestamp;
|
||||
|
||||
//stack utilities
|
||||
g_SqExports.PopStackInteger = PopStackInteger;
|
||||
g_SqExports.PopStackFloat = PopStackFloat;
|
||||
g_SqExports.PopStackSLong = PopStackSLong;
|
||||
g_SqExports.PopStackULong = PopStackULong;
|
||||
|
||||
// Export them to the server
|
||||
_Func->ExportFunctions(_Info->pluginId,
|
||||
const_cast< const void ** >(reinterpret_cast< void ** >(&sqexports)),
|
||||
|
@ -233,11 +233,11 @@ void Register_ChronoDate(HSQUIRRELVM vm, Table & /*cns*/)
|
||||
.Ctor< Uint16, Uint8, Uint8 >()
|
||||
// Static Properties
|
||||
.SetStaticValue(_SC("GlobalDelimiter"), &Date::Delimiter)
|
||||
// Core Metamethods
|
||||
// Core Meta-methods
|
||||
.Func(_SC("_tostring"), &Date::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Date::Typename)
|
||||
.Func(_SC("_cmp"), &Date::Cmp)
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func< Date (Date::*)(const Date &) const >(_SC("_add"), &Date::operator +)
|
||||
.Func< Date (Date::*)(const Date &) const >(_SC("_sub"), &Date::operator -)
|
||||
.Func< Date (Date::*)(const Date &) const >(_SC("_mul"), &Date::operator *)
|
||||
|
@ -342,11 +342,11 @@ void Register_ChronoTime(HSQUIRRELVM vm, Table & /*cns*/)
|
||||
.Ctor< Uint8, Uint8, Uint8, Uint16 >()
|
||||
// Static Properties
|
||||
.SetStaticValue(_SC("GlobalDelimiter"), &Time::Delimiter)
|
||||
// Core Metamethods
|
||||
// Core Meta-methods
|
||||
.Func(_SC("_tostring"), &Time::ToString)
|
||||
.SquirrelFunc(_SC("_typename"), &Time::Typename)
|
||||
.Func(_SC("_cmp"), &Time::Cmp)
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func< Time (Time::*)(const Time &) const >(_SC("_add"), &Time::operator +)
|
||||
.Func< Time (Time::*)(const Time &) const >(_SC("_sub"), &Time::operator -)
|
||||
.Func< Time (Time::*)(const Time &) const >(_SC("_mul"), &Time::operator *)
|
||||
|
@ -72,7 +72,7 @@ void Register_ChronoTimer(HSQUIRRELVM vm, Table & /*cns*/)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< const Timer & >()
|
||||
// Core Metamethods
|
||||
// Core Meta-methods
|
||||
.Func(_SC("_tostring"), &Timer::ToString)
|
||||
.Func(_SC("_cmp"), &Timer::Cmp)
|
||||
// Properties
|
||||
|
@ -123,10 +123,10 @@ void Register_ChronoTimestamp(HSQUIRRELVM vm, Table & /*cns*/)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< const Timestamp & >()
|
||||
// Core Metamethods
|
||||
// Core Meta-methods
|
||||
.Func(_SC("_tostring"), &Timestamp::ToString)
|
||||
.Func(_SC("_cmp"), &Timestamp::Cmp)
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func< Timestamp (Timestamp::*)(const Timestamp &) const >(_SC("_add"), &Timestamp::operator +)
|
||||
.Func< Timestamp (Timestamp::*)(const Timestamp &) const >(_SC("_sub"), &Timestamp::operator -)
|
||||
.Func< Timestamp (Timestamp::*)(const Timestamp &) const >(_SC("_mul"), &Timestamp::operator *)
|
||||
|
@ -1,7 +1,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Crypt.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cstdlib>
|
||||
|
@ -1,7 +1,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Crypt/AES.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cstdlib>
|
||||
@ -143,7 +142,7 @@ void Register_AES(HSQUIRRELVM vm)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< CSStr >()
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func(_SC("_cmp"), &AES256::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &AES256::Typename)
|
||||
.Func(_SC("_tostring"), &AES256::ToString)
|
||||
|
@ -1,7 +1,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Crypt/Hash.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <crc32.h>
|
||||
@ -56,7 +55,7 @@ template < class T > static void RegisterWrapper(Table & hashns, CCStr cname)
|
||||
hashns.Bind(cname, Class< Hash >(hashns.GetVM(), cname)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func(_SC("_tostring"), &Hash::ToString)
|
||||
// Properties
|
||||
.Prop(_SC("Hash"), &Hash::GetHash)
|
||||
|
@ -1,6 +1,5 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/IO/INI.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cerrno>
|
||||
@ -388,7 +387,7 @@ void Register_INI(HSQUIRRELVM vm)
|
||||
.Ctor()
|
||||
.Ctor< CSStr, SQInteger >()
|
||||
.Ctor< const IniResult & >()
|
||||
// Core Metamethods
|
||||
// Core Meta-methods
|
||||
.Func(_SC("_cmp"), &IniResult::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &IniResult::Typename)
|
||||
.Func(_SC("_tostring"), &IniResult::ToString)
|
||||
@ -404,7 +403,7 @@ void Register_INI(HSQUIRRELVM vm)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< const Entries & >()
|
||||
// Core Metamethods
|
||||
// Core Meta-methods
|
||||
.Func(_SC("_cmp"), &Entries::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &Entries::Typename)
|
||||
.Func(_SC("_tostring"), &Entries::ToString)
|
||||
@ -433,7 +432,7 @@ void Register_INI(HSQUIRRELVM vm)
|
||||
.Ctor< bool >()
|
||||
.Ctor< bool, bool >()
|
||||
.Ctor< bool, bool, bool >()
|
||||
// Core Metamethods
|
||||
// Core Meta-methods
|
||||
.Func(_SC("_cmp"), &Document::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &Document::Typename)
|
||||
.Func(_SC("_tostring"), &Document::ToString)
|
||||
|
@ -1,7 +1,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Math.hpp"
|
||||
#include "Library/Numeric.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cmath>
|
||||
@ -1075,7 +1074,7 @@ static SQInteger SqDigits1(HSQUIRRELVM vm)
|
||||
return sq_throwerror(vm, "Wrong number of arguments");
|
||||
}
|
||||
// Fetch the integer value from the stack
|
||||
Int64 n = std::llabs(PopStackLong(vm, 2));
|
||||
Int64 n = std::llabs(PopStackSLong(vm, 2));
|
||||
// Start with 0 digits
|
||||
Uint8 d = 0;
|
||||
// Identify the number of digits
|
||||
@ -1099,7 +1098,7 @@ static SQInteger SqDigits0(HSQUIRRELVM vm)
|
||||
return sq_throwerror(vm, "Wrong number of arguments");
|
||||
}
|
||||
// Fetch the integer value from the stack
|
||||
Int64 n = std::llabs(PopStackLong(vm, 2));
|
||||
Int64 n = std::llabs(PopStackSLong(vm, 2));
|
||||
// Start with 0 digits
|
||||
Uint8 d = 0;
|
||||
// Identify the number of digits
|
||||
|
@ -91,7 +91,7 @@ void Register_Numeric(HSQUIRRELVM vm)
|
||||
/* Properties */
|
||||
.Prop(_SC("Str"), &SLongInt::GetCStr, &SLongInt::SetStr)
|
||||
.Prop(_SC("Num"), &SLongInt::GetSNum, &SLongInt::SetNum)
|
||||
/* Core Metamethods */
|
||||
/* Core Meta-methods */
|
||||
.Func(_SC("_tostring"), &SLongInt::ToString)
|
||||
.Func(_SC("_typename"), &SLongInt::Typename)
|
||||
.Func(_SC("_cmp"), &SLongInt::Cmp)
|
||||
@ -101,7 +101,7 @@ void Register_Numeric(HSQUIRRELVM vm)
|
||||
.Func(_SC("tostring"), &SLongInt::ToSqString)
|
||||
.Func(_SC("tobool"), &SLongInt::ToSqBool)
|
||||
.Func(_SC("tochar"), &SLongInt::ToSqChar)
|
||||
/* Metamethods */
|
||||
/* Meta-methods */
|
||||
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_add"), &SLongInt::operator +)
|
||||
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_sub"), &SLongInt::operator -)
|
||||
.Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_mul"), &SLongInt::operator *)
|
||||
@ -127,7 +127,7 @@ void Register_Numeric(HSQUIRRELVM vm)
|
||||
/* Properties */
|
||||
.Prop(_SC("Str"), &ULongInt::GetCStr, &ULongInt::SetStr)
|
||||
.Prop(_SC("Num"), &ULongInt::GetSNum, &ULongInt::SetNum)
|
||||
/* Core Metamethods */
|
||||
/* Core Meta-methods */
|
||||
.Func(_SC("_tostring"), &ULongInt::ToString)
|
||||
.Func(_SC("_typename"), &ULongInt::Typename)
|
||||
.Func(_SC("_cmp"), &ULongInt::Cmp)
|
||||
@ -137,7 +137,7 @@ void Register_Numeric(HSQUIRRELVM vm)
|
||||
.Func(_SC("tostring"), &ULongInt::ToSqString)
|
||||
.Func(_SC("tobool"), &ULongInt::ToSqBool)
|
||||
.Func(_SC("tochar"), &ULongInt::ToSqChar)
|
||||
/* Metamethods */
|
||||
/* Meta-methods */
|
||||
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_add"), &ULongInt::operator +)
|
||||
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_sub"), &ULongInt::operator -)
|
||||
.Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_mul"), &ULongInt::operator *)
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include "Library/String.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Buffer.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cctype>
|
||||
|
@ -1,7 +1,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/System.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
#include "Base/Buffer.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -1,6 +1,5 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/System/Environment.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cctype>
|
||||
|
@ -1,7 +1,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/System/Path.hpp"
|
||||
#include "Library/System/Environment.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cctype>
|
||||
@ -1675,7 +1674,7 @@ void Register_SysPath(HSQUIRRELVM vm)
|
||||
.Ctor()
|
||||
.Ctor< CSStr >()
|
||||
.Ctor< CSStr, Int32 >()
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func(_SC("_cmp"), &SysPath::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &SysPath::Typename)
|
||||
.Func(_SC("_tostring"), &SysPath::ToString)
|
||||
|
@ -1,7 +1,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Utils/BufferWrapper.hpp"
|
||||
#include "Library/Utils/BufferInterpreter.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cstring>
|
||||
|
@ -1,6 +1,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Logger.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
#include "Base/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <ctime>
|
||||
@ -151,56 +151,6 @@ static inline void OutputConsoleMessage(Uint8 level, bool sub, CCStr tms, CCStr
|
||||
#endif // SQMOD_OS_WINDOWS
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Raw console message output.
|
||||
*/
|
||||
static inline void OutputMessageImpl(CCStr msg, va_list args)
|
||||
{
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
CONSOLE_SCREEN_BUFFER_INFO csb_before;
|
||||
GetConsoleScreenBufferInfo( hstdout, &csb_before);
|
||||
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN);
|
||||
std::printf("[SQMOD] ");
|
||||
|
||||
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
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
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Raw console error output.
|
||||
*/
|
||||
static inline void OutputErrorImpl(CCStr msg, va_list args)
|
||||
{
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
CONSOLE_SCREEN_BUFFER_INFO csb_before;
|
||||
GetConsoleScreenBufferInfo( hstdout, &csb_before);
|
||||
SetConsoleTextAttribute(hstdout, FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
std::printf("[SQMOD] ");
|
||||
|
||||
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
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
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Identify the associated message color.
|
||||
*/
|
||||
@ -557,46 +507,6 @@ SQMOD_CLOG(cLogSWrn, LOGL_WRN, true)
|
||||
SQMOD_CLOG(cLogSErr, LOGL_ERR, true)
|
||||
SQMOD_CLOG(cLogSFtl, LOGL_FTL, true)
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void OutputDebug(CCStr msg, ...)
|
||||
{
|
||||
#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
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void OutputMessage(CCStr msg, ...)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void OutputError(CCStr msg, ...)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template < Uint8 L, bool S > static SQInteger LogBasicMessage(HSQUIRRELVM vm)
|
||||
{
|
||||
|
@ -109,7 +109,7 @@ static uint8_t OnServerInitialise(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
LogFtl("Unable to load the plugin resources properly");
|
||||
LogFtl("Unable to load the plug-in resources properly");
|
||||
// Failed to initialize
|
||||
return SQMOD_FAILURE;
|
||||
}
|
||||
@ -118,7 +118,7 @@ static uint8_t OnServerInitialise(void)
|
||||
// See if a reload was requested
|
||||
SQMOD_RELOAD_CHECK(false)
|
||||
// Return the last known plug-in state
|
||||
return Core::Get().GetState();
|
||||
return ConvTo< Uint8 >::From(Core::Get().GetState());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -169,7 +169,7 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
|
||||
// See if a reload was requested
|
||||
SQMOD_RELOAD_CHECK(g_Reload)
|
||||
// Return the last known plug-in state
|
||||
return Core::Get().GetState();
|
||||
return ConvTo< Uint8 >::From(Core::Get().GetState());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -187,7 +187,7 @@ static uint8_t OnIncomingConnection(CStr player_name, size_t name_buffer_size,
|
||||
// See if a reload was requested
|
||||
SQMOD_RELOAD_CHECK(g_Reload)
|
||||
// Return the last known plug-in state
|
||||
return Core::Get().GetState();
|
||||
return ConvTo< Uint8 >::From(Core::Get().GetState());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -243,7 +243,7 @@ static uint8_t OnPlayerRequestClass(int32_t player_id, int32_t offset)
|
||||
// See if a reload was requested
|
||||
SQMOD_RELOAD_CHECK(g_Reload)
|
||||
// Return the last known plug-in state
|
||||
return Core::Get().GetState();
|
||||
return ConvTo< Uint8 >::From(Core::Get().GetState());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -260,7 +260,7 @@ static uint8_t OnPlayerRequestSpawn(int32_t player_id)
|
||||
// See if a reload was requested
|
||||
SQMOD_RELOAD_CHECK(g_Reload)
|
||||
// Return the last known plug-in state
|
||||
return Core::Get().GetState();
|
||||
return ConvTo< Uint8 >::From(Core::Get().GetState());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -325,7 +325,7 @@ static uint8_t OnPlayerRequestEnterVehicle(int32_t player_id, int32_t vehicle_id
|
||||
// See if a reload was requested
|
||||
SQMOD_RELOAD_CHECK(g_Reload)
|
||||
// Return the last known plug-in state
|
||||
return Core::Get().GetState();
|
||||
return ConvTo< Uint8 >::From(Core::Get().GetState());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -560,7 +560,7 @@ static uint8_t OnPlayerMessage(int32_t player_id, CCStr message)
|
||||
// See if a reload was requested
|
||||
SQMOD_RELOAD_CHECK(g_Reload)
|
||||
// Return the last known plug-in state
|
||||
return Core::Get().GetState();
|
||||
return ConvTo< Uint8 >::From(Core::Get().GetState());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -577,7 +577,7 @@ static uint8_t OnPlayerCommand(int32_t player_id, CCStr message)
|
||||
// See if a reload was requested
|
||||
SQMOD_RELOAD_CHECK(g_Reload)
|
||||
// Return the last known plug-in state
|
||||
return Core::Get().GetState();
|
||||
return ConvTo< Uint8 >::From(Core::Get().GetState());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -594,7 +594,7 @@ static uint8_t OnPlayerPrivateMessage(int32_t player_id, int32_t target_player_i
|
||||
// See if a reload was requested
|
||||
SQMOD_RELOAD_CHECK(g_Reload)
|
||||
// Return the last known plug-in state
|
||||
return Core::Get().GetState();
|
||||
return ConvTo< Uint8 >::From(Core::Get().GetState());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -728,7 +728,7 @@ static uint8_t OnPickupPickAttempt(int32_t pickup_id, int32_t player_id)
|
||||
// See if a reload was requested
|
||||
SQMOD_RELOAD_CHECK(false)
|
||||
// Return the last known plug-in state
|
||||
return Core::Get().GetState();
|
||||
return ConvTo< Uint8 >::From(Core::Get().GetState());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -908,10 +908,10 @@ void UnbindCallbacks()
|
||||
SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * funcs, PluginCallbacks * calls, PluginInfo * info)
|
||||
{
|
||||
using namespace SqMod;
|
||||
// Output plugin header
|
||||
// Output plug-in header
|
||||
puts("");
|
||||
OutputMessage("--------------------------------------------------------------------");
|
||||
OutputMessage("Plugin: %s", SQMOD_NAME);
|
||||
OutputMessage("Plug-in: %s", SQMOD_NAME);
|
||||
OutputMessage("Author: %s", SQMOD_AUTHOR);
|
||||
OutputMessage("Legal: %s", SQMOD_COPYRIGHT);
|
||||
OutputMessage("--------------------------------------------------------------------");
|
||||
@ -920,15 +920,15 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * funcs, PluginCallback
|
||||
_Func = funcs;
|
||||
_Clbk = calls;
|
||||
_Info = info;
|
||||
// Assign plugin version
|
||||
// Assign plug-in version
|
||||
_Info->pluginVersion = SQMOD_VERSION;
|
||||
_Info->apiMajorVersion = PLUGIN_API_MAJOR;
|
||||
_Info->apiMinorVersion = PLUGIN_API_MINOR;
|
||||
// Assign the plugin name
|
||||
// Assign the plug-in name
|
||||
std::snprintf(_Info->name, sizeof(_Info->name), "%s", SQMOD_HOST_NAME);
|
||||
// Attempt to initialize the logger before anything else
|
||||
Logger::Get().Initialize(nullptr);
|
||||
// Attempt to initialize the plugin core
|
||||
// Attempt to initialize the plug-in core
|
||||
if (!Core::Get().Initialize())
|
||||
{
|
||||
LogFtl("Unable to initialize the plug-in central core");
|
||||
@ -939,7 +939,7 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * funcs, PluginCallback
|
||||
}
|
||||
// Bind to server callbacks
|
||||
BindCallbacks();
|
||||
// Attempt to initialize the plugin exports
|
||||
// Attempt to initialize the plug-in exports
|
||||
InitExports();
|
||||
// Dummy spacing
|
||||
puts("");
|
||||
|
@ -1,7 +1,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Misc/Functions.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
#include "Base/Color3.hpp"
|
||||
#include "Base/Vector2.hpp"
|
||||
#include "Base/Vector3.hpp"
|
||||
|
@ -1,6 +1,5 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Routine.hpp"
|
||||
#include "Base/Stack.hpp"
|
||||
#include "Library/Chrono.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -998,7 +997,7 @@ void Register_Routine(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable(vm).Bind(_SC("SqRoutine"),
|
||||
Class< Routine, NoConstructor< Routine > >(vm, _SC("SqRoutine"))
|
||||
// Metamethods
|
||||
// Meta-methods
|
||||
.Func(_SC("_cmp"), &Routine::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &Routine::Typename)
|
||||
.Func(_SC("_tostring"), &Routine::ToString)
|
||||
|
Loading…
Reference in New Issue
Block a user