1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-11-04 00:07:19 +01:00

Move shared code into main source.

Remove extra module API.
This commit is contained in:
Sandu Liviu Catalin
2020-03-21 22:16:48 +02:00
parent 22c8d84b1e
commit 9978dbe88c
10 changed files with 2 additions and 1314 deletions

View File

@@ -1,612 +0,0 @@
// ------------------------------------------------------------------------------------------------
#include "Base/Buffer.hpp"
#include "sqrat/sqratUtil.h"
// ------------------------------------------------------------------------------------------------
#include <cstdlib>
#include <cstring>
#include <exception>
#include <stdexcept>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Compute the next power of two for the specified number.
*/
inline unsigned int NextPow2(unsigned int num)
{
--num;
num |= num >> 1;
num |= num >> 2;
num |= num >> 4;
num |= num >> 8;
num |= num >> 16;
return ++num;
}
/* ------------------------------------------------------------------------------------------------
* Throw an memory exception.
*/
void ThrowMemExcept(const char * msg, ...)
{
// Exception messages should be concise
SQChar buffer[256];
// Variable arguments structure
va_list args;
// Get the specified arguments
va_start(args, msg);
// Run the specified format
int ret = std::vsnprintf(buffer, sizeof(buffer), msg, args);
// Check for formatting errors
if (ret < 0)
{
throw Sqrat::Exception(_SC("Unknown memory error"));
}
// Throw the actual exception
throw Sqrat::Exception(buffer);
}
/* ------------------------------------------------------------------------------------------------
* Allocate a memory buffer and return it.
*/
static Buffer::Pointer AllocMem(Buffer::SzType size)
{
// Attempt to allocate memory directly
Buffer::Pointer ptr = reinterpret_cast< Buffer::Pointer >(std::malloc(size));
// Validate the allocated memory
if (!ptr)
{
ThrowMemExcept("Unable to allocate (%u) bytes of memory", size);
}
// Return the allocated memory
return ptr;
}
/* ------------------------------------------------------------------------------------------------
* ...
*/
class MemCat
{
// --------------------------------------------------------------------------------------------
friend class Memory;
friend class Buffer;
public:
// --------------------------------------------------------------------------------------------
typedef Buffer::Value Value; // The type of value used to represent a byte.
// --------------------------------------------------------------------------------------------
typedef Buffer::Reference Reference; // A reference to the stored value type.
typedef Buffer::ConstRef ConstRef; // A const reference to the stored value type.
// --------------------------------------------------------------------------------------------
typedef Buffer::Pointer Pointer; // A pointer to the stored value type.
typedef Buffer::ConstPtr ConstPtr; // A const pointer to the stored value type.
// --------------------------------------------------------------------------------------------
typedef Buffer::SzType SzType; // The type used to represent size in general.
private:
/* --------------------------------------------------------------------------------------------
* Structure used to store a memory chunk in the linked list.
*/
struct Node
{
// ----------------------------------------------------------------------------------------
SzType mCap; // The size of the memory chunk.
Pointer mPtr; // Pointer to the memory chunk.
Node* mNext; // The next node in the list.
/* ----------------------------------------------------------------------------------------
* Base constructor.
*/
Node(Node * next)
: mCap(0)
, mPtr(nullptr)
, mNext(next)
{
/* ... */
}
};
// --------------------------------------------------------------------------------------------
static Node * s_Nodes; /* List of unused node instances. */
// --------------------------------------------------------------------------------------------
Node* m_Head; /* The head memory node. */
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
MemCat()
: m_Head(nullptr)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~MemCat()
{
for (Node * node = m_Head, * next = nullptr; node; node = next)
{
// Free the memory (if any)
if (node->mPtr)
{
std::free(node->mPtr);
}
// Save the next node
next = node->mNext;
// Release the node instance
delete node;
}
// Explicitly set the head node to null
m_Head = nullptr;
}
/* --------------------------------------------------------------------------------------------
* Clear all memory buffers from the pool.
*/
void Clear()
{
for (Node * node = m_Head, * next = nullptr; node; node = next)
{
// Free the memory (if any)
if (node->mPtr)
{
free(node->mPtr);
}
// Save the next node
next = node->mNext;
// Release the node instance
Push(node);
}
// Explicitly set the head node to null
m_Head = nullptr;
}
/* --------------------------------------------------------------------------------------------
* Grab a memory buffer from the pool.
*/
void Grab(Pointer & ptr, SzType & size)
{
// NOTE: Function assumes (size > 0)
// Find a buffer large enough to satisfy the requested size
for (Node * node = m_Head, * prev = nullptr; node; prev = node, node = node->mNext)
{
// Is this buffer large enough?
if (node->mCap >= size)
{
// Was there a previous node?
if (prev)
{
prev->mNext = node->mNext;
}
// Probably this was the head
else
{
m_Head = node->mNext;
}
// Assign the memory
ptr = node->mPtr;
// Assign the size
size = node->mCap;
// Release the node instance
Push(node);
// Exit the function
return;
}
}
// Round up the size to a power of two number
size = (size & (size - 1)) ? NextPow2(size) : size;
// Allocate the memory directly
ptr = AllocMem(size);
// See if the memory could be allocated
// (shouldn't reach this point if allocation failed)
if (!ptr)
{
// Revert the size
size = 0;
// Throw the exception
ThrowMemExcept("Unable to allocate (%u) bytes of memory", size);
}
}
/* --------------------------------------------------------------------------------------------
* Return a memory buffer to the pool.
*/
void Drop(Pointer & ptr, SzType & size)
{
if (!ptr)
{
ThrowMemExcept("Cannot store invalid memory buffer");
}
// Request a node instance
Node * node = Pull();
// Assign the specified memory
node->mPtr = ptr;
// Assign the specified size
node->mCap = size;
// Demote the current head node
node->mNext = m_Head;
// Promote as the head node
m_Head = node;
}
/* --------------------------------------------------------------------------------------------
* Allocate a group of nodes and pool them for later use.
*/
static void Make()
{
for (SzType n = 16; n; --n)
{
// Create a new node instance
s_Nodes = new Node(s_Nodes);
// Validate the head node
if (!s_Nodes)
{
ThrowMemExcept("Unable to allocate memory nodes");
}
}
}
/* --------------------------------------------------------------------------------------------
* Retrieve an unused node from the free list.
*/
static Node * Pull()
{
// Are there any nodes available?
if (!s_Nodes)
{
Make(); // Make some!
}
// Grab the head node
Node * node = s_Nodes;
// Promote the next node as the head
s_Nodes = node->mNext;
// Return the node
return node;
}
/* --------------------------------------------------------------------------------------------
* Return a node to the free list.
*/
static void Push(Node * node)
{
// See if the node is even valid
if (!node)
{
ThrowMemExcept("Attempting to push invalid node");
}
// Demote the current head node
node->mNext = s_Nodes;
// Promote as the head node
s_Nodes = node;
}
};
// ------------------------------------------------------------------------------------------------
MemCat::Node * MemCat::s_Nodes = nullptr;
/* ------------------------------------------------------------------------------------------------
* Lightweight memory allocator to reduce the overhead of small allocations.
*/
class Memory
{
// --------------------------------------------------------------------------------------------
friend class Buffer; // Allow the buffer type to access the memory categories.
friend class MemRef; // Allow the memory manager reference to create new instances.
private:
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Memory()
: m_Small()
, m_Medium()
, m_Large()
{
// Allocate several nodes for when memory starts pooling
MemCat::Make();
}
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~Memory()
{
for (MemCat::Node * node = MemCat::s_Nodes, * next = nullptr; node; node = next)
{
// Save the next node
next = node->mNext;
// Release the node instance
delete node;
}
// Explicitly set the head node to null
MemCat::s_Nodes = nullptr;
}
private:
// --------------------------------------------------------------------------------------------
MemCat m_Small; // Small memory allocations of <= 1024 bytes.
MemCat m_Medium; // Medium memory allocations of <= 4096 bytes.
MemCat m_Large; // Large memory allocations of <= 4096 bytes.
};
// ------------------------------------------------------------------------------------------------
MemRef MemRef::s_Mem;
// ------------------------------------------------------------------------------------------------
void MemRef::Grab()
{
if (m_Ptr)
{
++(*m_Ref);
}
}
// ------------------------------------------------------------------------------------------------
void MemRef::Drop()
{
if (m_Ptr && --(*m_Ref) == 0)
{
delete m_Ptr;
delete m_Ref;
m_Ptr = nullptr;
m_Ref = nullptr;
}
}
// ------------------------------------------------------------------------------------------------
const MemRef & MemRef::Get()
{
if (!s_Mem.m_Ptr)
{
s_Mem.m_Ptr = new Memory();
s_Mem.m_Ref = new Counter(1);
}
return s_Mem;
}
// ------------------------------------------------------------------------------------------------
Buffer::Buffer(const Buffer & o)
: m_Ptr(nullptr)
, m_Cap(o.m_Cap)
, m_Cur(o.m_Cur)
, m_Mem(o.m_Mem)
{
if (m_Cap)
{
Request(o.m_Cap);
std::memcpy(m_Ptr, o.m_Ptr, o.m_Cap);
}
}
// ------------------------------------------------------------------------------------------------
Buffer::~Buffer()
{
// Do we have a buffer?
if (m_Ptr)
{
Release(); // Release it!
}
}
// ------------------------------------------------------------------------------------------------
Buffer & Buffer::operator = (const Buffer & o)
{
if (m_Ptr != o.m_Ptr)
{
// Can we work in the current buffer?
if (m_Cap && o.m_Cap <= m_Cap)
{
// It's safe to copy the data
std::memcpy(m_Ptr, o.m_Ptr, o.m_Cap);
}
// Do we even have data to copy?
else if (!o.m_Cap)
{
// Do we have a buffer?
if (m_Ptr)
{
Release(); // Release it!
}
}
else
{
// Do we have a buffer?
if (m_Ptr)
{
Release(); // Release it!
}
// Request a larger buffer
Request(o.m_Cap);
// Now it's safe to copy the data
std::memcpy(m_Ptr, o.m_Ptr, o.m_Cap);
}
// Also copy the edit cursor
m_Cur = o.m_Cur;
}
return *this;
}
// ------------------------------------------------------------------------------------------------
void Buffer::Grow(SzType n)
{
// Backup the current memory
Buffer bkp(m_Ptr, m_Cap, m_Cur, m_Mem);
// Acquire a bigger buffer
Request(bkp.m_Cap + n);
// Copy the data from the old buffer
std::memcpy(m_Ptr, bkp.m_Ptr, bkp.m_Cap);
// Copy the previous edit cursor
m_Cur = bkp.m_Cur;
}
// ------------------------------------------------------------------------------------------------
void Buffer::Request(SzType n)
{
// NOTE: Function assumes (n > 0)
// Is there a memory manager available?
if (!m_Mem)
{
// Round up the size to a power of two number
n = (n & (n - 1)) ? NextPow2(n) : n;
// Allocate the memory directly
m_Ptr = AllocMem(n);
}
// Find out in which category does this buffer reside
else if (n <= 1024)
{
m_Mem->m_Small.Grab(m_Ptr, n);
}
else if (n <= 4096)
{
m_Mem->m_Medium.Grab(m_Ptr, n);
}
else
{
m_Mem->m_Large.Grab(m_Ptr, n);
}
// If no errors occurred then we can set the size
m_Cap = n;
}
// ------------------------------------------------------------------------------------------------
void Buffer::Release()
{
// TODO: Implement a limit on how much memory can actually be pooled.
// Is there a memory manager available?
if (!m_Mem)
{
std::free(m_Ptr); // Deallocate the memory directly
}
// Find out to which category does this buffer belong
else if (m_Cap <= 1024)
{
m_Mem->m_Small.Drop(m_Ptr, m_Cap);
}
else if (m_Cap <= 4096)
{
m_Mem->m_Medium.Drop(m_Ptr, m_Cap);
}
else
{
m_Mem->m_Large.Drop(m_Ptr, m_Cap);
}
// Explicitly reset the buffer
m_Ptr = nullptr;
m_Cap = 0;
m_Cur = 0;
}
// ------------------------------------------------------------------------------------------------
Buffer::SzType Buffer::Write(SzType pos, ConstPtr data, SzType size)
{
// Do we have what to write?
if (!data || !size)
{
return 0;
}
// See if the buffer size must be adjusted
else if ((pos + size) >= m_Cap)
{
// Acquire a larger buffer
Grow((pos + size) - m_Cap + 32);
}
// Copy the data into the internal buffer
std::memcpy(m_Ptr + pos, data, size);
// Return the amount of data written to the buffer
return size;
}
// ------------------------------------------------------------------------------------------------
Buffer::SzType Buffer::WriteF(SzType pos, const char * fmt, ...)
{
// Initialize the variable argument list
va_list args;
va_start(args, fmt);
// Call the function that takes the variable argument list
const SzType ret = WriteF(pos, fmt, args);
// Finalize the variable argument list
va_end(args);
// Return the result
return ret;
}
// ------------------------------------------------------------------------------------------------
Buffer::SzType Buffer::WriteF(SzType pos, const char * fmt, va_list args)
{
// Is the specified position within range?
if (pos >= m_Cap)
{
// Acquire a larger buffer
Grow(pos - m_Cap + 32);
}
// Backup the variable argument list
va_list args_cpy;
va_copy(args_cpy, args);
// Attempt to write to the current buffer
// (if empty, it should tell us the necessary size)
int ret = std::vsnprintf(m_Ptr + pos, m_Cap, fmt, args);
// Do we need a bigger buffer?
if ((pos + ret) >= m_Cap)
{
// Acquire a larger buffer
Grow((pos + ret) - m_Cap + 32);
// Retry writing the requested information
ret = std::vsnprintf(m_Ptr + pos, m_Cap, fmt, args_cpy);
}
// Return the value 0 if data could not be written
if (ret < 0)
{
return 0;
}
// Return the number of written characters
return static_cast< SzType >(ret);
}
// ------------------------------------------------------------------------------------------------
Buffer::SzType Buffer::WriteS(SzType pos, ConstPtr str)
{
// Is there any string to write?
if (str && *str != '\0')
{
// Forward this to the regular write function
return Write(pos, str, std::strlen(str));
}
// Nothing to write
return 0;
}
// ------------------------------------------------------------------------------------------------
void Buffer::AppendF(const char * fmt, ...)
{
// Initialize the variable argument list
va_list args;
va_start(args, fmt);
// Forward this to the regular write function
m_Cur += WriteF(m_Cur, fmt, args);
// Finalize the variable argument list
va_end(args);
}
// ------------------------------------------------------------------------------------------------
void Buffer::AppendS(const char * str)
{
// Is there any string to write?
if (str)
{
m_Cur += Write(m_Cur, str, std::strlen(str));
}
}
} // Namespace:: SqMod

File diff suppressed because it is too large Load Diff

View File

@@ -1,809 +0,0 @@
#ifndef _BASE_DYNARG_HPP_
#define _BASE_DYNARG_HPP_
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Helper class used to check if a certain operation is possible on the specified argument.
*/
template < typename U > struct SqDynArg
{
static inline bool CanPop(HSQUIRRELVM vm)
{
return (sq_gettype(vm, 2) == OT_INSTANCE);
}
template < typename F > static inline auto Do(F & fn, HSQUIRRELVM vm)
{
Var< U * > var(vm, 2);
// Validate the obtained instance
if (!var.value)
{
STHROWF("No such instance");
}
// Attempt to perform the requested operation
return fn(*var.value);
}
template < typename F > static inline auto Do(const F & fn, HSQUIRRELVM vm)
{
Var< U * > var(vm, 2);
// Validate the obtained instance
if (!var.value)
{
STHROWF("No such instance");
}
// Attempt to perform the requested operation
return fn(*var.value);
}
};
/* ------------------------------------------------------------------------------------------------
* Instance pointer specializations of the argument checking structure.
*/
template < typename U > struct SqDynArg< U * >
{
static inline bool CanPop(HSQUIRRELVM vm)
{
return (sq_gettype(vm, 2) == OT_INSTANCE);
}
template < typename F > static inline auto Do(F & fn, HSQUIRRELVM vm)
{
Var< U * > var(vm, 2);
// Validate the obtained instance
if (!var.value)
{
STHROWF("No such instance");
}
// Attempt to perform the requested operation
return fn(var.value);
}
template < typename F > static inline auto Do(const F & fn, HSQUIRRELVM vm)
{
Var< U * > var(vm, 2);
// Validate the obtained instance
if (!var.value)
{
STHROWF("No such instance");
}
// Attempt to perform the requested operation
return fn(var.value);
}
};
/* ------------------------------------------------------------------------------------------------
* Instance pointer specializations of the argument checking structure.
*/
template < typename U > struct SqDynArg< const U * >
{
static inline bool CanPop(HSQUIRRELVM vm)
{
return (sq_gettype(vm, 2) == OT_INSTANCE);
}
template < typename F > static inline auto Do(F & fn, HSQUIRRELVM vm)
{
Var< U * > var(vm, 2);
// Validate the obtained instance
if (!var.value)
{
STHROWF("No such instance");
}
// Attempt to perform the requested operation
return fn(*var.value);
}
template < typename F > static inline auto Do(const F & fn, HSQUIRRELVM vm)
{
Var< U * > var(vm, 2);
// Validate the obtained instance
if (!var.value)
{
STHROWF("No such instance");
}
// Attempt to perform the requested operation
return fn(*var.value);
}
};
/* ------------------------------------------------------------------------------------------------
* Inherited by the base specializations of the argument checking structure.
*/
template < typename U, SQObjectType SqT > struct SqDynArgBase
{
static inline bool CanPop(HSQUIRRELVM vm)
{
return (sq_gettype(vm, 2) == SqT);
}
template < typename F > static inline auto Do(F & fn, HSQUIRRELVM vm)
{
Var< U > var(vm, 2);
// Attempt to perform the requested operation
return fn(var.value);
}
template < typename F > static inline auto Do(const F & fn, HSQUIRRELVM vm)
{
Var< U > var(vm, 2);
// Attempt to perform the requested operation
return fn(var.value);
}
};
// ------------------------------------------------------------------------------------------------
template < > struct SqDynArg< char >
: public SqDynArgBase< char, OT_INTEGER >
{ /* ... */ };
// ------------------------------------------------------------------------------------------------
template < > struct SqDynArg< signed char >
: public SqDynArgBase< signed char, OT_INTEGER >
{ /* ... */ };
// ------------------------------------------------------------------------------------------------
template < > struct SqDynArg< unsigned char >
: public SqDynArgBase< unsigned char, OT_INTEGER >
{ /* ... */ };
// ------------------------------------------------------------------------------------------------
template < > struct SqDynArg< signed short >
: public SqDynArgBase< signed short, OT_INTEGER >
{ /* ... */ };
// ------------------------------------------------------------------------------------------------
template < > struct SqDynArg< unsigned short >
: public SqDynArgBase< unsigned short, OT_INTEGER >
{ /* ... */ };
// ------------------------------------------------------------------------------------------------
template < > struct SqDynArg< signed int >
: public SqDynArgBase< signed int, OT_INTEGER >
{ /* ... */ };
// ------------------------------------------------------------------------------------------------
template < > struct SqDynArg< unsigned int >
: public SqDynArgBase< unsigned int, OT_INTEGER >
{ /* ... */ };
// ------------------------------------------------------------------------------------------------
template < > struct SqDynArg< signed long >
: public SqDynArgBase< signed long, OT_INTEGER >
{ /* ... */ };
// ------------------------------------------------------------------------------------------------
template < > struct SqDynArg< unsigned long >
: public SqDynArgBase< unsigned long, OT_INTEGER >
{ /* ... */ };
// ------------------------------------------------------------------------------------------------
template < > struct SqDynArg< signed long long >
: public SqDynArgBase< signed long long, OT_INTEGER >
{ /* ... */ };
// ------------------------------------------------------------------------------------------------
template < > struct SqDynArg< unsigned long long >
: public SqDynArgBase< unsigned long long, OT_INTEGER >
{ /* ... */ };
// ------------------------------------------------------------------------------------------------
template < > struct SqDynArg< float >
: public SqDynArgBase< float, OT_FLOAT >
{ /* ... */ };
// ------------------------------------------------------------------------------------------------
template < > struct SqDynArg< double >
: public SqDynArgBase< double, OT_FLOAT >
{ /* ... */ };
// ------------------------------------------------------------------------------------------------
template < > struct SqDynArg< bool >
: public SqDynArgBase< bool, OT_BOOL >
{ /* ... */ };
// ------------------------------------------------------------------------------------------------
template < > struct SqDynArg< SQChar * >
: public SqDynArgBase< SQChar *, OT_STRING >
{ /* ... */ };
// ------------------------------------------------------------------------------------------------
template < > struct SqDynArg< const SQChar * >
: public SqDynArgBase< const SQChar *, OT_STRING >
{ /* ... */ };
// ------------------------------------------------------------------------------------------------
template < > struct SqDynArg< String >
: public SqDynArgBase< String, OT_STRING >
{ /* ... */ };
// ------------------------------------------------------------------------------------------------
template < > struct SqDynArg< Table >
: public SqDynArgBase< Table, OT_TABLE >
{ /* ... */ };
// ------------------------------------------------------------------------------------------------
template < > struct SqDynArg< Array >
: public SqDynArgBase< Array, OT_ARRAY >
{ /* ... */ };
/* ------------------------------------------------------------------------------------------------
* Specialization of the argument checking structure for functions.
*/
template < > struct SqDynArg< Function >
{
static inline bool CanPop(HSQUIRRELVM vm)
{
const SQObjectType type = sq_gettype(vm, 2);
return (type == OT_CLOSURE || type == OT_NATIVECLOSURE);
}
template < typename F > static inline auto Do(F & fn, HSQUIRRELVM vm)
{
Var< Function > var(vm, 2);
// Attempt to perform the requested operation
return fn(var.value);
}
template < typename F > static inline auto Do(const F & fn, HSQUIRRELVM vm)
{
Var< Function > var(vm, 2);
// Attempt to perform the requested operation
return fn(var.value);
}
};
/* ------------------------------------------------------------------------------------------------
* Specialization of the argument checking structure for objects.
*/
template < > struct SqDynArg< Object >
{
static inline bool CanPop(HSQUIRRELVM /*vm*/)
{
return true; // Objects can use any type.
}
template < typename F > static inline auto Do(F & fn, HSQUIRRELVM vm)
{
Var< Object > var(vm, 2);
// Attempt to perform the requested operation
return fn(var.value);
}
template < typename F > static inline auto Do(const F & fn, HSQUIRRELVM vm)
{
Var< Object > var(vm, 2);
// Attempt to perform the requested operation
return fn(var.value);
}
};
/* ------------------------------------------------------------------------------------------------
* Specialization of the argument checking structure for null.
*/
template < > struct SqDynArg< std::nullptr_t >
{
static inline bool CanPop(HSQUIRRELVM vm)
{
return (sq_gettype(vm, 2) == OT_NULL);
}
template < typename F > static inline auto Do(F & fn, HSQUIRRELVM /*vm*/)
{
// Attempt to perform the requested operation
return fn(nullptr);
}
template < typename F > static inline auto Do(const F & fn, HSQUIRRELVM /*vm*/)
{
// Attempt to perform the requested operation
return fn(nullptr);
}
};
/* ------------------------------------------------------------------------------------------------
* Used to perform an operation on multiple types specified at compile time.
*/
template < typename... Ts > struct SqDynArgImpl;
/* ------------------------------------------------------------------------------------------------
* Zeroth case of the operation. No known operation of such pairs of types at this point.
*/
template < > struct SqDynArgImpl< >
{
template < typename T > static Int32 Try(const T & /*val*/, HSQUIRRELVM vm)
{
const String tn1(SqTypeName(vm, 1));
const String tn2(SqTypeName(vm, 2));
return sq_throwerror(vm, ToStrF("Such operation is not possible between (%s) and (%s)",
tn1.c_str(), tn2.c_str()));
}
};
/* ------------------------------------------------------------------------------------------------
* Argument pack type pealing. Attempt to perform the operation with a specified type.
*/
template < typename U, typename... Ts > struct SqDynArgImpl< U, Ts... >
{
template < typename F > static Int32 Try(F & fn, HSQUIRRELVM vm)
{
typedef typename std::decay< U >::type ArgType;
// Can the stack value be used with the current type?
if (SqDynArg< ArgType >::CanPop(vm))
{
// If not an instance then don't use a try catch block
if (sq_gettype(vm, 2) != OT_INSTANCE)
{
// Attempt to perform the operation and push the result on the stack
PushVar(vm, SqDynArg< ArgType >::Do(fn, vm));
// Specify that we completed the search and have a result
return 1;
}
// Instances require a try/catch block since we can't differentiate types
try
{
// Attempt to perform the operation and push the result on the stack
PushVar(vm, SqDynArg< ArgType >::Do(fn, vm));
// Specify that we completed the search and have a result
return 1;
}
catch (const Sqrat::Exception & e)
{
// Probably the wrong type
}
catch (...)
{
// Something very bad happened. At this point, we just don't want to let
// exceptions propagate to the virtual machine and we must end here.
// Either way, reaching this point is bad and we just shuved it under
// the rug. This is bad practice but circumstances forced me.
// Don't do this at home kids!
return -1;
}
}
// On to the next type
return SqDynArgImpl< Ts... >::Try(fn, vm);
}
};
/* ------------------------------------------------------------------------------------------------
* Squirrel function that forwards the call to the actual implementation.
*/
template < typename F, typename U, typename... Ts > SQInteger SqDynArgFwd(HSQUIRRELVM vm)
{
// Make sure that there are enough parameters on the stack
if (sq_gettop(vm) < 2)
{
return sq_throwerror(vm, "Insufficient parameters for such operation");
}
// Attempt to create the functor that performs the operation
F fn(vm);
// Is this functor in a valid state?
if (!fn)
{
return sq_throwerror(vm, "Functor failed to initialize");
}
// Attempt to perform the comparison
try
{
return SqDynArgImpl< U, Ts... >::Try(fn, vm);
}
catch (const Sqrat::Exception & e)
{
return sq_throwerror(vm, e.what());
}
catch (...)
{
return sq_throwerror(vm, "Unknown error occurred during comparison");
}
// We shouldn't really reach this point but something must be returned
return sq_throwerror(vm, "Operation encountered unknown behavior");
}
/* ------------------------------------------------------------------------------------------------
* Functor used to perform comparison.
*/
template < typename T > struct SqDynArgCmpFn
{
// --------------------------------------------------------------------------------------------
HSQUIRRELVM mVM; // The squirrel virtual machine.
Var< T * > mVar; // The instance of the base type.
/* --------------------------------------------------------------------------------------------
* Base constructor. (required)
*/
SqDynArgCmpFn(HSQUIRRELVM vm)
: mVM(vm), mVar(vm, 1)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to boolean. (required)
*/
operator bool () const
{
return (mVar.value != nullptr);
}
/* --------------------------------------------------------------------------------------------
* Function call operator for references. (required)
*/
template < typename U > SQInteger operator () (U & v) const
{
return mVar.value->Cmp(v);
}
/* --------------------------------------------------------------------------------------------
* Function call operator for const references. (required)
*/
template < typename U > SQInteger operator () (const U & v) const
{
return mVar.value->Cmp(v);
}
/* --------------------------------------------------------------------------------------------
* Function call operator for pointers. (required)
*/
template < typename U > SQInteger operator () (U * v) const
{
return mVar.value->Cmp(v);
}
/* --------------------------------------------------------------------------------------------
* Function call operator for const pointers. (required)
*/
template < typename U > SQInteger operator () (const U * v) const
{
return mVar.value->Cmp(v);
}
/* --------------------------------------------------------------------------------------------
* Function call operator for null pointers. (required)
*/
SQInteger operator () (std::nullptr_t) const
{
return mVar.value->Cmp(nullptr);
}
};
/* ------------------------------------------------------------------------------------------------
* Functor used to perform addition.
*/
template < typename T > struct SqDynArgAddFn
{
// --------------------------------------------------------------------------------------------
HSQUIRRELVM mVM; // The squirrel virtual machine.
Var< T * > mVar; // The instance of the base type.
/* --------------------------------------------------------------------------------------------
* Base constructor. (required)
*/
SqDynArgAddFn(HSQUIRRELVM vm)
: mVM(vm), mVar(vm, 1)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to boolean. (required)
*/
operator bool () const
{
return (mVar.value != nullptr);
}
/* --------------------------------------------------------------------------------------------
* Function call operator for references. (required)
*/
template < typename U > T operator () (U & v) const
{
return (*mVar.value) + v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for const references. (required)
*/
template < typename U > T operator () (const U & v) const
{
return (*mVar.value) + v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for pointers. (required)
*/
template < typename U > T operator () (U * v) const
{
return (*mVar.value) + v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for const pointers. (required)
*/
template < typename U > T operator () (const U * v) const
{
return (*mVar.value) + v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for null pointers. (required)
*/
T operator () (std::nullptr_t) const
{
return (*mVar.value);
}
};
/* ------------------------------------------------------------------------------------------------
* Functor used to perform subtraction.
*/
template < typename T > struct SqDynArgSubFn
{
// --------------------------------------------------------------------------------------------
HSQUIRRELVM mVM; // The squirrel virtual machine.
Var< T * > mVar; // The instance of the base type.
/* --------------------------------------------------------------------------------------------
* Base constructor. (required)
*/
SqDynArgSubFn(HSQUIRRELVM vm)
: mVM(vm), mVar(vm, 1)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to boolean. (required)
*/
operator bool () const
{
return (mVar.value != nullptr);
}
/* --------------------------------------------------------------------------------------------
* Function call operator for references. (required)
*/
template < typename U > T operator () (U & v) const
{
return (*mVar.value) - v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for const references. (required)
*/
template < typename U > T operator () (const U & v) const
{
return (*mVar.value) - v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for pointers. (required)
*/
template < typename U > T operator () (U * v) const
{
return (*mVar.value) - v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for const pointers. (required)
*/
template < typename U > T operator () (const U * v) const
{
return (*mVar.value) - v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for null pointers. (required)
*/
T operator () (std::nullptr_t) const
{
return (*mVar.value);
}
};
/* ------------------------------------------------------------------------------------------------
* Functor used to perform multiplication.
*/
template < typename T > struct SqDynArgMulFn
{
// --------------------------------------------------------------------------------------------
HSQUIRRELVM mVM; // The squirrel virtual machine.
Var< T * > mVar; // The instance of the base type.
/* --------------------------------------------------------------------------------------------
* Base constructor. (required)
*/
SqDynArgMulFn(HSQUIRRELVM vm)
: mVM(vm), mVar(vm, 1)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to boolean. (required)
*/
operator bool () const
{
return (mVar.value != nullptr);
}
/* --------------------------------------------------------------------------------------------
* Function call operator for references. (required)
*/
template < typename U > T operator () (U & v) const
{
return (*mVar.value) * v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for const references. (required)
*/
template < typename U > T operator () (const U & v) const
{
return (*mVar.value) * v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for pointers. (required)
*/
template < typename U > T operator () (U * v) const
{
return (*mVar.value) * v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for const pointers. (required)
*/
template < typename U > T operator () (const U * v) const
{
return (*mVar.value) * v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for null pointers. (required)
*/
T operator () (std::nullptr_t) const
{
return (*mVar.value) * static_cast< SQInteger >(0);
}
};
/* ------------------------------------------------------------------------------------------------
* Functor used to perform division.
*/
template < typename T > struct SqDynArgDivFn
{
// --------------------------------------------------------------------------------------------
HSQUIRRELVM mVM; // The squirrel virtual machine.
Var< T * > mVar; // The instance of the base type.
/* --------------------------------------------------------------------------------------------
* Base constructor. (required)
*/
SqDynArgDivFn(HSQUIRRELVM vm)
: mVM(vm), mVar(vm, 1)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to boolean. (required)
*/
operator bool () const
{
return (mVar.value != nullptr);
}
/* --------------------------------------------------------------------------------------------
* Function call operator for references. (required)
*/
template < typename U > T operator () (U & v) const
{
return (*mVar.value) / v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for const references. (required)
*/
template < typename U > T operator () (const U & v) const
{
return (*mVar.value) / v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for pointers. (required)
*/
template < typename U > T operator () (U * v) const
{
return (*mVar.value) / v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for const pointers. (required)
*/
template < typename U > T operator () (const U * v) const
{
return (*mVar.value) / v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for null pointers. (required)
*/
T operator () (std::nullptr_t) const
{
return (*mVar.value) / static_cast< SQInteger >(0);
}
};
/* ------------------------------------------------------------------------------------------------
* Functor used to perform modulus.
*/
template < typename T > struct SqDynArgModFn
{
// --------------------------------------------------------------------------------------------
HSQUIRRELVM mVM; // The squirrel virtual machine.
Var< T * > mVar; // The instance of the base type.
/* --------------------------------------------------------------------------------------------
* Base constructor. (required)
*/
SqDynArgModFn(HSQUIRRELVM vm)
: mVM(vm), mVar(vm, 1)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to boolean. (required)
*/
operator bool () const
{
return (mVar.value != nullptr);
}
/* --------------------------------------------------------------------------------------------
* Function call operator for references. (required)
*/
template < typename U > T operator () (U & v) const
{
return (*mVar.value) % v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for const references. (required)
*/
template < typename U > T operator () (const U & v) const
{
return (*mVar.value) % v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for pointers. (required)
*/
template < typename U > T operator () (U * v) const
{
return (*mVar.value) % v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for const pointers. (required)
*/
template < typename U > T operator () (const U * v) const
{
return (*mVar.value) % v;
}
/* --------------------------------------------------------------------------------------------
* Function call operator for null pointers. (required)
*/
T operator () (std::nullptr_t) const
{
return (*mVar.value) % static_cast< SQInteger >(0);
}
};
} // Namespace:: SqMod
#endif // _BASE_DYNARG_HPP_

View File

@@ -1 +0,0 @@
#include "Utility.inl"

View File

@@ -1 +0,0 @@
#include "Utility.inl"

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -68,42 +68,6 @@ extern "C" {
typedef void (*SqModAPI_LogMessage) (const SQChar * fmt, ...);
//script loading
typedef SQRESULT (*SqModAPI_LoadScript) (const SQChar * filepath, SQBool delay);
//numeric utilities
typedef SQRESULT (*SqModAPI_GetSLongValue) (HSQUIRRELVM vm, SQInteger idx, SqInt64 * num);
typedef SQRESULT (*SqModAPI_PushSLongObject) (HSQUIRRELVM vm, SqInt64 num);
typedef SQRESULT (*SqModAPI_GetULongValue) (HSQUIRRELVM vm, SQInteger idx, SqUint64 * num);
typedef SQRESULT (*SqModAPI_PushULongObject) (HSQUIRRELVM vm, SqUint64 num);
//time utilities
typedef SqInt64 (*SqModAPI_GetCurrentSysTime) (void);
typedef SqInt64 (*SqModAPI_GetEpochTimeMicro) (void);
typedef SqInt64 (*SqModAPI_GetEpochTimeMilli) (void);
typedef SQBool (*SqModAPI_ValidDate) (uint16_t year, uint8_t month, uint8_t day);
typedef SQBool (*SqModAPI_IsLeapYear) (uint16_t year);
typedef uint16_t (*SqModAPI_DaysInYear) (uint16_t year);
typedef uint8_t (*SqModAPI_DaysInMonth) (uint16_t year, uint8_t month);
typedef uint16_t (*SqModAPI_DayOfYear) (uint16_t year, uint8_t month, uint8_t day);
typedef SqInt64 (*SqModAPI_DateRangeToSeconds) (uint16_t lyear, uint8_t lmonth, uint8_t lday, uint16_t ryear, uint8_t rmonth, uint8_t rday);
typedef SQRESULT (*SqModAPI_GetTimestamp) (HSQUIRRELVM vm, SQInteger idx, SqInt64 * num);
typedef SQRESULT (*SqModAPI_PushTimestamp) (HSQUIRRELVM vm, SqInt64 num);
typedef SQRESULT (*SqModAPI_GetDate) (HSQUIRRELVM vm, SQInteger idx, uint16_t * year, uint8_t * month, uint8_t * day);
typedef SQRESULT (*SqModAPI_PushDate) (HSQUIRRELVM vm, uint16_t year, uint8_t month, uint8_t day);
typedef SQRESULT (*SqModAPI_GetTime) (HSQUIRRELVM vm, SQInteger idx, uint8_t * hour, uint8_t * minute, uint8_t * second, uint16_t * millisecond);
typedef SQRESULT (*SqModAPI_PushTime) (HSQUIRRELVM vm, uint8_t hour, uint8_t minute, uint8_t second, uint16_t millisecond);
typedef SQRESULT (*SqModAPI_GetDatetime) (HSQUIRRELVM vm, SQInteger idx, uint16_t * year, uint8_t * month, uint8_t * day, uint8_t * hour, uint8_t * minute, uint8_t * second, uint16_t * millisecond);
typedef SQRESULT (*SqModAPI_PushDatetime) (HSQUIRRELVM vm, uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint16_t millisecond);
//stack utilities
typedef SQInteger (*SqModAPI_PopStackInteger) (HSQUIRRELVM vm, SQInteger idx);
typedef SQFloat (*SqModAPI_PopStackFloat) (HSQUIRRELVM vm, SQInteger idx);
typedef SqInt64 (*SqModAPI_PopStackSLong) (HSQUIRRELVM vm, SQInteger idx);
typedef SqUint64 (*SqModAPI_PopStackULong) (HSQUIRRELVM vm, SQInteger idx);
//buffer utilities
typedef SQRESULT (*SqModAPI_PushBuffer) (HSQUIRRELVM vm, SQInteger size, SQInteger cursor);
typedef SQRESULT (*SqModAPI_PushBufferData) (HSQUIRRELVM vm, const char * data, SQInteger size, SQInteger cursor);
typedef SQRESULT (*SqModAPI_GetBufferInfo) (HSQUIRRELVM vm, SQInteger idx, const char ** ptr, SQInteger * size, SQInteger * cursor);
typedef const char * (*SqModAPI_GetBufferData) (HSQUIRRELVM vm, SQInteger idx);
typedef SQInteger (*SqModAPI_GetBufferSize) (HSQUIRRELVM vm, SQInteger idx);
typedef SQInteger (*SqModAPI_GetBufferCursor) (HSQUIRRELVM vm, SQInteger idx);
/* --------------------------------------------------------------------------------------------
* Allows modules to interface with the plug-in API without linking of any sorts
*/
@@ -128,41 +92,6 @@ extern "C" {
SqModAPI_LogMessage LogSFtl;
//script loading
SqModAPI_LoadScript LoadScript;
//numeric utilities
SqModAPI_GetSLongValue GetSLongValue;
SqModAPI_PushSLongObject PushSLongObject;
SqModAPI_GetULongValue GetULongValue;
SqModAPI_PushULongObject PushULongObject;
//time utilities
SqModAPI_GetCurrentSysTime GetCurrentSysTime;
SqModAPI_GetEpochTimeMicro GetEpochTimeMicro;
SqModAPI_GetEpochTimeMilli GetEpochTimeMilli;
SqModAPI_ValidDate ValidDate;
SqModAPI_IsLeapYear IsLeapYear;
SqModAPI_DaysInYear DaysInYear;
SqModAPI_DaysInMonth DaysInMonth;
SqModAPI_DayOfYear DayOfYear;
SqModAPI_DateRangeToSeconds DateRangeToSeconds;
SqModAPI_GetTimestamp GetTimestamp;
SqModAPI_PushTimestamp PushTimestamp;
SqModAPI_GetDate GetDate;
SqModAPI_PushDate PushDate;
SqModAPI_GetTime GetTime;
SqModAPI_PushTime PushTime;
SqModAPI_GetDatetime GetDatetime;
SqModAPI_PushDatetime PushDatetime;
//stack utilities
SqModAPI_PopStackInteger PopStackInteger;
SqModAPI_PopStackFloat PopStackFloat;
SqModAPI_PopStackSLong PopStackSLong;
SqModAPI_PopStackULong PopStackULong;
//buffer utilities
SqModAPI_PushBuffer PushBuffer;
SqModAPI_PushBufferData PushBufferData;
SqModAPI_GetBufferInfo GetBufferInfo;
SqModAPI_GetBufferData GetBufferData;
SqModAPI_GetBufferSize GetBufferSize;
SqModAPI_GetBufferCursor GetBufferCursor;
} sq_modapi, SQMODAPI, *HSQMODAPI;
#ifdef SQMOD_PLUGIN_API
@@ -189,45 +118,6 @@ extern "C" {
//script loading
extern SqModAPI_LoadScript SqMod_LoadScript;
//numeric utilities
extern SqModAPI_GetSLongValue SqMod_GetSLongValue;
extern SqModAPI_PushSLongObject SqMod_PushSLongObject;
extern SqModAPI_GetULongValue SqMod_GetULongValue;
extern SqModAPI_PushULongObject SqMod_PushULongObject;
//time utilities
extern SqModAPI_GetCurrentSysTime SqMod_GetCurrentSysTime;
extern SqModAPI_GetEpochTimeMicro SqMod_GetEpochTimeMicro;
extern SqModAPI_GetEpochTimeMilli SqMod_GetEpochTimeMilli;
extern SqModAPI_ValidDate SqMod_ValidDate;
extern SqModAPI_IsLeapYear SqMod_IsLeapYear;
extern SqModAPI_DaysInYear SqMod_DaysInYear;
extern SqModAPI_DaysInMonth SqMod_DaysInMonth;
extern SqModAPI_DayOfYear SqMod_DayOfYear;
extern SqModAPI_DateRangeToSeconds SqMod_DateRangeToSeconds;
extern SqModAPI_GetTimestamp SqMod_GetTimestamp;
extern SqModAPI_PushTimestamp SqMod_PushTimestamp;
extern SqModAPI_GetDate SqMod_GetDate;
extern SqModAPI_PushDate SqMod_PushDate;
extern SqModAPI_GetTime SqMod_GetTime;
extern SqModAPI_PushTime SqMod_PushTime;
extern SqModAPI_GetDatetime SqMod_GetDatetime;
extern SqModAPI_PushDatetime SqMod_PushDatetime;
//stack utilities
extern SqModAPI_PopStackInteger SqMod_PopStackInteger;
extern SqModAPI_PopStackFloat SqMod_PopStackFloat;
extern SqModAPI_PopStackSLong SqMod_PopStackSLong;
extern SqModAPI_PopStackULong SqMod_PopStackULong;
//buffer utilities
extern SqModAPI_PushBuffer SqMod_PushBuffer;
extern SqModAPI_PushBufferData SqMod_PushBufferData;
extern SqModAPI_GetBufferInfo SqMod_GetBufferInfo;
extern SqModAPI_GetBufferData SqMod_GetBufferData;
extern SqModAPI_GetBufferSize SqMod_GetBufferSize;
extern SqModAPI_GetBufferCursor SqMod_GetBufferCursor;
#endif // SQMOD_PLUGIN_API
/* --------------------------------------------------------------------------------------------

View File

@@ -23,45 +23,6 @@ SqModAPI_LogMessage SqMod_LogSFtl
//script loading
SqModAPI_LoadScript SqMod_LoadScript = NULL;
//numeric utilities
SqModAPI_GetSLongValue SqMod_GetSLongValue = NULL;
SqModAPI_PushSLongObject SqMod_PushSLongObject = NULL;
SqModAPI_GetULongValue SqMod_GetULongValue = NULL;
SqModAPI_PushULongObject SqMod_PushULongObject = NULL;
//time utilities
SqModAPI_GetCurrentSysTime SqMod_GetCurrentSysTime = NULL;
SqModAPI_GetEpochTimeMicro SqMod_GetEpochTimeMicro = NULL;
SqModAPI_GetEpochTimeMilli SqMod_GetEpochTimeMilli = NULL;
SqModAPI_ValidDate SqMod_ValidDate = NULL;
SqModAPI_IsLeapYear SqMod_IsLeapYear = NULL;
SqModAPI_DaysInYear SqMod_DaysInYear = NULL;
SqModAPI_DaysInMonth SqMod_DaysInMonth = NULL;
SqModAPI_DayOfYear SqMod_DayOfYear = NULL;
SqModAPI_DateRangeToSeconds SqMod_DateRangeToSeconds = NULL;
SqModAPI_GetTimestamp SqMod_GetTimestamp = NULL;
SqModAPI_PushTimestamp SqMod_PushTimestamp = NULL;
SqModAPI_GetDate SqMod_GetDate = NULL;
SqModAPI_PushDate SqMod_PushDate = NULL;
SqModAPI_GetTime SqMod_GetTime = NULL;
SqModAPI_PushTime SqMod_PushTime = NULL;
SqModAPI_GetDatetime SqMod_GetDatetime = NULL;
SqModAPI_PushDatetime SqMod_PushDatetime = NULL;
//stack utilities
SqModAPI_PopStackInteger SqMod_PopStackInteger = NULL;
SqModAPI_PopStackFloat SqMod_PopStackFloat = NULL;
SqModAPI_PopStackSLong SqMod_PopStackSLong = NULL;
SqModAPI_PopStackULong SqMod_PopStackULong = NULL;
//buffer utilities
SqModAPI_PushBuffer SqMod_PushBuffer = NULL;
SqModAPI_PushBufferData SqMod_PushBufferData = NULL;
SqModAPI_GetBufferInfo SqMod_GetBufferInfo = NULL;
SqModAPI_GetBufferData SqMod_GetBufferData = NULL;
SqModAPI_GetBufferSize SqMod_GetBufferSize = NULL;
SqModAPI_GetBufferCursor SqMod_GetBufferCursor = NULL;
#endif // SQMOD_PLUGIN_API
// ------------------------------------------------------------------------------------------------
@@ -96,45 +57,6 @@ uint8_t sqmod_api_expand(HSQMODAPI sqmodapi)
//script loading
SqMod_LoadScript = sqmodapi->LoadScript;
//numeric utilities
SqMod_GetSLongValue = sqmodapi->GetSLongValue;
SqMod_PushSLongObject = sqmodapi->PushSLongObject;
SqMod_GetULongValue = sqmodapi->GetULongValue;
SqMod_PushULongObject = sqmodapi->PushULongObject;
//time utilities
SqMod_GetCurrentSysTime = sqmodapi->GetCurrentSysTime;
SqMod_GetEpochTimeMicro = sqmodapi->GetEpochTimeMicro;
SqMod_GetEpochTimeMilli = sqmodapi->GetEpochTimeMilli;
SqMod_ValidDate = sqmodapi->ValidDate;
SqMod_IsLeapYear = sqmodapi->IsLeapYear;
SqMod_DaysInYear = sqmodapi->DaysInYear;
SqMod_DaysInMonth = sqmodapi->DaysInMonth;
SqMod_DayOfYear = sqmodapi->DayOfYear;
SqMod_DateRangeToSeconds = sqmodapi->DateRangeToSeconds;
SqMod_GetTimestamp = sqmodapi->GetTimestamp;
SqMod_PushTimestamp = sqmodapi->PushTimestamp;
SqMod_GetDate = sqmodapi->GetDate;
SqMod_PushDate = sqmodapi->PushDate;
SqMod_GetTime = sqmodapi->GetTime;
SqMod_PushTime = sqmodapi->PushTime;
SqMod_GetDatetime = sqmodapi->GetDatetime;
SqMod_PushDatetime = sqmodapi->PushDatetime;
//stack utilities
SqMod_PopStackInteger = sqmodapi->PopStackInteger;
SqMod_PopStackFloat = sqmodapi->PopStackFloat;
SqMod_PopStackSLong = sqmodapi->PopStackSLong;
SqMod_PopStackULong = sqmodapi->PopStackULong;
//buffer utilities
SqMod_PushBuffer = sqmodapi->PushBuffer;
SqMod_PushBufferData = sqmodapi->PushBufferData;
SqMod_GetBufferInfo = sqmodapi->GetBufferInfo;
SqMod_GetBufferData = sqmodapi->GetBufferData;
SqMod_GetBufferSize = sqmodapi->GetBufferSize;
SqMod_GetBufferCursor = sqmodapi->GetBufferCursor;
#endif // SQMOD_PLUGIN_API
return 1;
@@ -167,45 +89,6 @@ void sqmod_api_collapse()
//script loading
SqMod_LoadScript = NULL;
//numeric utilities
SqMod_GetSLongValue = NULL;
SqMod_PushSLongObject = NULL;
SqMod_GetULongValue = NULL;
SqMod_PushULongObject = NULL;
//time utilities
SqMod_GetCurrentSysTime = NULL;
SqMod_GetEpochTimeMicro = NULL;
SqMod_GetEpochTimeMilli = NULL;
SqMod_ValidDate = NULL;
SqMod_IsLeapYear = NULL;
SqMod_DaysInYear = NULL;
SqMod_DaysInMonth = NULL;
SqMod_DayOfYear = NULL;
SqMod_DateRangeToSeconds = NULL;
SqMod_GetTimestamp = NULL;
SqMod_PushTimestamp = NULL;
SqMod_GetDate = NULL;
SqMod_PushDate = NULL;
SqMod_GetTime = NULL;
SqMod_PushTime = NULL;
SqMod_GetDatetime = NULL;
SqMod_PushDatetime = NULL;
//stack utilities
SqMod_PopStackInteger = NULL;
SqMod_PopStackFloat = NULL;
SqMod_PopStackSLong = NULL;
SqMod_PopStackULong = NULL;
//buffer utilities
SqMod_PushBuffer = NULL;
SqMod_PushBufferData = NULL;
SqMod_GetBufferInfo = NULL;
SqMod_GetBufferData = NULL;
SqMod_GetBufferSize = NULL;
SqMod_GetBufferCursor = NULL;
#endif // SQMOD_PLUGIN_API
}