1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 08:47:17 +01:00

Fix the functions used to create buffers and extend with new ones to interact with them.

This commit is contained in:
Sandu Liviu Catalin 2016-07-09 17:21:41 +03:00
parent 953ef30c17
commit bd75ffe305
4 changed files with 262 additions and 92 deletions

View File

@ -99,6 +99,10 @@ extern "C" {
//buffer utilities
typedef SQRESULT (*SqEx_PushBuffer) (HSQUIRRELVM vm, SQInteger size, SQInteger cursor);
typedef SQRESULT (*SqEx_PushBufferData) (HSQUIRRELVM vm, const char * data, SQInteger size, SQInteger cursor);
typedef SQRESULT (*SqEx_GetBufferInfo) (HSQUIRRELVM vm, SQInteger idx, const char ** ptr, SQInteger * size, SQInteger * cursor);
typedef const char * (*SqEx_GetBufferData) (HSQUIRRELVM vm, SQInteger idx);
typedef SQInteger (*SqEx_GetBufferSize) (HSQUIRRELVM vm, SQInteger idx);
typedef SQInteger (*SqEx_GetBufferCursor) (HSQUIRRELVM vm, SQInteger idx);
/* --------------------------------------------------------------------------------------------
* Allows modules to interface with the plug-in API without linking of any sorts
@ -157,6 +161,10 @@ extern "C" {
//buffer utilities
SqEx_PushBuffer PushBuffer;
SqEx_PushBufferData PushBufferData;
SqEx_GetBufferInfo GetBufferInfo;
SqEx_GetBufferData GetBufferData;
SqEx_GetBufferSize GetBufferSize;
SqEx_GetBufferCursor GetBufferCursor;
} sq_exports, SQEXPORTS, *HSQEXPORTS;
#ifdef SQMOD_PLUGIN_API
@ -218,6 +226,10 @@ extern "C" {
//buffer utilities
extern SqEx_PushBuffer SqMod_PushBuffer;
extern SqEx_PushBufferData SqMod_PushBufferData;
extern SqEx_GetBufferInfo SqMod_GetBufferInfo;
extern SqEx_GetBufferData SqMod_GetBufferData;
extern SqEx_GetBufferSize SqMod_GetBufferSize;
extern SqEx_GetBufferCursor SqMod_GetBufferCursor;
#endif // SQMOD_PLUGIN_API

View File

@ -665,62 +665,66 @@ SQRESULT sqmod_api_expand(HSQEXPORTS sqmodapi)
#ifdef SQMOD_PLUGIN_API
//primitive functions
SqMod_GetSquirrelAPI = sqmodapi->GetSquirrelAPI;
SqMod_GetSquirrelVM = sqmodapi->GetSquirrelVM;
SqMod_GetSquirrelAPI = sqmodapi->GetSquirrelAPI;
SqMod_GetSquirrelVM = sqmodapi->GetSquirrelVM;
//logging utilities
SqMod_LogDbg = sqmodapi->LogDbg;
SqMod_LogUsr = sqmodapi->LogUsr;
SqMod_LogScs = sqmodapi->LogScs;
SqMod_LogInf = sqmodapi->LogInf;
SqMod_LogWrn = sqmodapi->LogWrn;
SqMod_LogErr = sqmodapi->LogErr;
SqMod_LogFtl = sqmodapi->LogFtl;
SqMod_LogSDbg = sqmodapi->LogSDbg;
SqMod_LogSUsr = sqmodapi->LogSUsr;
SqMod_LogSScs = sqmodapi->LogSScs;
SqMod_LogSInf = sqmodapi->LogSInf;
SqMod_LogSWrn = sqmodapi->LogSWrn;
SqMod_LogSErr = sqmodapi->LogSErr;
SqMod_LogSFtl = sqmodapi->LogSFtl;
SqMod_LogDbg = sqmodapi->LogDbg;
SqMod_LogUsr = sqmodapi->LogUsr;
SqMod_LogScs = sqmodapi->LogScs;
SqMod_LogInf = sqmodapi->LogInf;
SqMod_LogWrn = sqmodapi->LogWrn;
SqMod_LogErr = sqmodapi->LogErr;
SqMod_LogFtl = sqmodapi->LogFtl;
SqMod_LogSDbg = sqmodapi->LogSDbg;
SqMod_LogSUsr = sqmodapi->LogSUsr;
SqMod_LogSScs = sqmodapi->LogSScs;
SqMod_LogSInf = sqmodapi->LogSInf;
SqMod_LogSWrn = sqmodapi->LogSWrn;
SqMod_LogSErr = sqmodapi->LogSErr;
SqMod_LogSFtl = sqmodapi->LogSFtl;
//script loading
SqMod_LoadScript = sqmodapi->LoadScript;
SqMod_LoadScript = sqmodapi->LoadScript;
//numeric utilities
SqMod_GetSLongValue = sqmodapi->GetSLongValue;
SqMod_PushSLongObject = sqmodapi->PushSLongObject;
SqMod_GetULongValue = sqmodapi->GetULongValue;
SqMod_PushULongObject = sqmodapi->PushULongObject;
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;
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;
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_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
@ -733,62 +737,66 @@ void sqmod_api_collapse()
#ifdef SQMOD_PLUGIN_API
//primitive functions
SqMod_GetSquirrelAPI = NULL;
SqMod_GetSquirrelVM = NULL;
SqMod_GetSquirrelAPI = NULL;
SqMod_GetSquirrelVM = NULL;
//logging utilities
SqMod_LogDbg = NULL;
SqMod_LogUsr = NULL;
SqMod_LogScs = NULL;
SqMod_LogInf = NULL;
SqMod_LogWrn = NULL;
SqMod_LogErr = NULL;
SqMod_LogFtl = NULL;
SqMod_LogSDbg = NULL;
SqMod_LogSUsr = NULL;
SqMod_LogSScs = NULL;
SqMod_LogSInf = NULL;
SqMod_LogSWrn = NULL;
SqMod_LogSErr = NULL;
SqMod_LogSFtl = NULL;
SqMod_LogDbg = NULL;
SqMod_LogUsr = NULL;
SqMod_LogScs = NULL;
SqMod_LogInf = NULL;
SqMod_LogWrn = NULL;
SqMod_LogErr = NULL;
SqMod_LogFtl = NULL;
SqMod_LogSDbg = NULL;
SqMod_LogSUsr = NULL;
SqMod_LogSScs = NULL;
SqMod_LogSInf = NULL;
SqMod_LogSWrn = NULL;
SqMod_LogSErr = NULL;
SqMod_LogSFtl = NULL;
//script loading
SqMod_LoadScript = NULL;
SqMod_LoadScript = NULL;
//numeric utilities
SqMod_GetSLongValue = NULL;
SqMod_PushSLongObject = NULL;
SqMod_GetULongValue = NULL;
SqMod_PushULongObject = NULL;
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;
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;
SqMod_PopStackInteger = NULL;
SqMod_PopStackFloat = NULL;
SqMod_PopStackSLong = NULL;
SqMod_PopStackULong = NULL;
//buffer utilities
SqMod_PushBuffer = NULL;
SqMod_PushBufferData = NULL;
SqMod_PushBuffer = NULL;
SqMod_PushBufferData = NULL;
SqMod_GetBufferInfo = NULL;
SqMod_GetBufferData = NULL;
SqMod_GetBufferSize = NULL;
SqMod_GetBufferCursor = NULL;
#endif // SQMOD_PLUGIN_API
}

View File

@ -8,6 +8,7 @@
#include "Library/Chrono/Time.hpp"
#include "Library/Chrono/Datetime.hpp"
#include "Library/Chrono/Timestamp.hpp"
#include "Library/Utils/Buffer.hpp"
// ------------------------------------------------------------------------------------------------
#include <cmath>
@ -494,8 +495,7 @@ SQRESULT SqEx_PushBuffer(HSQUIRRELVM vm, SQInteger size, SQInteger cursor)
// Attempt to push the requested instance
try
{
Var< const Buffer & >::push(vm, Buffer(ConvTo< Buffer::SzType >::From(size),
ConvTo< Buffer::SzType >::From(cursor)));
Var< const SqBuffer & >::push(vm, SqBuffer(size, cursor));
}
catch (...)
{
@ -512,8 +512,7 @@ SQRESULT SqEx_PushBufferData(HSQUIRRELVM vm, const char * data, SQInteger size,
// Attempt to push the requested instance
try
{
Var< const Buffer & >::push(vm, Buffer(data, ConvTo< Buffer::SzType >::From(size),
ConvTo< Buffer::SzType >::From(cursor)));
Var< const SqBuffer & >::push(vm, SqBuffer(data, size, cursor));
}
catch (...)
{
@ -524,6 +523,126 @@ SQRESULT SqEx_PushBufferData(HSQUIRRELVM vm, const char * data, SQInteger size,
return SQ_OK;
}
// ------------------------------------------------------------------------------------------------
SQRESULT SqEx_GetBufferInfo(HSQUIRRELVM vm, SQInteger idx, const char ** ptr, SQInteger * size, SQInteger * cursor)
{
// Attempt to obtain the requested information
try
{
// Attempt to retrieve the instance
Var< SqBuffer * > var(vm, idx);
// Validate the obtained buffer
if (!(var.value) || !(var.value->GetRef()) || !(*var.value->GetRef()))
{
// Should we obtain the buffer contents?
if (ptr)
{
*ptr = nullptr; // Default to null data
}
// Should we obtain the buffer length?
if (size)
{
*size = 0; // Default to 0 length
}
// Should we obtain the cursor position?
if (cursor)
{
*cursor = 0; // Default to position 0
}
}
// Grab the internal buffer
const Buffer & b = *var.value->GetRef();
// Should we obtain the buffer contents?
if (ptr)
{
*ptr = b.Data();
}
// Should we obtain the buffer length?
if (size)
{
*size = ConvTo< SQInteger >::From(b.Capacity());
}
// Should we obtain the cursor position?
if (cursor)
{
*cursor = ConvTo< SQInteger >::From(b.Position());
}
}
catch (...)
{
// Specify that we failed
return SQ_ERROR;
}
// Specify that we succeeded
return SQ_OK;
}
// ------------------------------------------------------------------------------------------------
const char * SqEx_GetBufferData(HSQUIRRELVM vm, SQInteger idx)
{
// Attempt to obtain the requested information
try
{
// Attempt to retrieve the instance
Var< SqBuffer * > var(vm, idx);
// Validate the obtained buffer and return the requested information
if ((var.value) && (var.value->GetRef()) && (*var.value->GetRef()))
{
return var.value->GetRef()->Data();
}
}
catch (...)
{
// Just ignore it...
}
// Specify that we failed
return nullptr;
}
// ------------------------------------------------------------------------------------------------
SQInteger SqEx_GetBufferSize(HSQUIRRELVM vm, SQInteger idx)
{
// Attempt to obtain the requested information
try
{
// Attempt to retrieve the instance
Var< SqBuffer * > var(vm, idx);
// Validate the obtained buffer and return the requested information
if ((var.value) && (var.value->GetRef()) && (*var.value->GetRef()))
{
return ConvTo< SQInteger >::From(var.value->GetRef()->Capacity());
}
}
catch (...)
{
// Just ignore it...
}
// Specify that we failed
return -1;
}
// ------------------------------------------------------------------------------------------------
SQInteger SqEx_GetBufferCursor(HSQUIRRELVM vm, SQInteger idx)
{
// Attempt to obtain the requested information
try
{
// Attempt to retrieve the instance
Var< SqBuffer * > var(vm, idx);
// Validate the obtained buffer and return the requested information
if ((var.value) && (var.value->GetRef()) && (*var.value->GetRef()))
{
return ConvTo< SQInteger >::From(var.value->GetRef()->Position());
}
}
catch (...)
{
// Just ignore it...
}
// Specify that we failed
return -1;
}
// ------------------------------------------------------------------------------------------------
void InitExports()
{
@ -587,6 +706,10 @@ void InitExports()
//buffer utilities
g_SqExports.PushBuffer = SqEx_PushBuffer;
g_SqExports.PushBufferData = SqEx_PushBufferData;
g_SqExports.GetBufferInfo = SqEx_GetBufferInfo;
g_SqExports.GetBufferData = SqEx_GetBufferData;
g_SqExports.GetBufferSize = SqEx_GetBufferSize;
g_SqExports.GetBufferCursor = SqEx_GetBufferCursor;
// Export them to the server
_Func->ExportFunctions(_Info->pluginId,

View File

@ -63,6 +63,33 @@ public:
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Allocate constructor.
*/
SqBuffer(SQInteger n, SQInteger c)
: m_Buffer(new Buffer(ConvTo< SzType >::From(n), ConvTo< SzType >::From(c)))
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
SqBuffer(ConstPtr p, SQInteger n)
: m_Buffer(new Buffer(p, ConvTo< SzType >::From(n)))
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
SqBuffer(ConstPtr p, SQInteger n, SQInteger c)
: m_Buffer(new Buffer(p, ConvTo< SzType >::From(n), ConvTo< SzType >::From(c)))
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Reference constructor.
*/