mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-01-19 03:57:14 +01:00
Fix the functions used to create buffers and extend with new ones to interact with them.
This commit is contained in:
parent
953ef30c17
commit
bd75ffe305
@ -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
|
||||
|
||||
|
@ -721,6 +721,10 @@ SQRESULT sqmod_api_expand(HSQEXPORTS sqmodapi)
|
||||
//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
|
||||
|
||||
@ -789,6 +793,10 @@ void sqmod_api_collapse()
|
||||
//buffer utilities
|
||||
SqMod_PushBuffer = NULL;
|
||||
SqMod_PushBufferData = NULL;
|
||||
SqMod_GetBufferInfo = NULL;
|
||||
SqMod_GetBufferData = NULL;
|
||||
SqMod_GetBufferSize = NULL;
|
||||
SqMod_GetBufferCursor = NULL;
|
||||
|
||||
#endif // SQMOD_PLUGIN_API
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user