1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-21 01:27:14 +02:00

Expand the host plug-in API and not just the Squirrel API.

Extend the host plug-in API with a few more date/time functions.
Update some of the plugins to use the expanded functions of the host plug-in API.
This commit is contained in:
Sandu Liviu Catalin
2016-07-04 16:26:39 +03:00
parent 805251a6db
commit 87ab54d453
22 changed files with 396 additions and 78 deletions

@ -747,7 +747,7 @@ Object MakeSLongObj(Int64 val)
const StackGuard sg(vm);
#ifdef SQMOD_PLUGIN_API
// Push a long integer instance with the requested value on the stack
_SqMod->PushSLongObject(vm, val);
SqMod_PushSLongObject(vm, val);
#else
// Transform the specified value into a script object
PushVar< SLongInt >(vm, SLongInt(val));
@ -765,7 +765,7 @@ Object MakeULongObj(Uint64 val)
const StackGuard sg(vm);
#ifdef SQMOD_PLUGIN_API
// Push a long integer instance with the requested value on the stack
_SqMod->PushULongObject(vm, val);
SqMod_PushULongObject(vm, val);
#else
// Transform the specified value into a script object
PushVar< ULongInt >(vm, ULongInt(val));
@ -781,7 +781,7 @@ Object MakeSLongObj(HSQUIRRELVM vm, Int64 val)
const StackGuard sg(vm);
#ifdef SQMOD_PLUGIN_API
// Push a long integer instance with the requested value on the stack
_SqMod->PushSLongObject(vm, val);
SqMod_PushSLongObject(vm, val);
#else
// Transform the specified value into a script object
PushVar< SLongInt >(vm, SLongInt(val));
@ -797,7 +797,7 @@ Object MakeULongObj(HSQUIRRELVM vm, Uint64 val)
const StackGuard sg(vm);
#ifdef SQMOD_PLUGIN_API
// Push a long integer instance with the requested value on the stack
_SqMod->PushULongObject(vm, val);
SqMod_PushULongObject(vm, val);
#else
// Transform the specified value into a script object
PushVar< ULongInt >(vm, ULongInt(val));
@ -854,7 +854,7 @@ Uint64 FetchULongObjVal(HSQUIRRELVM vm, const Object & val)
SQInteger PopStackInteger(HSQUIRRELVM vm, SQInteger idx)
{
#ifdef SQMOD_PLUGIN_API
return _SqMod->PopStackInteger(vm, idx);
return SqMod_PopStackInteger(vm, idx);
#else
// Identify which type must be extracted
switch (sq_gettype(vm, idx))
@ -927,7 +927,7 @@ SQInteger PopStackInteger(HSQUIRRELVM vm, SQInteger idx)
SQFloat PopStackFloat(HSQUIRRELVM vm, SQInteger idx)
{
#ifdef SQMOD_PLUGIN_API
return _SqMod->PopStackFloat(vm, idx);
return SqMod_PopStackFloat(vm, idx);
#else
// Identify which type must be extracted
switch (sq_gettype(vm, idx))
@ -1004,7 +1004,7 @@ SQFloat PopStackFloat(HSQUIRRELVM vm, SQInteger idx)
Int64 PopStackSLong(HSQUIRRELVM vm, SQInteger idx)
{
#ifdef SQMOD_PLUGIN_API
return _SqMod->PopStackSLong(vm, idx);
return SqMod_PopStackSLong(vm, idx);
#else
// Identify which type must be extracted
switch (sq_gettype(vm, idx))
@ -1077,7 +1077,7 @@ Int64 PopStackSLong(HSQUIRRELVM vm, SQInteger idx)
Uint64 PopStackULong(HSQUIRRELVM vm, SQInteger idx)
{
#ifdef SQMOD_PLUGIN_API
return _SqMod->PopStackULong(vm, idx);
return SqMod_PopStackULong(vm, idx);
#else
// Identify which type must be extracted
switch (sq_gettype(vm, idx))

@ -77,6 +77,12 @@ extern "C" {
typedef SqInt64 (*SqEx_GetCurrentSysTime) (void);
typedef SqInt64 (*SqEx_GetEpochTimeMicro) (void);
typedef SqInt64 (*SqEx_GetEpochTimeMilli) (void);
typedef SQBool (*SqEx_ValidDate) (uint16_t year, uint8_t month, uint8_t day);
typedef SQBool (*SqEx_IsLeapYear) (uint16_t year);
typedef uint16_t (*SqEx_DaysInYear) (uint16_t year);
typedef uint8_t (*SqEx_DaysInMonth) (uint16_t year, uint8_t month);
typedef uint16_t (*SqEx_DayOfYear) (uint16_t year, uint8_t month, uint8_t day);
typedef SqInt64 (*SqEx_DateRangeToSeconds) (uint16_t lyear, uint8_t lmonth, uint8_t lday, uint16_t ryear, uint8_t rmonth, uint8_t rday);
typedef SQRESULT (*SqEx_GetTimestamp) (HSQUIRRELVM vm, SQInteger idx, SqInt64 * num);
typedef SQRESULT (*SqEx_PushTimestamp) (HSQUIRRELVM vm, SqInt64 num);
typedef SQRESULT (*SqEx_GetDate) (HSQUIRRELVM vm, SQInteger idx, uint16_t * year, uint8_t * month, uint8_t * day);
@ -129,6 +135,12 @@ extern "C" {
SqEx_GetCurrentSysTime GetCurrentSysTime;
SqEx_GetEpochTimeMicro GetEpochTimeMicro;
SqEx_GetEpochTimeMilli GetEpochTimeMilli;
SqEx_ValidDate ValidDate;
SqEx_IsLeapYear IsLeapYear;
SqEx_DaysInYear DaysInYear;
SqEx_DaysInMonth DaysInMonth;
SqEx_DayOfYear DayOfYear;
SqEx_DateRangeToSeconds DateRangeToSeconds;
SqEx_GetTimestamp GetTimestamp;
SqEx_PushTimestamp PushTimestamp;
SqEx_GetDate GetDate;
@ -147,6 +159,68 @@ extern "C" {
SqEx_PushBufferData PushBufferData;
} sq_exports, SQEXPORTS, *HSQEXPORTS;
#ifdef SQMOD_PLUGIN_API
//primitive functions
extern SqEx_GetSquirrelAPI SqMod_GetSquirrelAPI;
extern SqEx_GetSquirrelVM SqMod_GetSquirrelVM;
//logging utilities
extern SqEx_LogMessage SqMod_LogDbg;
extern SqEx_LogMessage SqMod_LogUsr;
extern SqEx_LogMessage SqMod_LogScs;
extern SqEx_LogMessage SqMod_LogInf;
extern SqEx_LogMessage SqMod_LogWrn;
extern SqEx_LogMessage SqMod_LogErr;
extern SqEx_LogMessage SqMod_LogFtl;
extern SqEx_LogMessage SqMod_LogSDbg;
extern SqEx_LogMessage SqMod_LogSUsr;
extern SqEx_LogMessage SqMod_LogSScs;
extern SqEx_LogMessage SqMod_LogSInf;
extern SqEx_LogMessage SqMod_LogSWrn;
extern SqEx_LogMessage SqMod_LogSErr;
extern SqEx_LogMessage SqMod_LogSFtl;
//script loading
extern SqEx_LoadScript SqMod_LoadScript;
//numeric utilities
extern SqEx_GetSLongValue SqMod_GetSLongValue;
extern SqEx_PushSLongObject SqMod_PushSLongObject;
extern SqEx_GetULongValue SqMod_GetULongValue;
extern SqEx_PushULongObject SqMod_PushULongObject;
//time utilities
extern SqEx_GetCurrentSysTime SqMod_GetCurrentSysTime;
extern SqEx_GetEpochTimeMicro SqMod_GetEpochTimeMicro;
extern SqEx_GetEpochTimeMilli SqMod_GetEpochTimeMilli;
extern SqEx_ValidDate SqMod_ValidDate;
extern SqEx_IsLeapYear SqMod_IsLeapYear;
extern SqEx_DaysInYear SqMod_DaysInYear;
extern SqEx_DaysInMonth SqMod_DaysInMonth;
extern SqEx_DayOfYear SqMod_DayOfYear;
extern SqEx_DateRangeToSeconds SqMod_DateRangeToSeconds;
extern SqEx_GetTimestamp SqMod_GetTimestamp;
extern SqEx_PushTimestamp SqMod_PushTimestamp;
extern SqEx_GetDate SqMod_GetDate;
extern SqEx_PushDate SqMod_PushDate;
extern SqEx_GetTime SqMod_GetTime;
extern SqEx_PushTime SqMod_PushTime;
extern SqEx_GetDatetime SqMod_GetDatetime;
extern SqEx_PushDatetime SqMod_PushDatetime;
//stack utilities
extern SqEx_PopStackInteger SqMod_PopStackInteger;
extern SqEx_PopStackFloat SqMod_PopStackFloat;
extern SqEx_PopStackSLong SqMod_PopStackSLong;
extern SqEx_PopStackULong SqMod_PopStackULong;
//buffer utilities
extern SqEx_PushBuffer SqMod_PushBuffer;
extern SqEx_PushBufferData SqMod_PushBufferData;
#endif // SQMOD_PLUGIN_API
/* --------------------------------------------------------------------------------------------
* Import the functions from the main squirrel plug-in.
*/
@ -157,11 +231,21 @@ extern "C" {
*/
SQUIRREL_API SQRESULT sq_api_expand(HSQAPI sqapi);
/* --------------------------------------------------------------------------------------------
* Assign the functions from the specified API structure into the global functions.
*/
SQUIRREL_API SQRESULT sqmod_api_expand(HSQEXPORTS sqmodapi);
/* --------------------------------------------------------------------------------------------
* Undo changes done by sq_api_expand.
*/
SQUIRREL_API void sq_api_collapse();
/* --------------------------------------------------------------------------------------------
* Undo changes done by sqmod_api_expand.
*/
SQUIRREL_API void sqmod_api_collapse();
#ifdef __cplusplus
} /*extern "C"*/
#endif

@ -590,3 +590,205 @@ void sq_api_collapse()
#endif // SQMOD_PLUGIN_API
}
// ------------------------------------------------------------------------------------------------
#ifdef SQMOD_PLUGIN_API
//primitive functions
SqEx_GetSquirrelAPI SqMod_GetSquirrelAPI = NULL;
SqEx_GetSquirrelVM SqMod_GetSquirrelVM = NULL;
//logging utilities
SqEx_LogMessage SqMod_LogDbg = NULL;
SqEx_LogMessage SqMod_LogUsr = NULL;
SqEx_LogMessage SqMod_LogScs = NULL;
SqEx_LogMessage SqMod_LogInf = NULL;
SqEx_LogMessage SqMod_LogWrn = NULL;
SqEx_LogMessage SqMod_LogErr = NULL;
SqEx_LogMessage SqMod_LogFtl = NULL;
SqEx_LogMessage SqMod_LogSDbg = NULL;
SqEx_LogMessage SqMod_LogSUsr = NULL;
SqEx_LogMessage SqMod_LogSScs = NULL;
SqEx_LogMessage SqMod_LogSInf = NULL;
SqEx_LogMessage SqMod_LogSWrn = NULL;
SqEx_LogMessage SqMod_LogSErr = NULL;
SqEx_LogMessage SqMod_LogSFtl = NULL;
//script loading
SqEx_LoadScript SqMod_LoadScript = NULL;
//numeric utilities
SqEx_GetSLongValue SqMod_GetSLongValue = NULL;
SqEx_PushSLongObject SqMod_PushSLongObject = NULL;
SqEx_GetULongValue SqMod_GetULongValue = NULL;
SqEx_PushULongObject SqMod_PushULongObject = NULL;
//time utilities
SqEx_GetCurrentSysTime SqMod_GetCurrentSysTime = NULL;
SqEx_GetEpochTimeMicro SqMod_GetEpochTimeMicro = NULL;
SqEx_GetEpochTimeMilli SqMod_GetEpochTimeMilli = NULL;
SqEx_ValidDate SqMod_ValidDate = NULL;
SqEx_IsLeapYear SqMod_IsLeapYear = NULL;
SqEx_DaysInYear SqMod_DaysInYear = NULL;
SqEx_DaysInMonth SqMod_DaysInMonth = NULL;
SqEx_DayOfYear SqMod_DayOfYear = NULL;
SqEx_DateRangeToSeconds SqMod_DateRangeToSeconds = NULL;
SqEx_GetTimestamp SqMod_GetTimestamp = NULL;
SqEx_PushTimestamp SqMod_PushTimestamp = NULL;
SqEx_GetDate SqMod_GetDate = NULL;
SqEx_PushDate SqMod_PushDate = NULL;
SqEx_GetTime SqMod_GetTime = NULL;
SqEx_PushTime SqMod_PushTime = NULL;
SqEx_GetDatetime SqMod_GetDatetime = NULL;
SqEx_PushDatetime SqMod_PushDatetime = NULL;
//stack utilities
SqEx_PopStackInteger SqMod_PopStackInteger = NULL;
SqEx_PopStackFloat SqMod_PopStackFloat = NULL;
SqEx_PopStackSLong SqMod_PopStackSLong = NULL;
SqEx_PopStackULong SqMod_PopStackULong = NULL;
//buffer utilities
SqEx_PushBuffer SqMod_PushBuffer = NULL;
SqEx_PushBufferData SqMod_PushBufferData = NULL;
#endif // SQMOD_PLUGIN_API
// ------------------------------------------------------------------------------------------------
SQRESULT sqmod_api_expand(HSQEXPORTS sqmodapi)
{
if (!sqmodapi)
{
return SQ_ERROR;
}
#ifdef SQMOD_PLUGIN_API
//primitive functions
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;
//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;
#endif // SQMOD_PLUGIN_API
return SQ_OK;
}
// ------------------------------------------------------------------------------------------------
void sqmod_api_collapse()
{
#ifdef SQMOD_PLUGIN_API
//primitive functions
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;
//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;
#endif // SQMOD_PLUGIN_API
}