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

Export functions to at least create shared buffers from modules.

This commit is contained in:
Sandu Liviu Catalin 2016-06-15 10:01:07 +03:00
parent 861c830bb7
commit 166760fd46
2 changed files with 47 additions and 0 deletions

View File

@ -89,6 +89,9 @@ extern "C" {
typedef SQFloat (*SqEx_PopStackFloat) (HSQUIRRELVM vm, SQInteger idx);
typedef SqInt64 (*SqEx_PopStackSLong) (HSQUIRRELVM vm, SQInteger idx);
typedef SqUint64 (*SqEx_PopStackULong) (HSQUIRRELVM vm, SQInteger idx);
//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);
/* --------------------------------------------------------------------------------------------
* Allows modules to interface with the plug-in API without linking of any sorts
@ -138,6 +141,9 @@ extern "C" {
SqEx_PopStackFloat PopStackFloat;
SqEx_PopStackSLong PopStackSLong;
SqEx_PopStackULong PopStackULong;
//buffer utilities
SqEx_PushBuffer PushBuffer;
SqEx_PushBufferData PushBufferData;
} sq_exports, SQEXPORTS, *HSQEXPORTS;
/* --------------------------------------------------------------------------------------------

View File

@ -1,5 +1,6 @@
// ------------------------------------------------------------------------------------------------
#include "Core.hpp"
#include "Base/Buffer.hpp"
// ------------------------------------------------------------------------------------------------
#include "Library/Numeric/LongInt.hpp"
@ -475,6 +476,42 @@ SQRESULT SqEx_PushDatetime(HSQUIRRELVM vm, uint16_t year, uint8_t month, uint8_t
return SQ_OK;
}
// ------------------------------------------------------------------------------------------------
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)));
}
catch (...)
{
// Specify that we failed
return SQ_ERROR;
}
// Specify that we succeeded
return SQ_OK;
}
// ------------------------------------------------------------------------------------------------
SQRESULT SqEx_PushBufferData(HSQUIRRELVM vm, const char * data, SQInteger size, SQInteger cursor)
{
// Attempt to push the requested instance
try
{
Var< const Buffer & >::push(vm, Buffer(data, ConvTo< Buffer::SzType >::From(size),
ConvTo< Buffer::SzType >::From(cursor)));
}
catch (...)
{
// Specify that we failed
return SQ_ERROR;
}
// Specify that we succeeded
return SQ_OK;
}
// ------------------------------------------------------------------------------------------------
void InitExports()
{
@ -529,6 +566,10 @@ void InitExports()
g_SqExports.PopStackSLong = PopStackSLong;
g_SqExports.PopStackULong = PopStackULong;
//buffer utilities
g_SqExports.PushBuffer = SqEx_PushBuffer;
g_SqExports.PushBufferData = SqEx_PushBufferData;
// Export them to the server
_Func->ExportFunctions(_Info->pluginId,
const_cast< const void ** >(reinterpret_cast< void ** >(&sqexports)),