1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-15 22:57:12 +02:00

Rvised the API distribution system to avoid segmentation fault crashes on Linux and make the overal code cleaner.

Moved the constants in IRC module into their own source and implemented a faster method of registering them.
Various other minor changes and adjustments. Some of them in order to comply with the new API distribution system.
This commit is contained in:
Sandu Liviu Catalin
2016-07-17 03:24:07 +03:00
parent 5ddb222903
commit 66d1110733
32 changed files with 3049 additions and 2773 deletions

View File

@ -8,7 +8,7 @@
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQInteger GetNick(HSQUIRRELVM vm)
static SQInteger SqGetNick(HSQUIRRELVM vm)
{
// Attempt to retrieve the value from the stack as a string
StackStrF val(vm, 2);
@ -26,7 +26,7 @@ SQInteger GetNick(HSQUIRRELVM vm)
}
// ------------------------------------------------------------------------------------------------
SQInteger GetHost(HSQUIRRELVM vm)
static SQInteger SqGetHost(HSQUIRRELVM vm)
{
// Attempt to retrieve the value from the stack as a string
StackStrF val(vm, 2);
@ -44,7 +44,7 @@ SQInteger GetHost(HSQUIRRELVM vm)
}
// ------------------------------------------------------------------------------------------------
SQInteger StripColorFromMIRC(HSQUIRRELVM vm)
static SQInteger SqStripColorFromMIRC(HSQUIRRELVM vm)
{
// Attempt to retrieve the value from the stack as a string
StackStrF val(vm, 2);
@ -69,7 +69,7 @@ SQInteger StripColorFromMIRC(HSQUIRRELVM vm)
}
// ------------------------------------------------------------------------------------------------
SQInteger ConvertColorFromMIRC(HSQUIRRELVM vm)
static SQInteger SqConvertColorFromMIRC(HSQUIRRELVM vm)
{
// Attempt to retrieve the value from the stack as a string
StackStrF val(vm, 2);
@ -94,7 +94,7 @@ SQInteger ConvertColorFromMIRC(HSQUIRRELVM vm)
}
// ------------------------------------------------------------------------------------------------
SQInteger ConvertColorToMIRC(HSQUIRRELVM vm)
static SQInteger SqConvertColorToMIRC(HSQUIRRELVM vm)
{
// Attempt to retrieve the value from the stack as a string
StackStrF val(vm, 2);
@ -118,4 +118,15 @@ SQInteger ConvertColorToMIRC(HSQUIRRELVM vm)
return 1;
}
// ================================================================================================
void Register_Common(Table & ircns)
{
ircns.Func(_SC("GetErrStr"), &irc_strerror);
ircns.SquirrelFunc(_SC("GetNick"), &SqGetNick);
ircns.SquirrelFunc(_SC("GetHost"), &SqGetHost);
ircns.SquirrelFunc(_SC("StripColorFromMIRC"), &SqStripColorFromMIRC);
ircns.SquirrelFunc(_SC("ConvertColorFromMIRC"), &SqConvertColorFromMIRC);
ircns.SquirrelFunc(_SC("ConvertColorToMIRC"), &SqConvertColorToMIRC);
}
} // Namespace:: SqMod

244
modules/irc/Constants.cpp Normal file
View File

@ -0,0 +1,244 @@
// ------------------------------------------------------------------------------------------------
#include "Common.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Helper class that represents an integral enumeration value. Used to reduce compilation times.
*/
struct EnumElement
{
CSStr Name;
Int32 Value;
};
// ------------------------------------------------------------------------------------------------
#define SQENUMCOUNT(arr) (sizeof(arr) / sizeof(EnumElement))
// ------------------------------------------------------------------------------------------------
static const EnumElement g_IrcEvent[] = {
{_SC("Connect"), SET_CONNECT},
{_SC("Nick"), SET_NICK},
{_SC("Quit"), SET_QUIT},
{_SC("Join"), SET_JOIN},
{_SC("Part"), SET_PART},
{_SC("Mode"), SET_MODE},
{_SC("Umode"), SET_UMODE},
{_SC("Topic"), SET_TOPIC},
{_SC("Kick"), SET_KICK},
{_SC("Channel"), SET_CHANNEL},
{_SC("PrivMsg"), SET_PRIVMSG},
{_SC("Notice"), SET_NOTICE},
{_SC("ChannelNotice"), SET_CHANNELNOTICE},
{_SC("Invite"), SET_INVITE},
{_SC("CtcpReq"), SET_CTCPREQ},
{_SC("CtcpRep"), SET_CTCPREP},
{_SC("CtcpAction"), SET_CTCPACTION},
{_SC("Unknown"), SET_UNKNOWN},
{_SC("Numeric"), SET_NUMERIC},
{_SC("DccChatReq"), SET_DCCCHATREQ},
{_SC("DccSendReq"), SET_DCCSENDREQ}
};
// ------------------------------------------------------------------------------------------------
static const EnumElement g_IrcErr[] = {
{_SC("Ok"), LIBIRC_ERR_OK},
{_SC("InVal"), LIBIRC_ERR_INVAL},
{_SC("Resolv"), LIBIRC_ERR_RESOLV},
{_SC("Socket"), LIBIRC_ERR_SOCKET},
{_SC("Connect"), LIBIRC_ERR_CONNECT},
{_SC("Closed"), LIBIRC_ERR_CLOSED},
{_SC("NoMem"), LIBIRC_ERR_NOMEM},
{_SC("Accept"), LIBIRC_ERR_ACCEPT},
{_SC("NoDccSend"), LIBIRC_ERR_NODCCSEND},
{_SC("Read"), LIBIRC_ERR_READ},
{_SC("Write"), LIBIRC_ERR_WRITE},
{_SC("State"), LIBIRC_ERR_STATE},
{_SC("Timeout"), LIBIRC_ERR_TIMEOUT},
{_SC("OpenFile"), LIBIRC_ERR_OPENFILE},
{_SC("Terminated"), LIBIRC_ERR_TERMINATED},
{_SC("NoIPv6"), LIBIRC_ERR_NOIPV6},
{_SC("SSLNotSupported"), LIBIRC_ERR_SSL_NOT_SUPPORTED},
{_SC("SSLInitFailed"), LIBIRC_ERR_SSL_INIT_FAILED},
{_SC("ConnectSSLFailed"), LIBIRC_ERR_CONNECT_SSL_FAILED},
{_SC("SSLCertVerifyFailed"), LIBIRC_ERR_SSL_CERT_VERIFY_FAILED},
{_SC("Max"), LIBIRC_ERR_MAX}
};
// ------------------------------------------------------------------------------------------------
static const EnumElement g_IrcOpt[] = {
{_SC("Debug"), LIBIRC_OPTION_DEBUG},
{_SC("StripNicks"), LIBIRC_OPTION_STRIPNICKS},
{_SC("SSLNoVerify"), LIBIRC_OPTION_SSL_NO_VERIFY}
};
// ------------------------------------------------------------------------------------------------
static const EnumElement g_IrcRFC[] = {
{_SC("RPL_WELCOME"), LIBIRC_RFC_RPL_WELCOME},
{_SC("RPL_YOURHOST"), LIBIRC_RFC_RPL_YOURHOST},
{_SC("RPL_CREATED"), LIBIRC_RFC_RPL_CREATED},
{_SC("RPL_MYINFO"), LIBIRC_RFC_RPL_MYINFO},
{_SC("RPL_BOUNCE"), LIBIRC_RFC_RPL_BOUNCE},
{_SC("RPL_NONE"), LIBIRC_RFC_RPL_NONE},
{_SC("RPL_USERHOST"), LIBIRC_RFC_RPL_USERHOST},
{_SC("RPL_ISON"), LIBIRC_RFC_RPL_ISON},
{_SC("RPL_AWAY"), LIBIRC_RFC_RPL_AWAY},
{_SC("RPL_UNAWAY"), LIBIRC_RFC_RPL_UNAWAY},
{_SC("RPL_NOWAWAY"), LIBIRC_RFC_RPL_NOWAWAY},
{_SC("RPL_WHOISUSER"), LIBIRC_RFC_RPL_WHOISUSER},
{_SC("RPL_WHOISSERVER"), LIBIRC_RFC_RPL_WHOISSERVER},
{_SC("RPL_WHOISOPERATOR"), LIBIRC_RFC_RPL_WHOISOPERATOR},
{_SC("RPL_WHOISIDLE"), LIBIRC_RFC_RPL_WHOISIDLE},
{_SC("RPL_ENDOFWHOIS"), LIBIRC_RFC_RPL_ENDOFWHOIS},
{_SC("RPL_WHOISCHANNELS"), LIBIRC_RFC_RPL_WHOISCHANNELS},
{_SC("RPL_WHOWASUSER"), LIBIRC_RFC_RPL_WHOWASUSER},
{_SC("RPL_ENDOFWHOWAS"), LIBIRC_RFC_RPL_ENDOFWHOWAS},
{_SC("RPL_LISTSTART"), LIBIRC_RFC_RPL_LISTSTART},
{_SC("RPL_LIST"), LIBIRC_RFC_RPL_LIST},
{_SC("RPL_LISTEND"), LIBIRC_RFC_RPL_LISTEND},
{_SC("RPL_UNIQOPIS"), LIBIRC_RFC_RPL_UNIQOPIS},
{_SC("RPL_CHANNELMODEIS"), LIBIRC_RFC_RPL_CHANNELMODEIS},
{_SC("RPL_NOTOPIC"), LIBIRC_RFC_RPL_NOTOPIC},
{_SC("RPL_TOPIC"), LIBIRC_RFC_RPL_TOPIC},
{_SC("RPL_INVITING"), LIBIRC_RFC_RPL_INVITING},
{_SC("RPL_SUMMONING"), LIBIRC_RFC_RPL_SUMMONING},
{_SC("RPL_INVITELIST"), LIBIRC_RFC_RPL_INVITELIST},
{_SC("RPL_ENDOFINVITELIST"), LIBIRC_RFC_RPL_ENDOFINVITELIST},
{_SC("RPL_EXCEPTLIST"), LIBIRC_RFC_RPL_EXCEPTLIST},
{_SC("RPL_ENDOFEXCEPTLIST"), LIBIRC_RFC_RPL_ENDOFEXCEPTLIST},
{_SC("RPL_VERSION"), LIBIRC_RFC_RPL_VERSION},
{_SC("RPL_WHOREPLY"), LIBIRC_RFC_RPL_WHOREPLY},
{_SC("RPL_ENDOFWHO"), LIBIRC_RFC_RPL_ENDOFWHO},
{_SC("RPL_NAMREPLY"), LIBIRC_RFC_RPL_NAMREPLY},
{_SC("RPL_ENDOFNAMES"), LIBIRC_RFC_RPL_ENDOFNAMES},
{_SC("RPL_LINKS"), LIBIRC_RFC_RPL_LINKS},
{_SC("RPL_ENDOFLINKS"), LIBIRC_RFC_RPL_ENDOFLINKS},
{_SC("RPL_BANLIST"), LIBIRC_RFC_RPL_BANLIST},
{_SC("RPL_ENDOFBANLIST"), LIBIRC_RFC_RPL_ENDOFBANLIST},
{_SC("RPL_INFO"), LIBIRC_RFC_RPL_INFO},
{_SC("RPL_ENDOFINFO"), LIBIRC_RFC_RPL_ENDOFINFO},
{_SC("RPL_MOTDSTART"), LIBIRC_RFC_RPL_MOTDSTART},
{_SC("RPL_MOTD"), LIBIRC_RFC_RPL_MOTD},
{_SC("RPL_ENDOFMOTD"), LIBIRC_RFC_RPL_ENDOFMOTD},
{_SC("RPL_YOUREOPER"), LIBIRC_RFC_RPL_YOUREOPER},
{_SC("RPL_REHASHING"), LIBIRC_RFC_RPL_REHASHING},
{_SC("RPL_YOURESERVICE"), LIBIRC_RFC_RPL_YOURESERVICE},
{_SC("RPL_TIME"), LIBIRC_RFC_RPL_TIME},
{_SC("RPL_USERSSTART"), LIBIRC_RFC_RPL_USERSSTART},
{_SC("RPL_USERS"), LIBIRC_RFC_RPL_USERS},
{_SC("RPL_ENDOFUSERS"), LIBIRC_RFC_RPL_ENDOFUSERS},
{_SC("RPL_NOUSERS"), LIBIRC_RFC_RPL_NOUSERS},
{_SC("RPL_TRACELINK"), LIBIRC_RFC_RPL_TRACELINK},
{_SC("RPL_TRACECONNECTING"), LIBIRC_RFC_RPL_TRACECONNECTING},
{_SC("RPL_TRACEHANDSHAKE"), LIBIRC_RFC_RPL_TRACEHANDSHAKE},
{_SC("RPL_TRACEUNKNOWN"), LIBIRC_RFC_RPL_TRACEUNKNOWN},
{_SC("RPL_TRACEOPERATOR"), LIBIRC_RFC_RPL_TRACEOPERATOR},
{_SC("RPL_TRACEUSER"), LIBIRC_RFC_RPL_TRACEUSER},
{_SC("RPL_TRACESERVER"), LIBIRC_RFC_RPL_TRACESERVER},
{_SC("RPL_TRACESERVICE"), LIBIRC_RFC_RPL_TRACESERVICE},
{_SC("RPL_TRACENEWTYPE"), LIBIRC_RFC_RPL_TRACENEWTYPE},
{_SC("RPL_TRACECLASS"), LIBIRC_RFC_RPL_TRACECLASS},
{_SC("RPL_TRACELOG"), LIBIRC_RFC_RPL_TRACELOG},
{_SC("RPL_TRACEEND"), LIBIRC_RFC_RPL_TRACEEND},
{_SC("RPL_STATSLINKINFO"), LIBIRC_RFC_RPL_STATSLINKINFO},
{_SC("RPL_STATSCOMMANDS"), LIBIRC_RFC_RPL_STATSCOMMANDS},
{_SC("RPL_ENDOFSTATS"), LIBIRC_RFC_RPL_ENDOFSTATS},
{_SC("RPL_STATSUPTIME"), LIBIRC_RFC_RPL_STATSUPTIME},
{_SC("RPL_STATSOLINE"), LIBIRC_RFC_RPL_STATSOLINE},
{_SC("RPL_UMODEIS"), LIBIRC_RFC_RPL_UMODEIS},
{_SC("RPL_SERVLIST"), LIBIRC_RFC_RPL_SERVLIST},
{_SC("RPL_SERVLISTEND"), LIBIRC_RFC_RPL_SERVLISTEND},
{_SC("RPL_LUSERCLIENT"), LIBIRC_RFC_RPL_LUSERCLIENT},
{_SC("RPL_LUSEROP"), LIBIRC_RFC_RPL_LUSEROP},
{_SC("RPL_LUSERUNKNOWN"), LIBIRC_RFC_RPL_LUSERUNKNOWN},
{_SC("RPL_LUSERCHANNELS"), LIBIRC_RFC_RPL_LUSERCHANNELS},
{_SC("RPL_LUSERME"), LIBIRC_RFC_RPL_LUSERME},
{_SC("RPL_ADMINME"), LIBIRC_RFC_RPL_ADMINME},
{_SC("RPL_ADMINLOC1"), LIBIRC_RFC_RPL_ADMINLOC1},
{_SC("RPL_ADMINLOC2"), LIBIRC_RFC_RPL_ADMINLOC2},
{_SC("RPL_ADMINEMAIL"), LIBIRC_RFC_RPL_ADMINEMAIL},
{_SC("RPL_TRYAGAIN"), LIBIRC_RFC_RPL_TRYAGAIN},
{_SC("ERR_NOSUCHNICK"), LIBIRC_RFC_ERR_NOSUCHNICK},
{_SC("ERR_NOSUCHSERVER"), LIBIRC_RFC_ERR_NOSUCHSERVER},
{_SC("ERR_NOSUCHCHANNEL"), LIBIRC_RFC_ERR_NOSUCHCHANNEL},
{_SC("ERR_CANNOTSENDTOCHAN"), LIBIRC_RFC_ERR_CANNOTSENDTOCHAN},
{_SC("ERR_TOOMANYCHANNELS"), LIBIRC_RFC_ERR_TOOMANYCHANNELS},
{_SC("ERR_WASNOSUCHNICK"), LIBIRC_RFC_ERR_WASNOSUCHNICK},
{_SC("ERR_TOOMANYTARGETS"), LIBIRC_RFC_ERR_TOOMANYTARGETS},
{_SC("ERR_NOSUCHSERVICE"), LIBIRC_RFC_ERR_NOSUCHSERVICE},
{_SC("ERR_NOORIGIN"), LIBIRC_RFC_ERR_NOORIGIN},
{_SC("ERR_NORECIPIENT"), LIBIRC_RFC_ERR_NORECIPIENT},
{_SC("ERR_NOTEXTTOSEND"), LIBIRC_RFC_ERR_NOTEXTTOSEND},
{_SC("ERR_NOTOPLEVEL"), LIBIRC_RFC_ERR_NOTOPLEVEL},
{_SC("ERR_WILDTOPLEVEL"), LIBIRC_RFC_ERR_WILDTOPLEVEL},
{_SC("ERR_BADMASK"), LIBIRC_RFC_ERR_BADMASK},
{_SC("ERR_UNKNOWNCOMMAND"), LIBIRC_RFC_ERR_UNKNOWNCOMMAND},
{_SC("ERR_NOMOTD"), LIBIRC_RFC_ERR_NOMOTD},
{_SC("ERR_NOADMININFO"), LIBIRC_RFC_ERR_NOADMININFO},
{_SC("ERR_FILEERROR"), LIBIRC_RFC_ERR_FILEERROR},
{_SC("ERR_NONICKNAMEGIVEN"), LIBIRC_RFC_ERR_NONICKNAMEGIVEN},
{_SC("ERR_ERRONEUSNICKNAME"), LIBIRC_RFC_ERR_ERRONEUSNICKNAME},
{_SC("ERR_NICKNAMEINUSE"), LIBIRC_RFC_ERR_NICKNAMEINUSE},
{_SC("ERR_NICKCOLLISION"), LIBIRC_RFC_ERR_NICKCOLLISION},
{_SC("ERR_UNAVAILRESOURCE"), LIBIRC_RFC_ERR_UNAVAILRESOURCE},
{_SC("ERR_USERNOTINCHANNEL"), LIBIRC_RFC_ERR_USERNOTINCHANNEL},
{_SC("ERR_NOTONCHANNEL"), LIBIRC_RFC_ERR_NOTONCHANNEL},
{_SC("ERR_USERONCHANNEL"), LIBIRC_RFC_ERR_USERONCHANNEL},
{_SC("ERR_NOLOGIN"), LIBIRC_RFC_ERR_NOLOGIN},
{_SC("ERR_SUMMONDISABLED"), LIBIRC_RFC_ERR_SUMMONDISABLED},
{_SC("ERR_USERSDISABLED"), LIBIRC_RFC_ERR_USERSDISABLED},
{_SC("ERR_NOTREGISTERED"), LIBIRC_RFC_ERR_NOTREGISTERED},
{_SC("ERR_NEEDMOREPARAMS"), LIBIRC_RFC_ERR_NEEDMOREPARAMS},
{_SC("ERR_ALREADYREGISTRED"), LIBIRC_RFC_ERR_ALREADYREGISTRED},
{_SC("ERR_NOPERMFORHOST"), LIBIRC_RFC_ERR_NOPERMFORHOST},
{_SC("ERR_PASSWDMISMATCH"), LIBIRC_RFC_ERR_PASSWDMISMATCH},
{_SC("ERR_YOUREBANNEDCREEP"), LIBIRC_RFC_ERR_YOUREBANNEDCREEP},
{_SC("ERR_YOUWILLBEBANNED"), LIBIRC_RFC_ERR_YOUWILLBEBANNED},
{_SC("ERR_KEYSET"), LIBIRC_RFC_ERR_KEYSET},
{_SC("ERR_CHANNELISFULL"), LIBIRC_RFC_ERR_CHANNELISFULL},
{_SC("ERR_UNKNOWNMODE"), LIBIRC_RFC_ERR_UNKNOWNMODE},
{_SC("ERR_INVITEONLYCHAN"), LIBIRC_RFC_ERR_INVITEONLYCHAN},
{_SC("ERR_BANNEDFROMCHAN"), LIBIRC_RFC_ERR_BANNEDFROMCHAN},
{_SC("ERR_BADCHANNELKEY"), LIBIRC_RFC_ERR_BADCHANNELKEY},
{_SC("ERR_BADCHANMASK"), LIBIRC_RFC_ERR_BADCHANMASK},
{_SC("ERR_NOCHANMODES"), LIBIRC_RFC_ERR_NOCHANMODES},
{_SC("ERR_BANLISTFULL"), LIBIRC_RFC_ERR_BANLISTFULL},
{_SC("ERR_NOPRIVILEGES"), LIBIRC_RFC_ERR_NOPRIVILEGES},
{_SC("ERR_CHANOPRIVSNEEDED"), LIBIRC_RFC_ERR_CHANOPRIVSNEEDED},
{_SC("ERR_CANTKILLSERVER"), LIBIRC_RFC_ERR_CANTKILLSERVER},
{_SC("ERR_RESTRICTED"), LIBIRC_RFC_ERR_RESTRICTED},
{_SC("ERR_UNIQOPPRIVSNEEDED"), LIBIRC_RFC_ERR_UNIQOPPRIVSNEEDED},
{_SC("ERR_NOOPERHOST"), LIBIRC_RFC_ERR_NOOPERHOST},
{_SC("ERR_UMODEUNKNOWNFLAG"), LIBIRC_RFC_ERR_UMODEUNKNOWNFLAG},
{_SC("ERR_USERSDONTMATCH"), LIBIRC_RFC_ERR_USERSDONTMATCH}
};
// ------------------------------------------------------------------------------------------------
static Enumeration RegisterEnum(HSQUIRRELVM vm, CSStr name, const EnumElement * data, Uint32 count)
{
// Allocate an empty enumeration
Enumeration e(vm);
// Register the values from the received data
for (Uint32 n = 0; n < count; ++n, ++data)
{
e.Const(data->Name, data->Value);
}
// Bind the enumeration to the constant table
ConstTable(vm).Enum(name, e);
// Return the enumeration for further changes if necessary
return e;
}
// ================================================================================================
void Register_Constants(Table & ircns)
{
RegisterEnum(ircns.GetVM(), _SC("SqIrcEvent"), g_IrcEvent, SQENUMCOUNT(g_IrcEvent));
RegisterEnum(ircns.GetVM(), _SC("SqIrcErr"), g_IrcErr, SQENUMCOUNT(g_IrcErr));
RegisterEnum(ircns.GetVM(), _SC("SqIrcOpt"), g_IrcOpt, SQENUMCOUNT(g_IrcOpt));
RegisterEnum(ircns.GetVM(), _SC("SqIrcRFC"), g_IrcRFC, SQENUMCOUNT(g_IrcRFC));
}
} // Namespace:: SqMod

View File

@ -1,6 +1,5 @@
// ------------------------------------------------------------------------------------------------
#include "Common.hpp"
#include "Session.hpp"
// ------------------------------------------------------------------------------------------------
#include <cstdio>
@ -14,68 +13,83 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Register the module API under the specified virtual machine.
*/
void RegisterAPI(HSQUIRRELVM vm);
// ------------------------------------------------------------------------------------------------
extern void SessionProcess();
extern void SessionTerminate();
// ------------------------------------------------------------------------------------------------
extern void Register_Common(Table & ircns);
extern void Register_Session(Table & ircns);
extern void Register_Constants(Table & ircns);
/* ------------------------------------------------------------------------------------------------
* Initialize the plug-in by obtaining the API provided by the host plug-in.
* Register the module API under the obtained virtual machine.
*/
void OnSquirrelInitialize()
static bool RegisterAPI()
{
// Attempt to import the plug-in API exported by the host plug-in
_SqMod = sq_api_import(_Func);
// Did we failed to obtain the plug-in exports?
if (!_SqMod)
// Make sure there's a valid virtual machine before proceeding
if (!DefaultVM::Get())
{
OutputError("Failed to attach [%s] on host plug-in.", SQIRC_NAME);
}
else
{
// Expand the Squirrel plug-in API into global functions
sqmod_api_expand(_SqMod);
// Obtain the Squirrel API
_SqAPI = SqMod_GetSquirrelAPI();
// Expand the Squirrel API into global functions
sq_api_expand(_SqAPI);
OutputError("%s: Cannot register API without a valid virtual machine", SQIRC_NAME);
// Registration failed
return false;
}
Table ircns;
Register_Common(ircns);
Register_Session(ircns);
Register_Constants(ircns);
RootTable().Bind(_SC("SqIRC"), ircns);
// Registration was successful
return true;
}
/* ------------------------------------------------------------------------------------------------
* Load the module on the virtual machine provided by the host module.
*/
void OnSquirrelLoad()
static bool OnSquirrelLoad()
{
// Make sure that we have a valid plug-in API
if (!_SqMod)
// Make sure that we have a valid module API
if (!SqMod_GetSquirrelVM)
{
return; // Unable to proceed!
OutputError("%s: Cannot obtain the Squirrel virtual machine without the module API", SQIRC_NAME);
// Unable to proceed!
return false;
}
// Obtain the Squirrel API and VM
_SqVM = SqMod_GetSquirrelVM();
// Obtain the Squirrel virtual machine from the host plug-in
DefaultVM::Set(SqMod_GetSquirrelVM());
// Make sure that a valid virtual machine exists
if (!_SqVM)
if (!DefaultVM::Get())
{
return; // Unable to proceed!
OutputError("%s: Squirrel virtual machine obtained from the host plug-in is invalid", SQIRC_NAME);
// Unable to proceed!
return false;
}
// Set this as the default database
DefaultVM::Set(_SqVM);
// Prevent common null objects from using dead virtual machines
NullArray() = Array();
NullTable() = Table();
NullObject() = Object();
NullFunction() = Function();
// Register the module API
RegisterAPI(_SqVM);
// Notify about the current status
OutputMessage("Registered: %s", SQIRC_NAME);
if (RegisterAPI())
{
OutputMessage("Registered: %s", SQIRC_NAME);
}
else
{
return false;
}
// At this point, the module was successfully loaded
return true;
}
/* ------------------------------------------------------------------------------------------------
* The virtual machine is about to be terminated and script resources should be released.
*/
void OnSquirrelTerminate()
static void OnSquirrelTerminate()
{
OutputMessage("Terminating: %s", SQIRC_NAME);
// Release null objects just in case
@ -88,31 +102,12 @@ void OnSquirrelTerminate()
/* ------------------------------------------------------------------------------------------------
* The virtual machined was closed and all memory associated with it was released.
*/
void OnSquirrelReleased()
static void OnSquirrelReleased()
{
// Release the current virtual machine, if any
DefaultVM::Set(nullptr);
// Terminate all sessions, if any
Session::Terminate();
}
/* ------------------------------------------------------------------------------------------------
* Validate the module API to make sure we don't run into issues.
*/
bool CheckAPIVer(CCStr ver)
{
// Obtain the numeric representation of the API version
const LongI vernum = std::strtol(ver, nullptr, 10);
// Check against version mismatch
if (vernum == SQMOD_API_VER)
{
return true;
}
// Log the incident
OutputError("API version mismatch on %s", SQIRC_NAME);
OutputMessage("=> Requested: %ld Have: %ld", vernum, SQMOD_API_VER);
// Invoker should not attempt to communicate through the module API
return false;
SessionTerminate();
}
/* ------------------------------------------------------------------------------------------------
@ -123,20 +118,33 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
switch(command_identifier)
{
case SQMOD_INITIALIZE_CMD:
if (CheckAPIVer(message))
{
if (CheckModuleAPIVer(message, SQIRC_NAME))
{
OnSquirrelInitialize();
try
{
ImportModuleAPI(_Func, SQIRC_NAME);
}
catch (const Sqrat::Exception & e)
{
OutputError("%s", e.what());
// Failed to initialize
return 0;
}
}
break;
} break;
case SQMOD_LOAD_CMD:
OnSquirrelLoad();
break;
{
return OnSquirrelLoad();
} break;
case SQMOD_TERMINATE_CMD:
{
OnSquirrelTerminate();
break;
} break;
case SQMOD_RELEASED_CMD:
{
OnSquirrelReleased();
break;
} break;
default: break;
}
return 1;
@ -147,9 +155,12 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
*/
static uint8_t OnServerInitialise()
{
return 1;
return 1; // Initialization was successful
}
/* ------------------------------------------------------------------------------------------------
* The server is about to shutdown gracefully.
*/
static void OnServerShutdown(void)
{
// The server may still send callbacks
@ -164,297 +175,7 @@ static void OnServerShutdown(void)
*/
static void OnServerFrame(float /*delta*/)
{
// Update the sessions and pool for events
Session::Process();
}
// ------------------------------------------------------------------------------------------------
void RegisterAPI(HSQUIRRELVM vm)
{
Table ircns(vm);
ircns.Bind(_SC("Session"), Class< Session, NoCopy< Session > >(vm, _SC("SqIrcSession"))
// Constructors
.Ctor()
// Core Meta-methods
.Func(_SC("_cmp"), &Session::Cmp)
.SquirrelFunc(_SC("_typename"), &Session::Typename)
.Func(_SC("_tostring"), &Session::ToString)
// Properties
.Prop(_SC("Valid"), &Session::IsValid)
.Prop(_SC("Connected"), &Session::IsConnected)
.Prop(_SC("Tag"), &Session::GetTag, &Session::SetTag)
.Prop(_SC("Data"), &Session::GetData, &Session::SetData)
.Prop(_SC("Server"), &Session::GetServer, &Session::SetServer)
.Prop(_SC("Password"), &Session::GetPassword, &Session::SetPassword)
.Prop(_SC("Nick"), &Session::GetNick, &Session::SetNick)
.Prop(_SC("User"), &Session::GetUser, &Session::SetUser)
.Prop(_SC("Name"), &Session::GetName, &Session::SetName)
.Prop(_SC("Port"), &Session::GetPort, &Session::SetPort)
.Prop(_SC("PoolTime"), &Session::GetPoolTime, &Session::SetPoolTime)
.Prop(_SC("LastCode"), &Session::GetLastCode)
.Prop(_SC("Tries"), &Session::GetTries, &Session::SetTries)
.Prop(_SC("Wait"), &Session::GetWait, &Session::SetWait)
.Prop(_SC("LeftTries"), &Session::GetLeftTries, &Session::SetLeftTries)
.Prop(_SC("NextTry"), &Session::GetNextTry, &Session::SetNextTry)
.Prop(_SC("SessionTime"), &Session::GetSessionTime)
.Prop(_SC("Reconnecting"), &Session::GetReconnect)
.Prop(_SC("IPv6"), &Session::GetIPv6)
.Prop(_SC("CtcpVersion"), (void (Session::*)(void))(nullptr), &Session::SetCtcpVersion)
.Prop(_SC("ErrNo"), &Session::GetErrNo)
.Prop(_SC("ErrStr"), &Session::GetErrStr)
// Member Methods
.Func(_SC("Bind"), &Session::BindEvent)
.Func(_SC("GetEvent"), &Session::GetEvent)
.Func(_SC("Disconnect"), &Session::Disconnect)
.Func(_SC("CmdPart"), &Session::CmdPart)
.Func(_SC("CmdInvite"), &Session::CmdInvite)
.Func(_SC("CmdNames"), &Session::CmdNames)
.Func(_SC("CmdMsg"), &Session::CmdMsg)
.Func(_SC("CmdMe"), &Session::CmdMe)
.Func(_SC("CmdNotice"), &Session::CmdNotice)
.Func(_SC("CmdCtcpRequest"), &Session::CmdCtcpRequest)
.Func(_SC("CmdCtcpReply"), &Session::CmdCtcpReply)
.Func(_SC("CmdNick"), &Session::CmdNick)
.Func(_SC("CmdWhois"), &Session::CmdWhois)
.Func(_SC("SendRaw"), &Session::SendRaw)
.Func(_SC("DestroyDcc"), &Session::DestroyDcc)
.Func(_SC("SetCtcpVersion"), &Session::SetCtcpVersion)
.Func(_SC("SetOption"), &Session::SetOption)
.Func(_SC("ResetOption"), &Session::ResetOption)
// Member Overloads
.Overload< Int32 (Session::*)(void) >(_SC("Connect"), &Session::Connect)
.Overload< Int32 (Session::*)(CSStr, Uint32, CSStr) >(_SC("Connect"), &Session::Connect)
.Overload< Int32 (Session::*)(CSStr, Uint32, CSStr, CSStr) >(_SC("Connect"), &Session::Connect)
.Overload< Int32 (Session::*)(CSStr, Uint32, CSStr, CSStr, CSStr) >(_SC("Connect"), &Session::Connect)
.Overload< Int32 (Session::*)(CSStr, Uint32, CSStr, CSStr, CSStr, CSStr) >(_SC("Connect"), &Session::Connect)
.Overload< Int32 (Session::*)(void) >(_SC("Connect6"), &Session::Connect6)
.Overload< Int32 (Session::*)(CSStr, Uint32, CSStr) >(_SC("Connect6"), &Session::Connect6)
.Overload< Int32 (Session::*)(CSStr, Uint32, CSStr, CSStr) >(_SC("Connect6"), &Session::Connect6)
.Overload< Int32 (Session::*)(CSStr, Uint32, CSStr, CSStr, CSStr) >(_SC("Connect6"), &Session::Connect6)
.Overload< Int32 (Session::*)(CSStr, Uint32, CSStr, CSStr, CSStr, CSStr) >(_SC("Connect6"), &Session::Connect6)
.Overload< Int32 (Session::*)(CSStr) >(_SC("CmdJoin"), &Session::CmdJoin)
.Overload< Int32 (Session::*)(CSStr, CSStr) >(_SC("CmdJoin"), &Session::CmdJoin)
.Overload< Int32 (Session::*)(void) >(_SC("CmdList"), &Session::CmdList)
.Overload< Int32 (Session::*)(CSStr) >(_SC("CmdList"), &Session::CmdList)
.Overload< Int32 (Session::*)(CSStr) >(_SC("CmdTopic"), &Session::CmdTopic)
.Overload< Int32 (Session::*)(CSStr, CSStr) >(_SC("CmdTopic"), &Session::CmdTopic)
.Overload< Int32 (Session::*)(CSStr) >(_SC("CmdChannelMode"), &Session::CmdChannelMode)
.Overload< Int32 (Session::*)(CSStr, CSStr) >(_SC("CmdChannelMode"), &Session::CmdChannelMode)
.Overload< Int32 (Session::*)(void) >(_SC("CmdUserMode"), &Session::CmdUserMode)
.Overload< Int32 (Session::*)(CSStr) >(_SC("CmdUserMode"), &Session::CmdUserMode)
.Overload< Int32 (Session::*)(CSStr, CSStr) >(_SC("CmdKick"), &Session::CmdKick)
.Overload< Int32 (Session::*)(CSStr, CSStr, CSStr) >(_SC("CmdKick"), &Session::CmdKick)
.Overload< Int32 (Session::*)(void) >(_SC("CmdQuit"), &Session::CmdQuit)
.Overload< Int32 (Session::*)(CSStr) >(_SC("CmdQuit"), &Session::CmdQuit)
// Squirrel Methods
.SquirrelFunc(_SC("CmdMsgF"), &Session::CmdMsgF)
.SquirrelFunc(_SC("CmdMeF"), &Session::CmdMeF)
.SquirrelFunc(_SC("CmdNoticeF"), &Session::CmdNoticeF)
);
ircns.Func(_SC("GetErrStr"), &irc_strerror);
ircns.SquirrelFunc(_SC("GetNick"), &GetNick);
ircns.SquirrelFunc(_SC("GetHost"), &GetHost);
ircns.SquirrelFunc(_SC("StripColorFromMIRC"), &StripColorFromMIRC);
ircns.SquirrelFunc(_SC("ConvertColorFromMIRC"), &ConvertColorFromMIRC);
ircns.SquirrelFunc(_SC("ConvertColorToMIRC"), &ConvertColorToMIRC);
RootTable(vm).Bind(_SC("SqIRC"), ircns);
Sqrat::ConstTable(vm).Enum(_SC("SqIrcEvent"), Sqrat::Enumeration(vm)
.Const(_SC("Connect"), SET_CONNECT)
.Const(_SC("Nick"), SET_NICK)
.Const(_SC("Quit"), SET_QUIT)
.Const(_SC("Join"), SET_JOIN)
.Const(_SC("Part"), SET_PART)
.Const(_SC("Mode"), SET_MODE)
.Const(_SC("Umode"), SET_UMODE)
.Const(_SC("Topic"), SET_TOPIC)
.Const(_SC("Kick"), SET_KICK)
.Const(_SC("Channel"), SET_CHANNEL)
.Const(_SC("PrivMsg"), SET_PRIVMSG)
.Const(_SC("Notice"), SET_NOTICE)
.Const(_SC("ChannelNotice"), SET_CHANNELNOTICE)
.Const(_SC("Invite"), SET_INVITE)
.Const(_SC("CtcpReq"), SET_CTCPREQ)
.Const(_SC("CtcpRep"), SET_CTCPREP)
.Const(_SC("CtcpAction"), SET_CTCPACTION)
.Const(_SC("Unknown"), SET_UNKNOWN)
.Const(_SC("Numeric"), SET_NUMERIC)
.Const(_SC("DccChatReq"), SET_DCCCHATREQ)
.Const(_SC("DccSendReq"), SET_DCCSENDREQ)
);
Sqrat::ConstTable(vm).Enum(_SC("SqIrcErr"), Sqrat::Enumeration(vm)
.Const(_SC("Ok"), LIBIRC_ERR_OK)
.Const(_SC("InVal"), LIBIRC_ERR_INVAL)
.Const(_SC("Resolv"), LIBIRC_ERR_RESOLV)
.Const(_SC("Socket"), LIBIRC_ERR_SOCKET)
.Const(_SC("Connect"), LIBIRC_ERR_CONNECT)
.Const(_SC("Closed"), LIBIRC_ERR_CLOSED)
.Const(_SC("NoMem"), LIBIRC_ERR_NOMEM)
.Const(_SC("Accept"), LIBIRC_ERR_ACCEPT)
.Const(_SC("NoDccSend"), LIBIRC_ERR_NODCCSEND)
.Const(_SC("Read"), LIBIRC_ERR_READ)
.Const(_SC("Write"), LIBIRC_ERR_WRITE)
.Const(_SC("State"), LIBIRC_ERR_STATE)
.Const(_SC("Timeout"), LIBIRC_ERR_TIMEOUT)
.Const(_SC("OpenFile"), LIBIRC_ERR_OPENFILE)
.Const(_SC("Terminated"), LIBIRC_ERR_TERMINATED)
.Const(_SC("NoIPv6"), LIBIRC_ERR_NOIPV6)
.Const(_SC("SSLNotSupported"), LIBIRC_ERR_SSL_NOT_SUPPORTED)
.Const(_SC("SSLInitFailed"), LIBIRC_ERR_SSL_INIT_FAILED)
.Const(_SC("ConnectSSLFailed"), LIBIRC_ERR_CONNECT_SSL_FAILED)
.Const(_SC("SSLCertVerifyFailed"), LIBIRC_ERR_SSL_CERT_VERIFY_FAILED)
.Const(_SC("Max"), LIBIRC_ERR_MAX)
);
Sqrat::ConstTable(vm).Enum(_SC("SqIrcOpt"), Sqrat::Enumeration(vm)
.Const(_SC("Debug"), LIBIRC_OPTION_DEBUG)
.Const(_SC("StripNicks"), LIBIRC_OPTION_STRIPNICKS)
.Const(_SC("SSLNoVerify"), LIBIRC_OPTION_SSL_NO_VERIFY)
);
Sqrat::ConstTable(vm).Enum(_SC("SqIrcRFC"), Sqrat::Enumeration(vm)
.Const(_SC("RPL_WELCOME"), LIBIRC_RFC_RPL_WELCOME)
.Const(_SC("RPL_YOURHOST"), LIBIRC_RFC_RPL_YOURHOST)
.Const(_SC("RPL_CREATED"), LIBIRC_RFC_RPL_CREATED)
.Const(_SC("RPL_MYINFO"), LIBIRC_RFC_RPL_MYINFO)
.Const(_SC("RPL_BOUNCE"), LIBIRC_RFC_RPL_BOUNCE)
.Const(_SC("RPL_NONE"), LIBIRC_RFC_RPL_NONE)
.Const(_SC("RPL_USERHOST"), LIBIRC_RFC_RPL_USERHOST)
.Const(_SC("RPL_ISON"), LIBIRC_RFC_RPL_ISON)
.Const(_SC("RPL_AWAY"), LIBIRC_RFC_RPL_AWAY)
.Const(_SC("RPL_UNAWAY"), LIBIRC_RFC_RPL_UNAWAY)
.Const(_SC("RPL_NOWAWAY"), LIBIRC_RFC_RPL_NOWAWAY)
.Const(_SC("RPL_WHOISUSER"), LIBIRC_RFC_RPL_WHOISUSER)
.Const(_SC("RPL_WHOISSERVER"), LIBIRC_RFC_RPL_WHOISSERVER)
.Const(_SC("RPL_WHOISOPERATOR"), LIBIRC_RFC_RPL_WHOISOPERATOR)
.Const(_SC("RPL_WHOISIDLE"), LIBIRC_RFC_RPL_WHOISIDLE)
.Const(_SC("RPL_ENDOFWHOIS"), LIBIRC_RFC_RPL_ENDOFWHOIS)
.Const(_SC("RPL_WHOISCHANNELS"), LIBIRC_RFC_RPL_WHOISCHANNELS)
.Const(_SC("RPL_WHOWASUSER"), LIBIRC_RFC_RPL_WHOWASUSER)
.Const(_SC("RPL_ENDOFWHOWAS"), LIBIRC_RFC_RPL_ENDOFWHOWAS)
.Const(_SC("RPL_LISTSTART"), LIBIRC_RFC_RPL_LISTSTART)
.Const(_SC("RPL_LIST"), LIBIRC_RFC_RPL_LIST)
.Const(_SC("RPL_LISTEND"), LIBIRC_RFC_RPL_LISTEND)
.Const(_SC("RPL_UNIQOPIS"), LIBIRC_RFC_RPL_UNIQOPIS)
.Const(_SC("RPL_CHANNELMODEIS"), LIBIRC_RFC_RPL_CHANNELMODEIS)
.Const(_SC("RPL_NOTOPIC"), LIBIRC_RFC_RPL_NOTOPIC)
.Const(_SC("RPL_TOPIC"), LIBIRC_RFC_RPL_TOPIC)
.Const(_SC("RPL_INVITING"), LIBIRC_RFC_RPL_INVITING)
.Const(_SC("RPL_SUMMONING"), LIBIRC_RFC_RPL_SUMMONING)
.Const(_SC("RPL_INVITELIST"), LIBIRC_RFC_RPL_INVITELIST)
.Const(_SC("RPL_ENDOFINVITELIST"), LIBIRC_RFC_RPL_ENDOFINVITELIST)
.Const(_SC("RPL_EXCEPTLIST"), LIBIRC_RFC_RPL_EXCEPTLIST)
.Const(_SC("RPL_ENDOFEXCEPTLIST"), LIBIRC_RFC_RPL_ENDOFEXCEPTLIST)
.Const(_SC("RPL_VERSION"), LIBIRC_RFC_RPL_VERSION)
.Const(_SC("RPL_WHOREPLY"), LIBIRC_RFC_RPL_WHOREPLY)
.Const(_SC("RPL_ENDOFWHO"), LIBIRC_RFC_RPL_ENDOFWHO)
.Const(_SC("RPL_NAMREPLY"), LIBIRC_RFC_RPL_NAMREPLY)
.Const(_SC("RPL_ENDOFNAMES"), LIBIRC_RFC_RPL_ENDOFNAMES)
.Const(_SC("RPL_LINKS"), LIBIRC_RFC_RPL_LINKS)
.Const(_SC("RPL_ENDOFLINKS"), LIBIRC_RFC_RPL_ENDOFLINKS)
.Const(_SC("RPL_BANLIST"), LIBIRC_RFC_RPL_BANLIST)
.Const(_SC("RPL_ENDOFBANLIST"), LIBIRC_RFC_RPL_ENDOFBANLIST)
.Const(_SC("RPL_INFO"), LIBIRC_RFC_RPL_INFO)
.Const(_SC("RPL_ENDOFINFO"), LIBIRC_RFC_RPL_ENDOFINFO)
.Const(_SC("RPL_MOTDSTART"), LIBIRC_RFC_RPL_MOTDSTART)
.Const(_SC("RPL_MOTD"), LIBIRC_RFC_RPL_MOTD)
.Const(_SC("RPL_ENDOFMOTD"), LIBIRC_RFC_RPL_ENDOFMOTD)
.Const(_SC("RPL_YOUREOPER"), LIBIRC_RFC_RPL_YOUREOPER)
.Const(_SC("RPL_REHASHING"), LIBIRC_RFC_RPL_REHASHING)
.Const(_SC("RPL_YOURESERVICE"), LIBIRC_RFC_RPL_YOURESERVICE)
.Const(_SC("RPL_TIME"), LIBIRC_RFC_RPL_TIME)
.Const(_SC("RPL_USERSSTART"), LIBIRC_RFC_RPL_USERSSTART)
.Const(_SC("RPL_USERS"), LIBIRC_RFC_RPL_USERS)
.Const(_SC("RPL_ENDOFUSERS"), LIBIRC_RFC_RPL_ENDOFUSERS)
.Const(_SC("RPL_NOUSERS"), LIBIRC_RFC_RPL_NOUSERS)
.Const(_SC("RPL_TRACELINK"), LIBIRC_RFC_RPL_TRACELINK)
.Const(_SC("RPL_TRACECONNECTING"), LIBIRC_RFC_RPL_TRACECONNECTING)
.Const(_SC("RPL_TRACEHANDSHAKE"), LIBIRC_RFC_RPL_TRACEHANDSHAKE)
.Const(_SC("RPL_TRACEUNKNOWN"), LIBIRC_RFC_RPL_TRACEUNKNOWN)
.Const(_SC("RPL_TRACEOPERATOR"), LIBIRC_RFC_RPL_TRACEOPERATOR)
.Const(_SC("RPL_TRACEUSER"), LIBIRC_RFC_RPL_TRACEUSER)
.Const(_SC("RPL_TRACESERVER"), LIBIRC_RFC_RPL_TRACESERVER)
.Const(_SC("RPL_TRACESERVICE"), LIBIRC_RFC_RPL_TRACESERVICE)
.Const(_SC("RPL_TRACENEWTYPE"), LIBIRC_RFC_RPL_TRACENEWTYPE)
.Const(_SC("RPL_TRACECLASS"), LIBIRC_RFC_RPL_TRACECLASS)
.Const(_SC("RPL_TRACELOG"), LIBIRC_RFC_RPL_TRACELOG)
.Const(_SC("RPL_TRACEEND"), LIBIRC_RFC_RPL_TRACEEND)
.Const(_SC("RPL_STATSLINKINFO"), LIBIRC_RFC_RPL_STATSLINKINFO)
.Const(_SC("RPL_STATSCOMMANDS"), LIBIRC_RFC_RPL_STATSCOMMANDS)
.Const(_SC("RPL_ENDOFSTATS"), LIBIRC_RFC_RPL_ENDOFSTATS)
.Const(_SC("RPL_STATSUPTIME"), LIBIRC_RFC_RPL_STATSUPTIME)
.Const(_SC("RPL_STATSOLINE"), LIBIRC_RFC_RPL_STATSOLINE)
.Const(_SC("RPL_UMODEIS"), LIBIRC_RFC_RPL_UMODEIS)
.Const(_SC("RPL_SERVLIST"), LIBIRC_RFC_RPL_SERVLIST)
.Const(_SC("RPL_SERVLISTEND"), LIBIRC_RFC_RPL_SERVLISTEND)
.Const(_SC("RPL_LUSERCLIENT"), LIBIRC_RFC_RPL_LUSERCLIENT)
.Const(_SC("RPL_LUSEROP"), LIBIRC_RFC_RPL_LUSEROP)
.Const(_SC("RPL_LUSERUNKNOWN"), LIBIRC_RFC_RPL_LUSERUNKNOWN)
.Const(_SC("RPL_LUSERCHANNELS"), LIBIRC_RFC_RPL_LUSERCHANNELS)
.Const(_SC("RPL_LUSERME"), LIBIRC_RFC_RPL_LUSERME)
.Const(_SC("RPL_ADMINME"), LIBIRC_RFC_RPL_ADMINME)
.Const(_SC("RPL_ADMINLOC1"), LIBIRC_RFC_RPL_ADMINLOC1)
.Const(_SC("RPL_ADMINLOC2"), LIBIRC_RFC_RPL_ADMINLOC2)
.Const(_SC("RPL_ADMINEMAIL"), LIBIRC_RFC_RPL_ADMINEMAIL)
.Const(_SC("RPL_TRYAGAIN"), LIBIRC_RFC_RPL_TRYAGAIN)
.Const(_SC("ERR_NOSUCHNICK"), LIBIRC_RFC_ERR_NOSUCHNICK)
.Const(_SC("ERR_NOSUCHSERVER"), LIBIRC_RFC_ERR_NOSUCHSERVER)
.Const(_SC("ERR_NOSUCHCHANNEL"), LIBIRC_RFC_ERR_NOSUCHCHANNEL)
.Const(_SC("ERR_CANNOTSENDTOCHAN"), LIBIRC_RFC_ERR_CANNOTSENDTOCHAN)
.Const(_SC("ERR_TOOMANYCHANNELS"), LIBIRC_RFC_ERR_TOOMANYCHANNELS)
.Const(_SC("ERR_WASNOSUCHNICK"), LIBIRC_RFC_ERR_WASNOSUCHNICK)
.Const(_SC("ERR_TOOMANYTARGETS"), LIBIRC_RFC_ERR_TOOMANYTARGETS)
.Const(_SC("ERR_NOSUCHSERVICE"), LIBIRC_RFC_ERR_NOSUCHSERVICE)
.Const(_SC("ERR_NOORIGIN"), LIBIRC_RFC_ERR_NOORIGIN)
.Const(_SC("ERR_NORECIPIENT"), LIBIRC_RFC_ERR_NORECIPIENT)
.Const(_SC("ERR_NOTEXTTOSEND"), LIBIRC_RFC_ERR_NOTEXTTOSEND)
.Const(_SC("ERR_NOTOPLEVEL"), LIBIRC_RFC_ERR_NOTOPLEVEL)
.Const(_SC("ERR_WILDTOPLEVEL"), LIBIRC_RFC_ERR_WILDTOPLEVEL)
.Const(_SC("ERR_BADMASK"), LIBIRC_RFC_ERR_BADMASK)
.Const(_SC("ERR_UNKNOWNCOMMAND"), LIBIRC_RFC_ERR_UNKNOWNCOMMAND)
.Const(_SC("ERR_NOMOTD"), LIBIRC_RFC_ERR_NOMOTD)
.Const(_SC("ERR_NOADMININFO"), LIBIRC_RFC_ERR_NOADMININFO)
.Const(_SC("ERR_FILEERROR"), LIBIRC_RFC_ERR_FILEERROR)
.Const(_SC("ERR_NONICKNAMEGIVEN"), LIBIRC_RFC_ERR_NONICKNAMEGIVEN)
.Const(_SC("ERR_ERRONEUSNICKNAME"), LIBIRC_RFC_ERR_ERRONEUSNICKNAME)
.Const(_SC("ERR_NICKNAMEINUSE"), LIBIRC_RFC_ERR_NICKNAMEINUSE)
.Const(_SC("ERR_NICKCOLLISION"), LIBIRC_RFC_ERR_NICKCOLLISION)
.Const(_SC("ERR_UNAVAILRESOURCE"), LIBIRC_RFC_ERR_UNAVAILRESOURCE)
.Const(_SC("ERR_USERNOTINCHANNEL"), LIBIRC_RFC_ERR_USERNOTINCHANNEL)
.Const(_SC("ERR_NOTONCHANNEL"), LIBIRC_RFC_ERR_NOTONCHANNEL)
.Const(_SC("ERR_USERONCHANNEL"), LIBIRC_RFC_ERR_USERONCHANNEL)
.Const(_SC("ERR_NOLOGIN"), LIBIRC_RFC_ERR_NOLOGIN)
.Const(_SC("ERR_SUMMONDISABLED"), LIBIRC_RFC_ERR_SUMMONDISABLED)
.Const(_SC("ERR_USERSDISABLED"), LIBIRC_RFC_ERR_USERSDISABLED)
.Const(_SC("ERR_NOTREGISTERED"), LIBIRC_RFC_ERR_NOTREGISTERED)
.Const(_SC("ERR_NEEDMOREPARAMS"), LIBIRC_RFC_ERR_NEEDMOREPARAMS)
.Const(_SC("ERR_ALREADYREGISTRED"), LIBIRC_RFC_ERR_ALREADYREGISTRED)
.Const(_SC("ERR_NOPERMFORHOST"), LIBIRC_RFC_ERR_NOPERMFORHOST)
.Const(_SC("ERR_PASSWDMISMATCH"), LIBIRC_RFC_ERR_PASSWDMISMATCH)
.Const(_SC("ERR_YOUREBANNEDCREEP"), LIBIRC_RFC_ERR_YOUREBANNEDCREEP)
.Const(_SC("ERR_YOUWILLBEBANNED"), LIBIRC_RFC_ERR_YOUWILLBEBANNED)
.Const(_SC("ERR_KEYSET"), LIBIRC_RFC_ERR_KEYSET)
.Const(_SC("ERR_CHANNELISFULL"), LIBIRC_RFC_ERR_CHANNELISFULL)
.Const(_SC("ERR_UNKNOWNMODE"), LIBIRC_RFC_ERR_UNKNOWNMODE)
.Const(_SC("ERR_INVITEONLYCHAN"), LIBIRC_RFC_ERR_INVITEONLYCHAN)
.Const(_SC("ERR_BANNEDFROMCHAN"), LIBIRC_RFC_ERR_BANNEDFROMCHAN)
.Const(_SC("ERR_BADCHANNELKEY"), LIBIRC_RFC_ERR_BADCHANNELKEY)
.Const(_SC("ERR_BADCHANMASK"), LIBIRC_RFC_ERR_BADCHANMASK)
.Const(_SC("ERR_NOCHANMODES"), LIBIRC_RFC_ERR_NOCHANMODES)
.Const(_SC("ERR_BANLISTFULL"), LIBIRC_RFC_ERR_BANLISTFULL)
.Const(_SC("ERR_NOPRIVILEGES"), LIBIRC_RFC_ERR_NOPRIVILEGES)
.Const(_SC("ERR_CHANOPRIVSNEEDED"), LIBIRC_RFC_ERR_CHANOPRIVSNEEDED)
.Const(_SC("ERR_CANTKILLSERVER"), LIBIRC_RFC_ERR_CANTKILLSERVER)
.Const(_SC("ERR_RESTRICTED"), LIBIRC_RFC_ERR_RESTRICTED)
.Const(_SC("ERR_UNIQOPPRIVSNEEDED"), LIBIRC_RFC_ERR_UNIQOPPRIVSNEEDED)
.Const(_SC("ERR_NOOPERHOST"), LIBIRC_RFC_ERR_NOOPERHOST)
.Const(_SC("ERR_UMODEUNKNOWNFLAG"), LIBIRC_RFC_ERR_UMODEUNKNOWNFLAG)
.Const(_SC("ERR_USERSDONTMATCH"), LIBIRC_RFC_ERR_USERSDONTMATCH)
);
SessionProcess(); // Update the sessions and pool for events
}
} // Namespace:: SqMod
@ -471,20 +192,9 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * functions, PluginCall
OutputMessage("Legal: %s", SQIRC_COPYRIGHT);
OutputMessage("--------------------------------------------------------------------");
puts("");
// Attempt to find the host plug-in ID
const int host_plugin_id = functions->FindPlugin(SQMOD_HOST_NAME);
// See if our plug-in was loaded after the host plug-in
if (host_plugin_id < 0)
// Make sure that the module was loaded after the host plug-in
if (!CheckModuleOrder(functions, info->pluginId, SQIRC_NAME))
{
OutputError("%s could find the host plug-in", SQIRC_NAME);
// Don't load!
return SQMOD_FAILURE;
}
// Should never reach this point but just in case
else if (static_cast< Uint32 >(host_plugin_id) > info->pluginId)
{
OutputError("%s loaded after the host plug-in", SQIRC_NAME);
// Don't load!
return SQMOD_FAILURE;
}
#ifdef SQMOD_OS_WINDOWS

View File

@ -440,24 +440,24 @@ Int32 Session::CmdNick(CSStr nick)
Object Session::GetNextTry() const
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Attempt to push a time-stamp instance on the stack
SqMod_PushTimestamp(_SqVM, m_NextTry);
SqMod_PushTimestamp(DefaultVM::Get(), m_NextTry);
// Obtain the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ------------------------------------------------------------------------------------------------
void Session::SetNextTry(Object & tm)
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push the specified object onto the stack
Var< Object >::push(_SqVM, tm);
Var< Object >::push(DefaultVM::Get(), tm);
// The resulted times-tamp value
Int64 microseconds = 0;
// Attempt to get the numeric value inside the specified object
if (SQ_FAILED(SqMod_GetTimestamp(_SqVM, -1, &microseconds)))
if (SQ_FAILED(SqMod_GetTimestamp(DefaultVM::Get(), -1, &microseconds)))
{
STHROWF("Invalid time-stamp specified");
}
@ -469,19 +469,19 @@ void Session::SetNextTry(Object & tm)
Object Session::GetSessionTime() const
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Attempt to push a time-stamp instance on the stack
if (m_SessionTime)
{
SqMod_PushTimestamp(_SqVM, SqMod_GetEpochTimeMicro() - m_SessionTime);
SqMod_PushTimestamp(DefaultVM::Get(), SqMod_GetEpochTimeMicro() - m_SessionTime);
}
// This session was not connected yet
else
{
SqMod_PushTimestamp(_SqVM, 0);
SqMod_PushTimestamp(DefaultVM::Get(), 0);
}
// Obtain the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ------------------------------------------------------------------------------------------------
@ -682,7 +682,7 @@ void Session::ForwardEvent(Function & listener, CCStr event, CCStr origin, CCStr
origin = _SC("");
}
// Each event must have an array of parameters (empty or not)
Array parameters(_SqVM, count);
Array parameters(DefaultVM::Get(), count);
// Are the any parameters?
if (params && count > 0)
{
@ -726,7 +726,7 @@ void Session::ForwardEvent(Function & listener, Uint32 event,
origin = _SC("");
}
// Each event must have an array of parameters (empty or not)
Array parameters(_SqVM, count);
Array parameters(DefaultVM::Get(), count);
// Are the any parameters?
if (params && count > 0)
{
@ -1181,4 +1181,104 @@ SQInteger Session::CmdNoticeF(HSQUIRRELVM vm)
return 1;
}
/* -----------------------------------------------------------------------------------------------
* Helper function used to avoid having to include the session header.
*/
void SessionProcess()
{
Session::Process();
}
/* -----------------------------------------------------------------------------------------------
* Helper function used to avoid having to include the session header.
*/
void SessionTerminate()
{
Session::Terminate();
}
// ================================================================================================
void Register_Session(Table & ircns)
{
ircns.Bind(_SC("Session"), Class< Session, NoCopy< Session > >(ircns.GetVM(), _SC("SqIrcSession"))
// Constructors
.Ctor()
// Core Meta-methods
.Func(_SC("_cmp"), &Session::Cmp)
.SquirrelFunc(_SC("_typename"), &Session::Typename)
.Func(_SC("_tostring"), &Session::ToString)
// Properties
.Prop(_SC("Valid"), &Session::IsValid)
.Prop(_SC("Connected"), &Session::IsConnected)
.Prop(_SC("Tag"), &Session::GetTag, &Session::SetTag)
.Prop(_SC("Data"), &Session::GetData, &Session::SetData)
.Prop(_SC("Server"), &Session::GetServer, &Session::SetServer)
.Prop(_SC("Password"), &Session::GetPassword, &Session::SetPassword)
.Prop(_SC("Nick"), &Session::GetNick, &Session::SetNick)
.Prop(_SC("User"), &Session::GetUser, &Session::SetUser)
.Prop(_SC("Name"), &Session::GetName, &Session::SetName)
.Prop(_SC("Port"), &Session::GetPort, &Session::SetPort)
.Prop(_SC("PoolTime"), &Session::GetPoolTime, &Session::SetPoolTime)
.Prop(_SC("LastCode"), &Session::GetLastCode)
.Prop(_SC("Tries"), &Session::GetTries, &Session::SetTries)
.Prop(_SC("Wait"), &Session::GetWait, &Session::SetWait)
.Prop(_SC("LeftTries"), &Session::GetLeftTries, &Session::SetLeftTries)
.Prop(_SC("NextTry"), &Session::GetNextTry, &Session::SetNextTry)
.Prop(_SC("SessionTime"), &Session::GetSessionTime)
.Prop(_SC("Reconnecting"), &Session::GetReconnect)
.Prop(_SC("IPv6"), &Session::GetIPv6)
.Prop(_SC("CtcpVersion"), (void (Session::*)(void))(nullptr), &Session::SetCtcpVersion)
.Prop(_SC("ErrNo"), &Session::GetErrNo)
.Prop(_SC("ErrStr"), &Session::GetErrStr)
// Member Methods
.Func(_SC("Bind"), &Session::BindEvent)
.Func(_SC("GetEvent"), &Session::GetEvent)
.Func(_SC("Disconnect"), &Session::Disconnect)
.Func(_SC("CmdPart"), &Session::CmdPart)
.Func(_SC("CmdInvite"), &Session::CmdInvite)
.Func(_SC("CmdNames"), &Session::CmdNames)
.Func(_SC("CmdMsg"), &Session::CmdMsg)
.Func(_SC("CmdMe"), &Session::CmdMe)
.Func(_SC("CmdNotice"), &Session::CmdNotice)
.Func(_SC("CmdCtcpRequest"), &Session::CmdCtcpRequest)
.Func(_SC("CmdCtcpReply"), &Session::CmdCtcpReply)
.Func(_SC("CmdNick"), &Session::CmdNick)
.Func(_SC("CmdWhois"), &Session::CmdWhois)
.Func(_SC("SendRaw"), &Session::SendRaw)
.Func(_SC("DestroyDcc"), &Session::DestroyDcc)
.Func(_SC("SetCtcpVersion"), &Session::SetCtcpVersion)
.Func(_SC("SetOption"), &Session::SetOption)
.Func(_SC("ResetOption"), &Session::ResetOption)
// Member Overloads
.Overload< Int32 (Session::*)(void) >(_SC("Connect"), &Session::Connect)
.Overload< Int32 (Session::*)(CSStr, Uint32, CSStr) >(_SC("Connect"), &Session::Connect)
.Overload< Int32 (Session::*)(CSStr, Uint32, CSStr, CSStr) >(_SC("Connect"), &Session::Connect)
.Overload< Int32 (Session::*)(CSStr, Uint32, CSStr, CSStr, CSStr) >(_SC("Connect"), &Session::Connect)
.Overload< Int32 (Session::*)(CSStr, Uint32, CSStr, CSStr, CSStr, CSStr) >(_SC("Connect"), &Session::Connect)
.Overload< Int32 (Session::*)(void) >(_SC("Connect6"), &Session::Connect6)
.Overload< Int32 (Session::*)(CSStr, Uint32, CSStr) >(_SC("Connect6"), &Session::Connect6)
.Overload< Int32 (Session::*)(CSStr, Uint32, CSStr, CSStr) >(_SC("Connect6"), &Session::Connect6)
.Overload< Int32 (Session::*)(CSStr, Uint32, CSStr, CSStr, CSStr) >(_SC("Connect6"), &Session::Connect6)
.Overload< Int32 (Session::*)(CSStr, Uint32, CSStr, CSStr, CSStr, CSStr) >(_SC("Connect6"), &Session::Connect6)
.Overload< Int32 (Session::*)(CSStr) >(_SC("CmdJoin"), &Session::CmdJoin)
.Overload< Int32 (Session::*)(CSStr, CSStr) >(_SC("CmdJoin"), &Session::CmdJoin)
.Overload< Int32 (Session::*)(void) >(_SC("CmdList"), &Session::CmdList)
.Overload< Int32 (Session::*)(CSStr) >(_SC("CmdList"), &Session::CmdList)
.Overload< Int32 (Session::*)(CSStr) >(_SC("CmdTopic"), &Session::CmdTopic)
.Overload< Int32 (Session::*)(CSStr, CSStr) >(_SC("CmdTopic"), &Session::CmdTopic)
.Overload< Int32 (Session::*)(CSStr) >(_SC("CmdChannelMode"), &Session::CmdChannelMode)
.Overload< Int32 (Session::*)(CSStr, CSStr) >(_SC("CmdChannelMode"), &Session::CmdChannelMode)
.Overload< Int32 (Session::*)(void) >(_SC("CmdUserMode"), &Session::CmdUserMode)
.Overload< Int32 (Session::*)(CSStr) >(_SC("CmdUserMode"), &Session::CmdUserMode)
.Overload< Int32 (Session::*)(CSStr, CSStr) >(_SC("CmdKick"), &Session::CmdKick)
.Overload< Int32 (Session::*)(CSStr, CSStr, CSStr) >(_SC("CmdKick"), &Session::CmdKick)
.Overload< Int32 (Session::*)(void) >(_SC("CmdQuit"), &Session::CmdQuit)
.Overload< Int32 (Session::*)(CSStr) >(_SC("CmdQuit"), &Session::CmdQuit)
// Squirrel Methods
.SquirrelFunc(_SC("CmdMsgF"), &Session::CmdMsgF)
.SquirrelFunc(_SC("CmdMeF"), &Session::CmdMeF)
.SquirrelFunc(_SC("CmdNoticeF"), &Session::CmdNoticeF)
);
}
} // Namespace:: SqMod

View File

@ -43,7 +43,7 @@ void SqThrowLast(HSQUIRRELVM vm, CSStr msg)
}
// ------------------------------------------------------------------------------------------------
Object SqFromJSON(HSQUIRRELVM vm, json_t * jval)
Object SqFromJSON(HSQUIRRELVM /*vm*/, json_t * jval)
{
switch (json_typeof(jval))
{

View File

@ -23,9 +23,9 @@ Object JArray::ToString() const
// Remember the current stack size
const StackGuard sg;
// Transform the string into a script object
sq_pushstring(_SqVM, csg.mPtr ? csg.mPtr : _SC(""), -1);
sq_pushstring(DefaultVM::Get(), csg.mPtr ? csg.mPtr : _SC(""), -1);
// Return the created script object
return Var< Object >(_SqVM, -1).value;
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ================================================================================================

View File

@ -23,9 +23,9 @@ Object JObject::ToString() const
// Remember the current stack size
const StackGuard sg;
// Transform the string into a script object
sq_pushstring(_SqVM, csg.mPtr ? csg.mPtr : _SC(""), -1);
sq_pushstring(DefaultVM::Get(), csg.mPtr ? csg.mPtr : _SC(""), -1);
// Return the created script object
return Var< Object >(_SqVM, -1).value;
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ================================================================================================

View File

@ -23,9 +23,9 @@ Object JValue::ToString() const
// Remember the current stack size
const StackGuard sg;
// Transform the string into a script object
sq_pushstring(_SqVM, csg.mPtr ? csg.mPtr : _SC(""), -1);
sq_pushstring(DefaultVM::Get(), csg.mPtr ? csg.mPtr : _SC(""), -1);
// Return the created script object
return Var< Object >(_SqVM, -1).value;
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ------------------------------------------------------------------------------------------------

View File

@ -8,68 +8,91 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Register the module API under the specified virtual machine.
*/
void RegisterAPI(HSQUIRRELVM vm);
// ------------------------------------------------------------------------------------------------
extern void Register_Common(Table & jns);
extern void Register_JArray(Table & jns);
extern void Register_JObject(Table & jns);
extern void Register_JValue(Table & jns);
/* ------------------------------------------------------------------------------------------------
* Initialize the plug-in by obtaining the API provided by the host plug-in.
* Register the module API under the obtained virtual machine.
*/
void OnSquirrelInitialize()
static bool RegisterAPI()
{
// Attempt to import the plug-in API exported by the host plug-in
_SqMod = sq_api_import(_Func);
// Did we failed to obtain the plug-in exports?
if (!_SqMod)
// Make sure there's a valid virtual machine before proceeding
if (!DefaultVM::Get())
{
OutputError("Failed to attach [%s] on host plug-in.", SQJSON_NAME);
}
else
{
// Expand the Squirrel plug-in API into global functions
sqmod_api_expand(_SqMod);
// Obtain the Squirrel API
_SqAPI = SqMod_GetSquirrelAPI();
// Expand the Squirrel API into global functions
sq_api_expand(_SqAPI);
OutputError("%s: Cannot register API without a valid virtual machine", SQJSON_NAME);
// Registration failed
return false;
}
Table jns;
Register_Common(jns);
Register_JArray(jns);
Register_JObject(jns);
Register_JValue(jns);
RootTable().Bind(_SC("SqJSON"), jns);
Sqrat::ConstTable()
.Const(_SC("JSON_OBJECT"), JSON_OBJECT)
.Const(_SC("JSON_ARRAY"), JSON_ARRAY)
.Const(_SC("JSON_STRING"), JSON_STRING)
.Const(_SC("JSON_INTEGER"), JSON_INTEGER)
.Const(_SC("JSON_REAL"), JSON_REAL)
.Const(_SC("JSON_TRUE"), JSON_TRUE)
.Const(_SC("JSON_FALSE"), JSON_FALSE)
.Const(_SC("JSON_NULL"), JSON_NULL);
// Registration was successful
return true;
}
/* ------------------------------------------------------------------------------------------------
* Load the module on the virtual machine provided by the host module.
*/
void OnSquirrelLoad()
static bool OnSquirrelLoad()
{
// Make sure that we have a valid plug-in API
if (!_SqMod)
// Make sure that we have a valid module API
if (!SqMod_GetSquirrelVM)
{
return; // Unable to proceed.
OutputError("%s: Cannot obtain the Squirrel virtual machine without the module API", SQJSON_NAME);
// Unable to proceed!
return false;
}
// Obtain the Squirrel API and VM
_SqVM = SqMod_GetSquirrelVM();
// Obtain the Squirrel virtual machine from the host plug-in
DefaultVM::Set(SqMod_GetSquirrelVM());
// Make sure that a valid virtual machine exists
if (!_SqVM)
if (!DefaultVM::Get())
{
return; // Unable to proceed.
OutputError("%s: Squirrel virtual machine obtained from the host plug-in is invalid", SQJSON_NAME);
// Unable to proceed!
return false;
}
// Set this as the default database
DefaultVM::Set(_SqVM);
// Prevent common null objects from using dead virtual machines
NullArray() = Array();
NullTable() = Table();
NullObject() = Object();
NullFunction() = Function();
// Register the module API
RegisterAPI(_SqVM);
// Notify about the current status
OutputMessage("Registered: %s", SQJSON_NAME);
if (RegisterAPI())
{
OutputMessage("Registered: %s", SQJSON_NAME);
}
else
{
return false;
}
// At this point, the module was successfully loaded
return true;
}
/* ------------------------------------------------------------------------------------------------
* The virtual machine is about to be terminated and script resources should be released.
*/
void OnSquirrelTerminate()
static void OnSquirrelTerminate()
{
OutputMessage("Terminating: %s", SQJSON_NAME);
// Release null objects just in case
@ -82,31 +105,12 @@ void OnSquirrelTerminate()
/* ------------------------------------------------------------------------------------------------
* The virtual machined was closed and all memory associated with it was released.
*/
void OnSquirrelReleased()
static void OnSquirrelReleased()
{
// Release the current virtual machine, if any
DefaultVM::Set(nullptr);
}
/* ------------------------------------------------------------------------------------------------
* Validate the module API to make sure we don't run into issues.
*/
bool CheckAPIVer(CCStr ver)
{
// Obtain the numeric representation of the API version
const LongI vernum = std::strtol(ver, nullptr, 10);
// Check against version mismatch
if (vernum == SQMOD_API_VER)
{
return true;
}
// Log the incident
OutputError("API version mismatch on %s", SQJSON_NAME);
OutputMessage("=> Requested: %ld Have: %ld", vernum, SQMOD_API_VER);
// Invoker should not attempt to communicate through the module API
return false;
}
/* ------------------------------------------------------------------------------------------------
* React to command sent by other plug-ins.
*/
@ -115,20 +119,33 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
switch(command_identifier)
{
case SQMOD_INITIALIZE_CMD:
if (CheckAPIVer(message))
{
if (CheckModuleAPIVer(message, SQJSON_NAME))
{
OnSquirrelInitialize();
try
{
ImportModuleAPI(_Func, SQJSON_NAME);
}
catch (const Sqrat::Exception & e)
{
OutputError("%s", e.what());
// Failed to initialize
return 0;
}
}
break;
} break;
case SQMOD_LOAD_CMD:
OnSquirrelLoad();
break;
{
return OnSquirrelLoad();
} break;
case SQMOD_TERMINATE_CMD:
{
OnSquirrelTerminate();
break;
} break;
case SQMOD_RELEASED_CMD:
{
OnSquirrelReleased();
break;
} break;
default: break;
}
return 1;
@ -139,9 +156,12 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
*/
static uint8_t OnServerInitialise()
{
return 1;
return 1; // Initialization was successful
}
/* ------------------------------------------------------------------------------------------------
* The server is about to shutdown gracefully.
*/
static void OnServerShutdown(void)
{
// The server may still send callbacks
@ -150,35 +170,6 @@ static void OnServerShutdown(void)
_Clbk->OnPluginCommand = nullptr;
}
// ------------------------------------------------------------------------------------------------
extern void Register_Common(Table & jns);
extern void Register_JArray(Table & jns);
extern void Register_JObject(Table & jns);
extern void Register_JValue(Table & jns);
// ------------------------------------------------------------------------------------------------
void RegisterAPI(HSQUIRRELVM vm)
{
Table jns(vm);
Register_Common(jns);
Register_JArray(jns);
Register_JObject(jns);
Register_JValue(jns);
RootTable(vm).Bind(_SC("SqJSON"), jns);
Sqrat::ConstTable(vm)
.Const(_SC("JSON_OBJECT"), JSON_OBJECT)
.Const(_SC("JSON_ARRAY"), JSON_ARRAY)
.Const(_SC("JSON_STRING"), JSON_STRING)
.Const(_SC("JSON_INTEGER"), JSON_INTEGER)
.Const(_SC("JSON_REAL"), JSON_REAL)
.Const(_SC("JSON_TRUE"), JSON_TRUE)
.Const(_SC("JSON_FALSE"), JSON_FALSE)
.Const(_SC("JSON_NULL"), JSON_NULL);
}
} // Namespace:: SqMod
// ------------------------------------------------------------------------------------------------
@ -193,20 +184,9 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * functions, PluginCall
OutputMessage("Legal: %s", SQJSON_COPYRIGHT);
OutputMessage("--------------------------------------------------------------------");
std::puts("");
// Attempt to find the host plug-in ID
const int host_plugin_id = functions->FindPlugin(SQMOD_HOST_NAME);
// See if our plug-in was loaded after the host plug-in
if (host_plugin_id < 0)
// Make sure that the module was loaded after the host plug-in
if (!CheckModuleOrder(functions, info->pluginId, SQJSON_NAME))
{
OutputError("%s could find the host plug-in", SQJSON_NAME);
// Don't load!
return SQMOD_FAILURE;
}
// Should never reach this point but just in case
else if (static_cast< Uint32 >(host_plugin_id) > info->pluginId)
{
OutputError("%s loaded after the host plug-in", SQJSON_NAME);
// Don't load!
return SQMOD_FAILURE;
}
// Store server proxies

View File

@ -11,153 +11,21 @@
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Register the module API under the specified virtual machine.
* Register the module API under the obtained virtual machine.
*/
void RegisterAPI(HSQUIRRELVM vm);
/* ------------------------------------------------------------------------------------------------
* Initialize the plug-in by obtaining the API provided by the host plug-in.
*/
void OnSquirrelInitialize()
static bool RegisterAPI()
{
// Attempt to import the plug-in API exported by the host plug-in
_SqMod = sq_api_import(_Func);
// Did we failed to obtain the plug-in exports?
if (!_SqMod)
// Make sure there's a valid virtual machine before proceeding
if (!DefaultVM::Get())
{
OutputError("Failed to attach [%s] on host plug-in.", SQMG_NAME);
OutputError("%s: Cannot register API without a valid virtual machine", SQMG_NAME);
// Registration failed
return false;
}
else
{
// Expand the Squirrel plug-in API into global functions
sqmod_api_expand(_SqMod);
// Obtain the Squirrel API
_SqAPI = SqMod_GetSquirrelAPI();
// Expand the Squirrel API into global functions
sq_api_expand(_SqAPI);
}
}
/* ------------------------------------------------------------------------------------------------
* Load the module on the virtual machine provided by the host module.
*/
void OnSquirrelLoad()
{
// Make sure that we have a valid plug-in API
if (!_SqMod)
{
return; // Unable to proceed.
}
// Obtain the Squirrel API and VM
_SqVM = SqMod_GetSquirrelVM();
// Make sure that a valid virtual machine exists
if (!_SqVM)
{
return; // Unable to proceed.
}
// Set this as the default database
DefaultVM::Set(_SqVM);
// Prevent common null objects from using dead virtual machines
NullArray() = Array();
NullTable() = Table();
NullObject() = Object();
NullFunction() = Function();
// Register the module API
RegisterAPI(_SqVM);
// Notify about the current status
OutputMessage("Registered: %s", SQMG_NAME);
}
Table mgns;
/* ------------------------------------------------------------------------------------------------
* The virtual machine is about to be terminated and script resources should be released.
*/
void OnSquirrelTerminate()
{
OutputMessage("Terminating: %s", SQMG_NAME);
// Release null objects just in case
NullObject().Release();
NullTable().Release();
NullArray().Release();
NullFunction().ReleaseGently();
}
/* ------------------------------------------------------------------------------------------------
* The virtual machined was closed and all memory associated with it was released.
*/
void OnSquirrelReleased()
{
// Release the current virtual machine, if any
DefaultVM::Set(nullptr);
}
/* ------------------------------------------------------------------------------------------------
* Validate the module API to make sure we don't run into issues.
*/
bool CheckAPIVer(CCStr ver)
{
// Obtain the numeric representation of the API version
const LongI vernum = std::strtol(ver, nullptr, 10);
// Check against version mismatch
if (vernum == SQMOD_API_VER)
{
return true;
}
// Log the incident
OutputError("API version mismatch on %s", SQMG_NAME);
OutputMessage("=> Requested: %ld Have: %ld", vernum, SQMOD_API_VER);
// Invoker should not attempt to communicate through the module API
return false;
}
/* ------------------------------------------------------------------------------------------------
* React to command sent by other plug-ins.
*/
static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
{
switch(command_identifier)
{
case SQMOD_INITIALIZE_CMD:
if (CheckAPIVer(message))
{
OnSquirrelInitialize();
}
break;
case SQMOD_LOAD_CMD:
OnSquirrelLoad();
break;
case SQMOD_TERMINATE_CMD:
OnSquirrelTerminate();
break;
case SQMOD_RELEASED_CMD:
OnSquirrelReleased();
break;
default: break;
}
return 1;
}
/* ------------------------------------------------------------------------------------------------
* The server was initialized and this plug-in was loaded successfully.
*/
static uint8_t OnServerInitialise()
{
return 1;
}
static void OnServerShutdown(void)
{
// The server may still send callbacks
_Clbk->OnServerInitialise = nullptr;
_Clbk->OnServerShutdown = nullptr;
_Clbk->OnPluginCommand = nullptr;
}
// ------------------------------------------------------------------------------------------------
void RegisterAPI(HSQUIRRELVM vm)
{
Table mgns(vm);
mgns.Bind(_SC("Manager"), Class< Manager >(vm, _SC("SqMgManager"))
mgns.Bind(_SC("Manager"), Class< Manager >(mgns,GetVM(), _SC("SqMgManager"))
// Constructors
.Ctor()
.Ctor< const Manager & >()
@ -176,7 +44,7 @@ void RegisterAPI(HSQUIRRELVM vm)
.Overload< Connection (Manager::*)(CSStr, Uint32) const >(_SC("Connect"), &Manager::Connect)
);
mgns.Bind(_SC("Connection"), Class< Connection >(vm, _SC("SqMgConnection"))
mgns.Bind(_SC("Connection"), Class< Connection >(mgns,GetVM(), _SC("SqMgConnection"))
// Constructors
.Ctor()
.Ctor< const Connection & >()
@ -190,9 +58,9 @@ void RegisterAPI(HSQUIRRELVM vm)
//.Func(_SC("Check"), &Connection::Check)
);
RootTable(vm).Bind(_SC("SqMg"), mgns);
RootTable().Bind(_SC("SqMg"), mgns);
ConstTable(vm).Enum(_SC("EMgF"), Enumeration(vm)
ConstTable().Enum(_SC("EMgF"), Enumeration()
.Const(_SC("LISTENING"), MG_F_LISTENING)
.Const(_SC("UDP"), MG_F_UDP)
.Const(_SC("RESOLVING"), MG_F_RESOLVING)
@ -213,7 +81,7 @@ void RegisterAPI(HSQUIRRELVM vm)
.Const(_SC("USER_6"), MG_F_USER_6)
);
ConstTable(vm).Enum(_SC("MgEv"), Enumeration(vm)
ConstTable().Enum(_SC("MgEv"), Enumeration()
.Const(_SC("UNKNOWN"), static_cast< Int32 >(MGEV_UNKNOWN))
.Const(_SC("POLL"), static_cast< Int32 >(MGCE_POLL))
.Const(_SC("ACCEPT"), static_cast< Int32 >(MGCE_ACCEPT))
@ -259,7 +127,131 @@ void RegisterAPI(HSQUIRRELVM vm)
.Const(_SC("COAP_ACK"), static_cast< Int32 >(MGCE_COAP_ACK))
.Const(_SC("COAP_RST"), static_cast< Int32 >(MGCE_COAP_RST))
.Const(_SC("MAX"), static_cast< Int32 >(MGCE_MAX))
);
);
// Registration was successful
return true;
}
/* ------------------------------------------------------------------------------------------------
* Load the module on the virtual machine provided by the host module.
*/
static bool OnSquirrelLoad()
{
// Make sure that we have a valid module API
if (!SqMod_GetSquirrelVM)
{
OutputError("%s: Cannot obtain the Squirrel virtual machine without the module API", SQMG_NAME);
// Unable to proceed!
return false;
}
// Obtain the Squirrel virtual machine from the host plug-in
DefaultVM::Set(SqMod_GetSquirrelVM());
// Make sure that a valid virtual machine exists
if (!DefaultVM::Get())
{
OutputError("%s: Squirrel virtual machine obtained from the host plug-in is invalid", SQMG_NAME);
// Unable to proceed!
return false;
}
// Prevent common null objects from using dead virtual machines
NullArray() = Array();
NullTable() = Table();
NullObject() = Object();
NullFunction() = Function();
// Register the module API
if (RegisterAPI())
{
OutputMessage("Registered: %s", SQMG_NAME);
}
else
{
return false;
}
// At this point, the module was successfully loaded
return true;
}
/* ------------------------------------------------------------------------------------------------
* The virtual machine is about to be terminated and script resources should be released.
*/
static void OnSquirrelTerminate()
{
OutputMessage("Terminating: %s", SQMG_NAME);
// Release null objects just in case
NullObject().Release();
NullTable().Release();
NullArray().Release();
NullFunction().ReleaseGently();
// Release script resources...
}
/* ------------------------------------------------------------------------------------------------
* The virtual machined was closed and all memory associated with it was released.
*/
static void OnSquirrelReleased()
{
// Release the current virtual machine, if any
DefaultVM::Set(nullptr);
}
/* ------------------------------------------------------------------------------------------------
* React to command sent by other plug-ins.
*/
static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
{
switch(command_identifier)
{
case SQMOD_INITIALIZE_CMD:
{
if (CheckModuleAPIVer(message, SQMG_NAME))
{
try
{
ImportModuleAPI(_Func, SQMG_NAME);
}
catch (const Sqrat::Exception & e)
{
OutputError("%s", e.what());
// Failed to initialize
return 0;
}
}
} break;
case SQMOD_LOAD_CMD:
{
return OnSquirrelLoad();
} break;
case SQMOD_TERMINATE_CMD:
{
OnSquirrelTerminate();
} break;
case SQMOD_RELEASED_CMD:
{
OnSquirrelReleased();
} break;
default: break;
}
return 1;
}
/* ------------------------------------------------------------------------------------------------
* The server was initialized and this plug-in was loaded successfully.
*/
static uint8_t OnServerInitialise()
{
return 1; // Initialization was successful
}
/* ------------------------------------------------------------------------------------------------
* The server is about to shutdown gracefully.
*/
static void OnServerShutdown(void)
{
// The server may still send callbacks
_Clbk->OnServerInitialise = nullptr;
_Clbk->OnServerShutdown = nullptr;
_Clbk->OnPluginCommand = nullptr;
}
} // Namespace:: SqMod
@ -276,20 +268,9 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * functions, PluginCall
OutputMessage("Legal: %s", SQMG_COPYRIGHT);
OutputMessage("--------------------------------------------------------------------");
std::puts("");
// Attempt to find the host plug-in ID
const int host_plugin_id = functions->FindPlugin(SQMOD_HOST_NAME);
// See if our plug-in was loaded after the host plug-in
if (host_plugin_id < 0)
// Make sure that the module was loaded after the host plug-in
if (!CheckModuleOrder(functions, info->pluginId, SQMG_NAME))
{
OutputError("%s could find the host plug-in", SQMG_NAME);
// Don't load!
return SQMOD_FAILURE;
}
// Should never reach this point but just in case
else if (static_cast< Uint32 >(host_plugin_id) > info->pluginId)
{
OutputError("%s loaded after the host plug-in", SQMG_NAME);
// Don't load!
return SQMOD_FAILURE;
}
// Store server proxies

View File

@ -314,11 +314,11 @@ Object EntryDataList::GetLong() const
STHROWF("Unsupported conversion from (%s) to (uint64)", AsTypeStr(m_Elem->entry_data.type));
}
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push a long integer instance with the requested value on the stack
SqMod_PushULongObject(_SqVM, longint);
SqMod_PushULongObject(DefaultVM::Get(), longint);
// Get the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ------------------------------------------------------------------------------------------------

View File

@ -9,67 +9,65 @@
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Register the module API under the specified virtual machine.
* Register the module API under the obtained virtual machine.
*/
void RegisterAPI(HSQUIRRELVM vm);
/* ------------------------------------------------------------------------------------------------
* Initialize the plug-in by obtaining the API provided by the host plug-in.
*/
void OnSquirrelInitialize()
static bool RegisterAPI()
{
// Attempt to import the plug-in API exported by the host plug-in
_SqMod = sq_api_import(_Func);
// Did we failed to obtain the plug-in exports?
if (!_SqMod)
// Make sure there's a valid virtual machine before proceeding
if (!DefaultVM::Get())
{
OutputError("Failed to attach [%s] on host plug-in.", SQMMDB_NAME);
}
else
{
// Expand the Squirrel plug-in API into global functions
sqmod_api_expand(_SqMod);
// Obtain the Squirrel API
_SqAPI = SqMod_GetSquirrelAPI();
// Expand the Squirrel API into global functions
sq_api_expand(_SqAPI);
OutputError("%s: Cannot register API without a valid virtual machine", SQMMDB_NAME);
// Registration failed
return false;
}
// Registration was successful
return true;
}
/* ------------------------------------------------------------------------------------------------
* Load the module on the virtual machine provided by the host module.
*/
void OnSquirrelLoad()
static bool OnSquirrelLoad()
{
// Make sure that we have a valid plug-in API
if (!_SqMod)
// Make sure that we have a valid module API
if (!SqMod_GetSquirrelVM)
{
return; // Unable to proceed.
OutputError("%s: Cannot obtain the Squirrel virtual machine without the module API", SQMMDB_NAME);
// Unable to proceed!
return false;
}
// Obtain the Squirrel API and VM
_SqVM = SqMod_GetSquirrelVM();
// Obtain the Squirrel virtual machine from the host plug-in
DefaultVM::Set(SqMod_GetSquirrelVM());
// Make sure that a valid virtual machine exists
if (!_SqVM)
if (!DefaultVM::Get())
{
return; // Unable to proceed.
OutputError("%s: Squirrel virtual machine obtained from the host plug-in is invalid", SQMMDB_NAME);
// Unable to proceed!
return false;
}
// Set this as the default database
DefaultVM::Set(_SqVM);
// Prevent common null objects from using dead virtual machines
NullArray() = Array();
NullTable() = Table();
NullObject() = Object();
NullFunction() = Function();
// Register the module API
RegisterAPI(_SqVM);
// Notify about the current status
OutputMessage("Registered: %s", SQMMDB_NAME);
if (RegisterAPI())
{
OutputMessage("Registered: %s", SQMMDB_NAME);
}
else
{
return false;
}
// At this point, the module was successfully loaded
return true;
}
/* ------------------------------------------------------------------------------------------------
* The virtual machine is about to be terminated and script resources should be released.
*/
void OnSquirrelTerminate()
static void OnSquirrelTerminate()
{
OutputMessage("Terminating: %s", SQMMDB_NAME);
// Release null objects just in case
@ -77,36 +75,18 @@ void OnSquirrelTerminate()
NullTable().Release();
NullArray().Release();
NullFunction().ReleaseGently();
// Release script resources...
}
/* ------------------------------------------------------------------------------------------------
* The virtual machined was closed and all memory associated with it was released.
*/
void OnSquirrelReleased()
static void OnSquirrelReleased()
{
// Release the current virtual machine, if any
DefaultVM::Set(nullptr);
}
/* ------------------------------------------------------------------------------------------------
* Validate the module API to make sure we don't run into issues.
*/
bool CheckAPIVer(CCStr ver)
{
// Obtain the numeric representation of the API version
const LongI vernum = std::strtol(ver, nullptr, 10);
// Check against version mismatch
if (vernum == SQMOD_API_VER)
{
return true;
}
// Log the incident
OutputError("API version mismatch on %s", SQMMDB_NAME);
OutputMessage("=> Requested: %ld Have: %ld", vernum, SQMOD_API_VER);
// Invoker should not attempt to communicate through the module API
return false;
}
/* ------------------------------------------------------------------------------------------------
* React to command sent by other plug-ins.
*/
@ -115,20 +95,33 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
switch(command_identifier)
{
case SQMOD_INITIALIZE_CMD:
if (CheckAPIVer(message))
{
if (CheckModuleAPIVer(message, SQMMDB_NAME))
{
OnSquirrelInitialize();
try
{
ImportModuleAPI(_Func, SQMMDB_NAME);
}
catch (const Sqrat::Exception & e)
{
OutputError("%s", e.what());
// Failed to initialize
return 0;
}
}
break;
} break;
case SQMOD_LOAD_CMD:
OnSquirrelLoad();
break;
{
return OnSquirrelLoad();
} break;
case SQMOD_TERMINATE_CMD:
{
OnSquirrelTerminate();
break;
} break;
case SQMOD_RELEASED_CMD:
{
OnSquirrelReleased();
break;
} break;
default: break;
}
return 1;
@ -139,9 +132,12 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
*/
static uint8_t OnServerInitialise()
{
return 1;
return 1; // Initialization was successful
}
/* ------------------------------------------------------------------------------------------------
* The server is about to shutdown gracefully.
*/
static void OnServerShutdown(void)
{
// The server may still send callbacks
@ -150,12 +146,6 @@ static void OnServerShutdown(void)
_Clbk->OnPluginCommand = nullptr;
}
// ------------------------------------------------------------------------------------------------
void RegisterAPI(HSQUIRRELVM vm)
{
}
} // Namespace:: SqMod
// ------------------------------------------------------------------------------------------------
@ -170,20 +160,9 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * functions, PluginCall
OutputMessage("Legal: %s", SQMMDB_COPYRIGHT);
OutputMessage("--------------------------------------------------------------------");
puts("");
// Attempt to find the host plug-in ID
const int host_plugin_id = functions->FindPlugin(SQMOD_HOST_NAME);
// See if our plug-in was loaded after the host plug-in
if (host_plugin_id < 0)
// Make sure that the module was loaded after the host plug-in
if (!CheckModuleOrder(functions, info->pluginId, SQMMDB_NAME))
{
OutputError("%s could find the host plug-in", SQMMDB_NAME);
// Don't load!
return SQMOD_FAILURE;
}
// Should never reach this point but just in case
else if (host_plugin_id > (info->nPluginId))
{
OutputError("%s loaded after the host plug-in", SQMMDB_NAME);
// Don't load!
return SQMOD_FAILURE;
}
// Store server proxies

View File

@ -18,11 +18,11 @@ void SqDateToMySQLTime(Object & obj, MYSQL_TIME & t)
uint8_t month = 0, day = 0;
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push the specified object onto the stack
Var< Object >::push(_SqVM, obj);
Var< Object >::push(DefaultVM::Get(), obj);
// Attempt to get the values inside the specified object
if (SQ_FAILED(SqMod_GetDate(_SqVM, -1, &year, &month, &day)))
if (SQ_FAILED(SqMod_GetDate(DefaultVM::Get(), -1, &year, &month, &day)))
{
STHROWF("Invalid date specified");
}
@ -47,11 +47,11 @@ void SqTimeToMySQLTime(Object & obj, MYSQL_TIME & t)
uint16_t milli = 0;
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push the specified object onto the stack
Var< Object >::push(_SqVM, obj);
Var< Object >::push(DefaultVM::Get(), obj);
// Attempt to get the values inside the specified object
if (SQ_FAILED(SqMod_GetTime(_SqVM, -1, &hour, &minute, &second, &milli)))
if (SQ_FAILED(SqMod_GetTime(DefaultVM::Get(), -1, &hour, &minute, &second, &milli)))
{
STHROWF("Invalid time specified");
}
@ -73,11 +73,11 @@ void SqDatetimeToMySQLTime(Object & obj, MYSQL_TIME & t)
uint8_t month = 0, day = 0, hour = 0, minute = 0, second = 0;
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push the specified object onto the stack
Var< Object >::push(_SqVM, obj);
Var< Object >::push(DefaultVM::Get(), obj);
// Attempt to get the values inside the specified object
if (SQ_FAILED(SqMod_GetDatetime(_SqVM, -1, &year, &month, &day, &hour, &minute, &second, &milli)))
if (SQ_FAILED(SqMod_GetDatetime(DefaultVM::Get(), -1, &year, &month, &day, &hour, &minute, &second, &milli)))
{
STHROWF("Invalid date and time specified");
}

View File

@ -8,68 +8,81 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Register the module API under the specified virtual machine.
*/
void RegisterAPI(HSQUIRRELVM vm);
// ------------------------------------------------------------------------------------------------
extern void Register_Account(Table & sqlns);
extern void Register_Connection(Table & sqlns);
extern void Register_ResultSet(Table & sqlns);
extern void Register_Statement(Table & sqlns);
/* ------------------------------------------------------------------------------------------------
* Initialize the plug-in by obtaining the API provided by the host plug-in.
* Register the module API under the obtained virtual machine.
*/
void OnSquirrelInitialize()
static bool RegisterAPI()
{
// Attempt to import the plug-in API exported by the host plug-in
_SqMod = sq_api_import(_Func);
// Did we failed to obtain the plug-in exports?
if (!_SqMod)
// Make sure there's a valid virtual machine before proceeding
if (!DefaultVM::Get())
{
OutputError("Failed to attach [%s] on host plug-in.", SQMYSQL_NAME);
}
else
{
// Expand the Squirrel plug-in API into global functions
sqmod_api_expand(_SqMod);
// Obtain the Squirrel API
_SqAPI = SqMod_GetSquirrelAPI();
// Expand the Squirrel API into global functions
sq_api_expand(_SqAPI);
OutputError("%s: Cannot register API without a valid virtual machine", SQMYSQL_NAME);
// Registration failed
return false;
}
Table sqlns;
Register_Account(sqlns);
Register_Connection(sqlns);
Register_ResultSet(sqlns);
Register_Statement(sqlns);
RootTable().Bind(_SC("SqMySQL"), sqlns);
// Registration was successful
return true;
}
/* ------------------------------------------------------------------------------------------------
* Load the module on the virtual machine provided by the host module.
*/
void OnSquirrelLoad()
static bool OnSquirrelLoad()
{
// Make sure that we have a valid plug-in API
if (!_SqMod)
// Make sure that we have a valid module API
if (!SqMod_GetSquirrelVM)
{
return; // Unable to proceed.
OutputError("%s: Cannot obtain the Squirrel virtual machine without the module API", SQMYSQL_NAME);
// Unable to proceed!
return false;
}
// Obtain the Squirrel API and VM
_SqVM = SqMod_GetSquirrelVM();
// Obtain the Squirrel virtual machine from the host plug-in
DefaultVM::Set(SqMod_GetSquirrelVM());
// Make sure that a valid virtual machine exists
if (!_SqVM)
if (!DefaultVM::Get())
{
return; // Unable to proceed.
OutputError("%s: Squirrel virtual machine obtained from the host plug-in is invalid", SQMYSQL_NAME);
// Unable to proceed!
return false;
}
// Set this as the default database
DefaultVM::Set(_SqVM);
// Prevent common null objects from using dead virtual machines
NullArray() = Array();
NullTable() = Table();
NullObject() = Object();
NullFunction() = Function();
// Register the module API
RegisterAPI(_SqVM);
// Notify about the current status
OutputMessage("Registered: %s", SQMYSQL_NAME);
if (RegisterAPI())
{
OutputMessage("Registered: %s", SQMYSQL_NAME);
}
else
{
return false;
}
// At this point, the module was successfully loaded
return true;
}
/* ------------------------------------------------------------------------------------------------
* The virtual machine is about to be terminated and script resources should be released.
*/
void OnSquirrelTerminate()
static void OnSquirrelTerminate()
{
OutputMessage("Terminating: %s", SQMYSQL_NAME);
// Release null objects just in case
@ -77,36 +90,18 @@ void OnSquirrelTerminate()
NullTable().Release();
NullArray().Release();
NullFunction().ReleaseGently();
// Release script resources...
}
/* ------------------------------------------------------------------------------------------------
* The virtual machined was closed and all memory associated with it was released.
*/
void OnSquirrelReleased()
static void OnSquirrelReleased()
{
// Release the current virtual machine, if any
DefaultVM::Set(nullptr);
}
/* ------------------------------------------------------------------------------------------------
* Validate the module API to make sure we don't run into issues.
*/
bool CheckAPIVer(CCStr ver)
{
// Obtain the numeric representation of the API version
const LongI vernum = std::strtol(ver, nullptr, 10);
// Check against version mismatch
if (vernum == SQMOD_API_VER)
{
return true;
}
// Log the incident
OutputError("API version mismatch on %s", SQMYSQL_NAME);
OutputMessage("=> Requested: %ld Have: %ld", vernum, SQMOD_API_VER);
// Invoker should not attempt to communicate through the module API
return false;
}
/* ------------------------------------------------------------------------------------------------
* React to command sent by other plug-ins.
*/
@ -115,20 +110,33 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
switch(command_identifier)
{
case SQMOD_INITIALIZE_CMD:
if (CheckAPIVer(message))
{
if (CheckModuleAPIVer(message, SQMYSQL_NAME))
{
OnSquirrelInitialize();
try
{
ImportModuleAPI(_Func, SQMYSQL_NAME);
}
catch (const Sqrat::Exception & e)
{
OutputError("%s", e.what());
// Failed to initialize
return 0;
}
}
break;
} break;
case SQMOD_LOAD_CMD:
OnSquirrelLoad();
break;
{
return OnSquirrelLoad();
} break;
case SQMOD_TERMINATE_CMD:
{
OnSquirrelTerminate();
break;
} break;
case SQMOD_RELEASED_CMD:
{
OnSquirrelReleased();
break;
} break;
default: break;
}
return 1;
@ -139,9 +147,12 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
*/
static uint8_t OnServerInitialise()
{
return 1;
return 1; // Initialization was successful
}
/* ------------------------------------------------------------------------------------------------
* The server is about to shutdown gracefully.
*/
static void OnServerShutdown(void)
{
// The server may still send callbacks
@ -150,25 +161,6 @@ static void OnServerShutdown(void)
_Clbk->OnPluginCommand = nullptr;
}
// ------------------------------------------------------------------------------------------------
extern void Register_Account(Table & sqlns);
extern void Register_Connection(Table & sqlns);
extern void Register_ResultSet(Table & sqlns);
extern void Register_Statement(Table & sqlns);
// ------------------------------------------------------------------------------------------------
void RegisterAPI(HSQUIRRELVM vm)
{
Table sqlns(vm);
Register_Account(sqlns);
Register_Connection(sqlns);
Register_ResultSet(sqlns);
Register_Statement(sqlns);
RootTable(vm).Bind(_SC("SqMySQL"), sqlns);
}
} // Namespace:: SqMod
// ------------------------------------------------------------------------------------------------
@ -183,20 +175,9 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * functions, PluginCall
OutputMessage("Legal: %s", SQMYSQL_COPYRIGHT);
OutputMessage("--------------------------------------------------------------------");
std::puts("");
// Attempt to find the host plug-in ID
const int host_plugin_id = functions->FindPlugin(SQMOD_HOST_NAME);
// See if our plug-in was loaded after the host plug-in
if (host_plugin_id < 0)
// Make sure that the module was loaded after the host plug-in
if (!CheckModuleOrder(functions, info->pluginId, SQMYSQL_NAME))
{
OutputError("%s could find the host plug-in", SQMYSQL_NAME);
// Don't load!
return SQMOD_FAILURE;
}
// Should never reach this point but just in case
else if (static_cast< Uint32 >(host_plugin_id) > info->pluginId)
{
OutputError("%s loaded after the host plug-in", SQMYSQL_NAME);
// Don't load!
return SQMOD_FAILURE;
}
// Store server proxies

View File

@ -8,9 +8,43 @@
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
*
* ...
*/
class Parameter
{
public:
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Parameter();
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
Parameter(const Parameter & o);
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
Parameter(Parameter && o);
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~Parameter();
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
Parameter & operator = (const Parameter & o);
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
Parameter & operator = (Parameter && o);
};
} // Namespace:: SqMod

View File

@ -9,67 +9,75 @@
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Register the module API under the specified virtual machine.
* Register the module API under the obtained virtual machine.
*/
void RegisterAPI(HSQUIRRELVM vm);
/* ------------------------------------------------------------------------------------------------
* Initialize the plug-in by obtaining the API provided by the host plug-in.
*/
void OnSquirrelInitialize()
static bool RegisterAPI()
{
// Attempt to import the plug-in API exported by the host plug-in
_SqMod = sq_api_import(_Func);
// Did we failed to obtain the plug-in exports?
if (!_SqMod)
// Make sure there's a valid virtual machine before proceeding
if (!DefaultVM::Get())
{
OutputError("Failed to attach [%s] on host plug-in.", SQSAMPLE_NAME);
}
else
{
// Expand the Squirrel plug-in API into global functions
sqmod_api_expand(_SqMod);
// Obtain the Squirrel API
_SqAPI = SqMod_GetSquirrelAPI();
// Expand the Squirrel API into global functions
sq_api_expand(_SqAPI);
OutputError("%s: Cannot register API without a valid virtual machine", SQSAMPLE_NAME);
// Registration failed
return false;
}
RootTable().Bind(_SC("SampleType"), Class< SampleType >(DefaultVM::Get(), _SC("SampleType"))
.Ctor()
.Ctor< int >()
.Var(_SC("MyNum"), &SampleType::mMyNum)
.Prop(_SC("MyVal"), &SampleType::GetMyVal, &SampleType::SetMyVal)
.Func(_SC("SampleMethod"), &SampleType::SampleMethod)
);
RootTable().Func(_SC("SampleFunction"), &SampleFunction);
// Registration was successful
return true;
}
/* ------------------------------------------------------------------------------------------------
* Load the module on the virtual machine provided by the host module.
*/
void OnSquirrelLoad()
static bool OnSquirrelLoad()
{
// Make sure that we have a valid plug-in API
if (!_SqMod)
// Make sure that we have a valid module API
if (!SqMod_GetSquirrelVM)
{
return; // Unable to proceed.
OutputError("%s: Cannot obtain the Squirrel virtual machine without the module API", SQSAMPLE_NAME);
// Unable to proceed!
return false;
}
// Obtain the Squirrel API and VM
_SqVM = SqMod_GetSquirrelVM();
// Obtain the Squirrel virtual machine from the host plug-in
DefaultVM::Set(SqMod_GetSquirrelVM());
// Make sure that a valid virtual machine exists
if (!_SqVM)
if (!DefaultVM::Get())
{
return; // Unable to proceed.
OutputError("%s: Squirrel virtual machine obtained from the host plug-in is invalid", SQSAMPLE_NAME);
// Unable to proceed!
return false;
}
// Set this as the default database
DefaultVM::Set(_SqVM);
// Prevent common null objects from using dead virtual machines
NullArray() = Array();
NullTable() = Table();
NullObject() = Object();
NullFunction() = Function();
// Register the module API
RegisterAPI(_SqVM);
// Notify about the current status
OutputMessage("Registered: %s", SQSAMPLE_NAME);
if (RegisterAPI())
{
OutputMessage("Registered: %s", SQSAMPLE_NAME);
}
else
{
return false;
}
// At this point, the module was successfully loaded
return true;
}
/* ------------------------------------------------------------------------------------------------
* The virtual machine is about to be terminated and script resources should be released.
*/
void OnSquirrelTerminate()
static void OnSquirrelTerminate()
{
OutputMessage("Terminating: %s", SQSAMPLE_NAME);
// Release null objects just in case
@ -83,31 +91,12 @@ void OnSquirrelTerminate()
/* ------------------------------------------------------------------------------------------------
* The virtual machined was closed and all memory associated with it was released.
*/
void OnSquirrelReleased()
static void OnSquirrelReleased()
{
// Release the current virtual machine, if any
DefaultVM::Set(nullptr);
}
/* ------------------------------------------------------------------------------------------------
* Validate the module API to make sure we don't run into issues.
*/
bool CheckAPIVer(CCStr ver)
{
// Obtain the numeric representation of the API version
const LongI vernum = std::strtol(ver, nullptr, 10);
// Check against version mismatch
if (vernum == SQMOD_API_VER)
{
return true;
}
// Log the incident
OutputError("API version mismatch on %s", SQSAMPLE_NAME);
OutputMessage("=> Requested: %ld Have: %ld", vernum, SQMOD_API_VER);
// Invoker should not attempt to communicate through the module API
return false;
}
/* ------------------------------------------------------------------------------------------------
* React to command sent by other plug-ins.
*/
@ -116,20 +105,33 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
switch(command_identifier)
{
case SQMOD_INITIALIZE_CMD:
if (CheckAPIVer(message))
{
if (CheckModuleAPIVer(message, SQSAMPLE_NAME))
{
OnSquirrelInitialize();
try
{
ImportModuleAPI(_Func, SQSAMPLE_NAME);
}
catch (const Sqrat::Exception & e)
{
OutputError("%s", e.what());
// Failed to initialize
return 0;
}
}
break;
} break;
case SQMOD_LOAD_CMD:
OnSquirrelLoad();
break;
{
return OnSquirrelLoad();
} break;
case SQMOD_TERMINATE_CMD:
{
OnSquirrelTerminate();
break;
} break;
case SQMOD_RELEASED_CMD:
{
OnSquirrelReleased();
break;
} break;
default: break;
}
return 1;
@ -140,9 +142,12 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
*/
static uint8_t OnServerInitialise()
{
return 1;
return 1; // Initialization was successful
}
/* ------------------------------------------------------------------------------------------------
* The server is about to shutdown gracefully.
*/
static void OnServerShutdown(void)
{
// The server may still send callbacks
@ -151,20 +156,6 @@ static void OnServerShutdown(void)
_Clbk->OnPluginCommand = nullptr;
}
// ------------------------------------------------------------------------------------------------
void RegisterAPI(HSQUIRRELVM vm)
{
RootTable(vm).Bind(_SC("SampleType"), Class< SampleType >(vm, _SC("SampleType"))
.Ctor()
.Ctor< int >()
.Var(_SC("MyNum"), &SampleType::mMyNum)
.Prop(_SC("MyVal"), &SampleType::GetMyVal, &SampleType::SetMyVal)
.Func(_SC("SampleMethod"), &SampleType::SampleMethod)
);
RootTable(vm).Func(_SC("SampleFunction"), &SampleFunction);
}
} // Namespace:: SqMod
// ------------------------------------------------------------------------------------------------
@ -179,20 +170,9 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * functions, PluginCall
OutputMessage("Legal: %s", SQSAMPLE_COPYRIGHT);
OutputMessage("--------------------------------------------------------------------");
std::puts("");
// Attempt to find the host plug-in ID
const int host_plugin_id = functions->FindPlugin(SQMOD_HOST_NAME);
// See if our plug-in was loaded after the host plug-in
if (host_plugin_id < 0)
// Make sure that the module was loaded after the host plug-in
if (!CheckModuleOrder(functions, info->pluginId, SQSAMPLE_NAME))
{
OutputError("%s could find the host plug-in", SQSAMPLE_NAME);
// Don't load!
return SQMOD_FAILURE;
}
// Should never reach this point but just in case
else if (static_cast< Uint32 >(host_plugin_id) > info->pluginId)
{
OutputError("%s loaded after the host plug-in", SQSAMPLE_NAME);
// Don't load!
return SQMOD_FAILURE;
}
// Store server proxies

View File

@ -430,12 +430,12 @@ Object Column::GetString() const
{
SQMOD_VALIDATE_ROW(*this);
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push the column text on the stack
sq_pushstring(_SqVM, reinterpret_cast< CSStr >(sqlite3_column_text(m_Handle->mPtr, m_Index)),
sq_pushstring(DefaultVM::Get(), reinterpret_cast< CSStr >(sqlite3_column_text(m_Handle->mPtr, m_Index)),
sqlite3_column_bytes(m_Handle->mPtr, m_Index));
// Get the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ------------------------------------------------------------------------------------------------
@ -470,7 +470,7 @@ Object Column::GetBuffer() const
STHROWF("Unable to allocate buffer of at least (%d) bytes", size);
}
// Get the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ------------------------------------------------------------------------------------------------
@ -478,11 +478,11 @@ Object Column::GetBlob() const
{
SQMOD_VALIDATE_ROW(*this);
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Obtain the size of the data
const Int32 sz = sqlite3_column_bytes(m_Handle->mPtr, m_Index);
// Allocate a blob of the same size
SQUserPointer p = sqstd_createblob(_SqVM, sz);
SQUserPointer p = sqstd_createblob(DefaultVM::Get(), sz);
// Obtain a pointer to the data
const void * b = sqlite3_column_blob(m_Handle->mPtr, m_Index);
// Could the memory blob be allocated?
@ -494,9 +494,9 @@ Object Column::GetBlob() const
else if (!b)
{
// Pop the memory blob from the stack
sq_pop(_SqVM, 1);
sq_pop(DefaultVM::Get(), 1);
// Push a null value instead
sq_pushnull(_SqVM);
sq_pushnull(DefaultVM::Get());
}
// Copy the data into the memory blob
else
@ -504,7 +504,7 @@ Object Column::GetBlob() const
std::memcpy(p, b, sz);
}
// Get the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ================================================================================================

View File

@ -82,22 +82,22 @@ Int32 ReleaseMemory(Int32 bytes)
Object GetMemoryUsage()
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push a long integer instance with the requested value on the stack
SqMod_PushSLongObject(_SqVM, sqlite3_memory_used());
SqMod_PushSLongObject(DefaultVM::Get(), sqlite3_memory_used());
// Obtain the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ------------------------------------------------------------------------------------------------
Object GetMemoryHighwaterMark(bool reset)
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push a long integer instance with the requested value on the stack
SqMod_PushSLongObject(_SqVM, sqlite3_memory_highwater(reset));
SqMod_PushSLongObject(DefaultVM::Get(), sqlite3_memory_highwater(reset));
// Obtain the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ------------------------------------------------------------------------------------------------

View File

@ -8,68 +8,87 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Register the module API under the specified virtual machine.
*/
void RegisterAPI(HSQUIRRELVM vm);
// ------------------------------------------------------------------------------------------------
extern void Register_Constants(Table & sqlns);
extern void Register_Common(Table & sqlns);
extern void Register_Connection(Table & sqlns);
extern void Register_Statement(Table & sqlns);
extern void Register_Parameter(Table & sqlns);
extern void Register_Column(Table & sqlns);
extern void Register_Transaction(Table & sqlns);
/* ------------------------------------------------------------------------------------------------
* Initialize the plug-in by obtaining the API provided by the host plug-in.
* Register the module API under the obtained virtual machine.
*/
void OnSquirrelInitialize()
static bool RegisterAPI()
{
// Attempt to import the plug-in API exported by the host plug-in
_SqMod = sq_api_import(_Func);
// Did we failed to obtain the plug-in exports?
if (!_SqMod)
// Make sure there's a valid virtual machine before proceeding
if (!DefaultVM::Get())
{
OutputError("Failed to attach [%s] on host plug-in.", SQSQLITE_NAME);
}
else
{
// Expand the Squirrel plug-in API into global functions
sqmod_api_expand(_SqMod);
// Obtain the Squirrel API
_SqAPI = SqMod_GetSquirrelAPI();
// Expand the Squirrel API into global functions
sq_api_expand(_SqAPI);
OutputError("%s: Cannot register API without a valid virtual machine", SQSQLITE_NAME);
// Registration failed
return false;
}
Table sqlns;
Register_Constants(sqlns);
Register_Common(sqlns);
Register_Connection(sqlns);
Register_Statement(sqlns);
Register_Parameter(sqlns);
Register_Column(sqlns);
Register_Transaction(sqlns);
RootTable().Bind(_SC("SQLite"), sqlns);
// Registration was successful
return true;
}
/* ------------------------------------------------------------------------------------------------
* Load the module on the virtual machine provided by the host module.
*/
void OnSquirrelLoad()
static bool OnSquirrelLoad()
{
// Make sure that we have a valid plug-in API
if (!_SqMod)
// Make sure that we have a valid module API
if (!SqMod_GetSquirrelVM)
{
return; // Unable to proceed!
OutputError("%s: Cannot obtain the Squirrel virtual machine without the module API", SQSQLITE_NAME);
// Unable to proceed!
return false;
}
// Obtain the Squirrel API and VM
_SqVM = SqMod_GetSquirrelVM();
// Obtain the Squirrel virtual machine from the host plug-in
DefaultVM::Set(SqMod_GetSquirrelVM());
// Make sure that a valid virtual machine exists
if (!_SqVM)
if (!DefaultVM::Get())
{
return; // Unable to proceed!
OutputError("%s: Squirrel virtual machine obtained from the host plug-in is invalid", SQSQLITE_NAME);
// Unable to proceed!
return false;
}
// Set this as the default database
DefaultVM::Set(_SqVM);
// Prevent common null objects from using dead virtual machines
NullArray() = Array();
NullTable() = Table();
NullObject() = Object();
NullFunction() = Function();
// Register the module API
RegisterAPI(_SqVM);
// Notify about the current status
OutputMessage("Registered: %s", SQSQLITE_NAME);
if (RegisterAPI())
{
OutputMessage("Registered: %s", SQSQLITE_NAME);
}
else
{
return false;
}
// At this point, the module was successfully loaded
return true;
}
/* ------------------------------------------------------------------------------------------------
* The virtual machine is about to be terminated and script resources should be released.
*/
void OnSquirrelTerminate()
static void OnSquirrelTerminate()
{
OutputMessage("Terminating: %s", SQSQLITE_NAME);
// Release null objects just in case
@ -77,36 +96,18 @@ void OnSquirrelTerminate()
NullTable().Release();
NullArray().Release();
NullFunction().ReleaseGently();
// Release script resources...
}
/* ------------------------------------------------------------------------------------------------
* The virtual machined was closed and all memory associated with it was released.
*/
void OnSquirrelReleased()
static void OnSquirrelReleased()
{
// Release the current virtual machine, if any
DefaultVM::Set(nullptr);
}
/* ------------------------------------------------------------------------------------------------
* Validate the module API to make sure we don't run into issues.
*/
bool CheckAPIVer(CCStr ver)
{
// Obtain the numeric representation of the API version
const LongI vernum = std::strtol(ver, nullptr, 10);
// Check against version mismatch
if (vernum == SQMOD_API_VER)
{
return true;
}
// Log the incident
OutputError("API version mismatch on %s", SQSQLITE_NAME);
OutputMessage("=> Requested: %ld Have: %ld", vernum, SQMOD_API_VER);
// Invoker should not attempt to communicate through the module API
return false;
}
/* ------------------------------------------------------------------------------------------------
* React to command sent by other plug-ins.
*/
@ -115,20 +116,33 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
switch(command_identifier)
{
case SQMOD_INITIALIZE_CMD:
if (CheckAPIVer(message))
{
if (CheckModuleAPIVer(message, SQSQLITE_NAME))
{
OnSquirrelInitialize();
try
{
ImportModuleAPI(_Func, SQSQLITE_NAME);
}
catch (const Sqrat::Exception & e)
{
OutputError("%s", e.what());
// Failed to initialize
return 0;
}
}
break;
} break;
case SQMOD_LOAD_CMD:
OnSquirrelLoad();
break;
{
return OnSquirrelLoad();
} break;
case SQMOD_TERMINATE_CMD:
{
OnSquirrelTerminate();
break;
} break;
case SQMOD_RELEASED_CMD:
{
OnSquirrelReleased();
break;
} break;
default: break;
}
return 1;
@ -139,9 +153,12 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
*/
static uint8_t OnServerInitialise()
{
return 1;
return 1; // Initialization was successful
}
/* ------------------------------------------------------------------------------------------------
* The server is about to shutdown gracefully.
*/
static void OnServerShutdown(void)
{
// The server may still send callbacks
@ -150,31 +167,6 @@ static void OnServerShutdown(void)
_Clbk->OnPluginCommand = nullptr;
}
// ------------------------------------------------------------------------------------------------
extern void Register_Constants(Table & sqlns);
extern void Register_Common(Table & sqlns);
extern void Register_Connection(Table & sqlns);
extern void Register_Statement(Table & sqlns);
extern void Register_Parameter(Table & sqlns);
extern void Register_Column(Table & sqlns);
extern void Register_Transaction(Table & sqlns);
// ------------------------------------------------------------------------------------------------
void RegisterAPI(HSQUIRRELVM vm)
{
Table sqlns(vm);
Register_Constants(sqlns);
Register_Common(sqlns);
Register_Connection(sqlns);
Register_Statement(sqlns);
Register_Parameter(sqlns);
Register_Column(sqlns);
Register_Transaction(sqlns);
RootTable(vm).Bind(_SC("SQLite"), sqlns);
}
} // Namespace:: SqMod
// ------------------------------------------------------------------------------------------------
@ -189,20 +181,9 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * functions, PluginCall
OutputMessage("Legal: %s", SQSQLITE_COPYRIGHT);
OutputMessage("--------------------------------------------------------------------");
puts("");
// Attempt to find the host plug-in ID
const int host_plugin_id = functions->FindPlugin(SQMOD_HOST_NAME);
// See if our plug-in was loaded after the host plug-in
if (host_plugin_id < 0)
// Make sure that the module was loaded after the host plug-in
if (!CheckModuleOrder(functions, info->pluginId, SQSQLITE_NAME))
{
OutputError("%s could find the host plug-in", SQSQLITE_NAME);
// Don't load!
return SQMOD_FAILURE;
}
// Should never reach this point but just in case
else if (static_cast< Uint32 >(host_plugin_id) > info->pluginId)
{
OutputError("%s loaded after the host plug-in", SQSQLITE_NAME);
// Don't load!
return SQMOD_FAILURE;
}
// Store server proxies

View File

@ -16,53 +16,53 @@ SQInteger Attribute::Typename(HSQUIRRELVM vm)
Object Attribute::AsLong(Object & def) const
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push the specified object onto the stack
Var< Object >::push(_SqVM, def);
Var< Object >::push(DefaultVM::Get(), def);
// The resulted long integer value
Int64 longint = 0;
// Attempt to get the numeric value inside the specified object
if (SQ_FAILED(SqMod_GetSLongValue(_SqVM, -1, &longint)))
if (SQ_FAILED(SqMod_GetSLongValue(DefaultVM::Get(), -1, &longint)))
{
STHROWF("Invalid long integer specified");
}
// Push a long integer instance with the requested value on the stack
SqMod_PushSLongObject(_SqVM, m_Attr.as_llong(longint));
SqMod_PushSLongObject(DefaultVM::Get(), m_Attr.as_llong(longint));
// Obtain the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ------------------------------------------------------------------------------------------------
Object Attribute::AsUlong(Object & def) const
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push the specified object onto the stack
Var< Object >::push(_SqVM, def);
Var< Object >::push(DefaultVM::Get(), def);
// The resulted long integer value
Uint64 longint = 0;
// Attempt to get the numeric value inside the specified object
if (SQ_FAILED(SqMod_GetULongValue(_SqVM, -1, &longint)))
if (SQ_FAILED(SqMod_GetULongValue(DefaultVM::Get(), -1, &longint)))
{
STHROWF("Invalid long integer specified");
}
// Push a long integer instance with the requested value on the stack
SqMod_PushULongObject(_SqVM, m_Attr.as_ullong(longint));
SqMod_PushULongObject(DefaultVM::Get(), m_Attr.as_ullong(longint));
// Obtain the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ------------------------------------------------------------------------------------------------
bool Attribute::ApplyLong(Object & value)
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push the specified object onto the stack
Var< Object & >::push(_SqVM, value);
Var< Object & >::push(DefaultVM::Get(), value);
// The resulted long integer value
Int64 longint = 0;
// Attempt to get the numeric value inside the specified object
if (SQ_FAILED(SqMod_GetSLongValue(_SqVM, -1, &longint)))
if (SQ_FAILED(SqMod_GetSLongValue(DefaultVM::Get(), -1, &longint)))
{
STHROWF("Invalid long integer specified");
}
@ -74,13 +74,13 @@ bool Attribute::ApplyLong(Object & value)
bool Attribute::ApplyUlong(Object & value)
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push the specified object onto the stack
Var< Object & >::push(_SqVM, value);
Var< Object & >::push(DefaultVM::Get(), value);
// The resulted long integer value
Uint64 longint = 0;
// Attempt to get the numeric value inside the specified object
if (SQ_FAILED(SqMod_GetULongValue(_SqVM, -1, &longint)))
if (SQ_FAILED(SqMod_GetULongValue(DefaultVM::Get(), -1, &longint)))
{
STHROWF("Invalid long integer specified");
}
@ -92,24 +92,24 @@ bool Attribute::ApplyUlong(Object & value)
Object Attribute::GetLong() const
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push a long integer instance with the requested value on the stack
SqMod_PushSLongObject(_SqVM, m_Attr.as_llong());
SqMod_PushSLongObject(DefaultVM::Get(), m_Attr.as_llong());
// Obtain the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ------------------------------------------------------------------------------------------------
void Attribute::SetLong(Object & value)
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push the specified object onto the stack
Var< Object & >::push(_SqVM, value);
Var< Object & >::push(DefaultVM::Get(), value);
// The resulted long integer value
Int64 longint = 0;
// Attempt to get the numeric value inside the specified object
if (SQ_FAILED(SqMod_GetSLongValue(_SqVM, -1, &longint)))
if (SQ_FAILED(SqMod_GetSLongValue(DefaultVM::Get(), -1, &longint)))
{
STHROWF("Invalid long integer specified");
}
@ -121,24 +121,24 @@ void Attribute::SetLong(Object & value)
Object Attribute::GetUlong() const
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push a long integer instance with the requested value on the stack
SqMod_PushULongObject(_SqVM, m_Attr.as_ullong());
SqMod_PushULongObject(DefaultVM::Get(), m_Attr.as_ullong());
// Obtain the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ------------------------------------------------------------------------------------------------
void Attribute::SetUlong(Object & value)
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push the specified object onto the stack
Var< Object & >::push(_SqVM, value);
Var< Object & >::push(DefaultVM::Get(), value);
// The resulted long integer value
Uint64 longint = 0;
// Attempt to get the numeric value inside the specified object
if (SQ_FAILED(SqMod_GetULongValue(_SqVM, -1, &longint)))
if (SQ_FAILED(SqMod_GetULongValue(DefaultVM::Get(), -1, &longint)))
{
STHROWF("Invalid long integer specified");
}

View File

@ -14,153 +14,21 @@
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Register the module API under the specified virtual machine.
* Register the module API under the obtained virtual machine.
*/
void RegisterAPI(HSQUIRRELVM vm);
/* ------------------------------------------------------------------------------------------------
* Initialize the plug-in by obtaining the API provided by the host plug-in.
*/
void OnSquirrelInitialize()
static bool RegisterAPI()
{
// Attempt to import the plug-in API exported by the host plug-in
_SqMod = sq_api_import(_Func);
// Did we failed to obtain the plug-in exports?
if (!_SqMod)
// Make sure there's a valid virtual machine before proceeding
if (!DefaultVM::Get())
{
OutputError("Failed to attach [%s] on host plug-in.", SQXML_NAME);
OutputError("%s: Cannot register API without a valid virtual machine", SQXML_NAME);
// Registration failed
return false;
}
else
{
// Expand the Squirrel plug-in API into global functions
sqmod_api_expand(_SqMod);
// Obtain the Squirrel API
_SqAPI = SqMod_GetSquirrelAPI();
// Expand the Squirrel API into global functions
sq_api_expand(_SqAPI);
}
}
/* ------------------------------------------------------------------------------------------------
* Load the module on the virtual machine provided by the host module.
*/
void OnSquirrelLoad()
{
// Make sure that we have a valid plug-in API
if (!_SqMod)
{
return; // Unable to proceed!
}
// Obtain the Squirrel API and VM
_SqVM = SqMod_GetSquirrelVM();
// Make sure that a valid virtual machine exists
if (!_SqVM)
{
return; // Unable to proceed!
}
// Set this as the default database
DefaultVM::Set(_SqVM);
// Prevent common null objects from using dead virtual machines
NullArray() = Array();
NullTable() = Table();
NullObject() = Object();
NullFunction() = Function();
// Register the module API
RegisterAPI(_SqVM);
// Notify about the current status
OutputMessage("Registered: %s", SQXML_NAME);
}
Table xmlns;
/* ------------------------------------------------------------------------------------------------
* The virtual machine is about to be terminated and script resources should be released.
*/
void OnSquirrelTerminate()
{
OutputMessage("Terminating: %s", SQXML_NAME);
// Release null objects just in case
NullObject().Release();
NullTable().Release();
NullArray().Release();
NullFunction().ReleaseGently();
}
/* ------------------------------------------------------------------------------------------------
* The virtual machined was closed and all memory associated with it was released.
*/
void OnSquirrelReleased()
{
// Release the current virtual machine, if any
DefaultVM::Set(nullptr);
}
/* ------------------------------------------------------------------------------------------------
* Validate the module API to make sure we don't run into issues.
*/
bool CheckAPIVer(CCStr ver)
{
// Obtain the numeric representation of the API version
const LongI vernum = std::strtol(ver, nullptr, 10);
// Check against version mismatch
if (vernum == SQMOD_API_VER)
{
return true;
}
// Log the incident
OutputError("API version mismatch on %s", SQXML_NAME);
OutputMessage("=> Requested: %ld Have: %ld", vernum, SQMOD_API_VER);
// Invoker should not attempt to communicate through the module API
return false;
}
/* ------------------------------------------------------------------------------------------------
* React to command sent by other plug-ins.
*/
static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
{
switch(command_identifier)
{
case SQMOD_INITIALIZE_CMD:
if (CheckAPIVer(message))
{
OnSquirrelInitialize();
}
break;
case SQMOD_LOAD_CMD:
OnSquirrelLoad();
break;
case SQMOD_TERMINATE_CMD:
OnSquirrelTerminate();
break;
case SQMOD_RELEASED_CMD:
OnSquirrelReleased();
break;
default: break;
}
return 1;
}
/* ------------------------------------------------------------------------------------------------
* The server was initialized and this plug-in was loaded successfully.
*/
static uint8_t OnServerInitialise()
{
return 1;
}
static void OnServerShutdown(void)
{
// The server may still send callbacks
_Clbk->OnServerInitialise = nullptr;
_Clbk->OnServerShutdown = nullptr;
_Clbk->OnPluginCommand = nullptr;
}
// ------------------------------------------------------------------------------------------------
void RegisterAPI(HSQUIRRELVM vm)
{
Table xmlns(vm);
xmlns.Bind(_SC("ParseResult"), Class< ParseResult >(vm, _SC("SqXmlParseResult"))
xmlns.Bind(_SC("ParseResult"), Class< ParseResult >(xmlns.GetVM(), _SC("SqXmlParseResult"))
// Constructors
.Ctor()
.Ctor< const ParseResult & >()
@ -180,7 +48,7 @@ void RegisterAPI(HSQUIRRELVM vm)
.Func(_SC("Check"), &ParseResult::Check)
);
xmlns.Bind(_SC("Attribute"), Class< Attribute >(vm, _SC("SqXmlAttribute"))
xmlns.Bind(_SC("Attribute"), Class< Attribute >(xmlns.GetVM(), _SC("SqXmlAttribute"))
// Constructors
.Ctor()
.Ctor< const Attribute & >()
@ -225,7 +93,7 @@ void RegisterAPI(HSQUIRRELVM vm)
.Func(_SC("SetBool"), &Attribute::ApplyBool)
);
xmlns.Bind(_SC("Text"), Class< Text >(vm, _SC("SqXmlText"))
xmlns.Bind(_SC("Text"), Class< Text >(xmlns.GetVM(), _SC("SqXmlText"))
// Constructors
.Ctor()
.Ctor< const Text & >()
@ -265,7 +133,7 @@ void RegisterAPI(HSQUIRRELVM vm)
.Func(_SC("SetBool"), &Text::ApplyBool)
);
xmlns.Bind(_SC("Node"), Class< Node >(vm, _SC("SqXmlNode"))
xmlns.Bind(_SC("Node"), Class< Node >(xmlns.GetVM(), _SC("SqXmlNode"))
// Constructors
.Ctor()
.Ctor< const Node & >()
@ -341,7 +209,7 @@ void RegisterAPI(HSQUIRRELVM vm)
.Func(_SC("FindElemByPath"), &Node::FindElemByPath)
);
xmlns.Bind(_SC("Document"), Class< Document, NoCopy< Document > >(vm, _SC("SqXmlDocument"))
xmlns.Bind(_SC("Document"), Class< Document, NoCopy< Document > >(xmlns.GetVM(), _SC("SqXmlDocument"))
// Constructors
.Ctor()
// Core Meta-methods
@ -366,9 +234,9 @@ void RegisterAPI(HSQUIRRELVM vm)
.Overload< void (Document::*)(CSStr, CSStr, Uint32, Int32) >(_SC("SaveFile"), &Document::SaveFile)
);
RootTable(vm).Bind(_SC("SqXml"), xmlns);
RootTable().Bind(_SC("SqXml"), xmlns);
ConstTable(vm).Enum(_SC("SqXmlNodeType"), Enumeration(vm)
ConstTable().Enum(_SC("SqXmlNodeType"), Enumeration()
.Const(_SC("Null"), static_cast< Int32 >(node_null))
.Const(_SC("Document"), static_cast< Int32 >(node_document))
.Const(_SC("Element"), static_cast< Int32 >(node_element))
@ -380,7 +248,7 @@ void RegisterAPI(HSQUIRRELVM vm)
.Const(_SC("Doctype"), static_cast< Int32 >(node_doctype))
);
ConstTable(vm).Enum(_SC("SqXmlParse"), Enumeration(vm)
ConstTable().Enum(_SC("SqXmlParse"), Enumeration()
.Const(_SC("Minimal"), static_cast< Int32 >(parse_minimal))
.Const(_SC("Default"), static_cast< Int32 >(parse_default))
.Const(_SC("Full"), static_cast< Int32 >(parse_full))
@ -400,7 +268,7 @@ void RegisterAPI(HSQUIRRELVM vm)
.Const(_SC("EmbedPCData"), static_cast< Int32 >(parse_embed_pcdata))
);
ConstTable(vm).Enum(_SC("SqXmlEncoding"), Enumeration(vm)
ConstTable().Enum(_SC("SqXmlEncoding"), Enumeration()
.Const(_SC("Auto"), static_cast< Int32 >(encoding_auto))
.Const(_SC("Utf8"), static_cast< Int32 >(encoding_utf8))
.Const(_SC("Utf16LE"), static_cast< Int32 >(encoding_utf16_le))
@ -413,7 +281,7 @@ void RegisterAPI(HSQUIRRELVM vm)
.Const(_SC("Latin1"), static_cast< Int32 >(encoding_latin1))
);
ConstTable(vm).Enum(_SC("SqXmlFormat"), Enumeration(vm)
ConstTable().Enum(_SC("SqXmlFormat"), Enumeration()
.Const(_SC("Indent"), static_cast< Int32 >(format_indent))
.Const(_SC("WriteBOM"), static_cast< Int32 >(format_write_bom))
.Const(_SC("Raw"), static_cast< Int32 >(format_raw))
@ -424,7 +292,7 @@ void RegisterAPI(HSQUIRRELVM vm)
.Const(_SC("Default"), static_cast< Int32 >(format_default))
);
ConstTable(vm).Enum(_SC("SqXmlParseStatus"), Enumeration(vm)
ConstTable().Enum(_SC("SqXmlParseStatus"), Enumeration()
.Const(_SC("Ok"), static_cast< Int32 >(status_ok))
.Const(_SC("FileNotFound"), static_cast< Int32 >(status_file_not_found))
.Const(_SC("IOError"), static_cast< Int32 >(status_io_error))
@ -444,13 +312,137 @@ void RegisterAPI(HSQUIRRELVM vm)
.Const(_SC("NoDocumentElement"), static_cast< Int32 >(status_no_document_element))
);
ConstTable(vm).Enum(_SC("SqXmlXpathValueType"), Enumeration(vm)
ConstTable().Enum(_SC("SqXmlXpathValueType"), Enumeration()
.Const(_SC("None"), static_cast< Int32 >(xpath_type_none))
.Const(_SC("NodeSet"), static_cast< Int32 >(xpath_type_node_set))
.Const(_SC("Number"), static_cast< Int32 >(xpath_type_number))
.Const(_SC("String"), static_cast< Int32 >(xpath_type_string))
.Const(_SC("Boolean"), static_cast< Int32 >(xpath_type_boolean))
);
// Registration was successful
return true;
}
/* ------------------------------------------------------------------------------------------------
* Load the module on the virtual machine provided by the host module.
*/
static bool OnSquirrelLoad()
{
// Make sure that we have a valid module API
if (!SqMod_GetSquirrelVM)
{
OutputError("%s: Cannot obtain the Squirrel virtual machine without the module API", SQXML_NAME);
// Unable to proceed!
return false;
}
// Obtain the Squirrel virtual machine from the host plug-in
DefaultVM::Set(SqMod_GetSquirrelVM());
// Make sure that a valid virtual machine exists
if (!DefaultVM::Get())
{
OutputError("%s: Squirrel virtual machine obtained from the host plug-in is invalid", SQXML_NAME);
// Unable to proceed!
return false;
}
// Prevent common null objects from using dead virtual machines
NullArray() = Array();
NullTable() = Table();
NullObject() = Object();
NullFunction() = Function();
// Register the module API
if (RegisterAPI())
{
OutputMessage("Registered: %s", SQXML_NAME);
}
else
{
return false;
}
// At this point, the module was successfully loaded
return true;
}
/* ------------------------------------------------------------------------------------------------
* The virtual machine is about to be terminated and script resources should be released.
*/
static void OnSquirrelTerminate()
{
OutputMessage("Terminating: %s", SQXML_NAME);
// Release null objects just in case
NullObject().Release();
NullTable().Release();
NullArray().Release();
NullFunction().ReleaseGently();
// Release script resources...
}
/* ------------------------------------------------------------------------------------------------
* The virtual machined was closed and all memory associated with it was released.
*/
static void OnSquirrelReleased()
{
// Release the current virtual machine, if any
DefaultVM::Set(nullptr);
}
/* ------------------------------------------------------------------------------------------------
* React to command sent by other plug-ins.
*/
static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
{
switch(command_identifier)
{
case SQMOD_INITIALIZE_CMD:
{
if (CheckModuleAPIVer(message, SQXML_NAME))
{
try
{
ImportModuleAPI(_Func, SQXML_NAME);
}
catch (const Sqrat::Exception & e)
{
OutputError("%s", e.what());
// Failed to initialize
return 0;
}
}
} break;
case SQMOD_LOAD_CMD:
{
return OnSquirrelLoad();
} break;
case SQMOD_TERMINATE_CMD:
{
OnSquirrelTerminate();
} break;
case SQMOD_RELEASED_CMD:
{
OnSquirrelReleased();
} break;
default: break;
}
return 1;
}
/* ------------------------------------------------------------------------------------------------
* The server was initialized and this plug-in was loaded successfully.
*/
static uint8_t OnServerInitialise()
{
return 1; // Initialization was successful
}
/* ------------------------------------------------------------------------------------------------
* The server is about to shutdown gracefully.
*/
static void OnServerShutdown(void)
{
// The server may still send callbacks
_Clbk->OnServerInitialise = nullptr;
_Clbk->OnServerShutdown = nullptr;
_Clbk->OnPluginCommand = nullptr;
}
} // Namespace:: SqMod
@ -467,20 +459,9 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * functions, PluginCall
OutputMessage("Legal: %s", SQXML_COPYRIGHT);
OutputMessage("--------------------------------------------------------------------");
puts("");
// Attempt to find the host plug-in ID
const int host_plugin_id = functions->FindPlugin(SQMOD_HOST_NAME);
// See if our plug-in was loaded after the host plug-in
if (host_plugin_id < 0)
// Make sure that the module was loaded after the host plug-in
if (!CheckModuleOrder(functions, info->pluginId, SQXML_NAME))
{
OutputError("%s could find the host plug-in", SQXML_NAME);
// Don't load!
return SQMOD_FAILURE;
}
// Should never reach this point but just in case
else if (static_cast< Uint32 >(host_plugin_id) > info->pluginId)
{
OutputError("%s loaded after the host plug-in", SQXML_NAME);
// Don't load!
return SQMOD_FAILURE;
}
// Store server proxies

View File

@ -37,53 +37,53 @@ Int32 Text::Cmp(const Text & o)
Object Text::AsLong(Object & def) const
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push the specified object onto the stack
Var< Object >::push(_SqVM, def);
Var< Object >::push(DefaultVM::Get(), def);
// The resulted long integer value
Int64 longint = 0;
// Attempt to get the numeric value inside the specified object
if (SQ_FAILED(SqMod_GetSLongValue(_SqVM, -1, &longint)))
if (SQ_FAILED(SqMod_GetSLongValue(DefaultVM::Get(), -1, &longint)))
{
STHROWF("Invalid long integer specified");
}
// Push a long integer instance with the requested value on the stack
SqMod_PushSLongObject(_SqVM, m_Text.as_llong(longint));
SqMod_PushSLongObject(DefaultVM::Get(), m_Text.as_llong(longint));
// Obtain the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ------------------------------------------------------------------------------------------------
Object Text::AsUlong(Object & def) const
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push the specified object onto the stack
Var< Object >::push(_SqVM, def);
Var< Object >::push(DefaultVM::Get(), def);
// The resulted long integer value
Uint64 longint = 0;
// Attempt to get the numeric value inside the specified object
if (SQ_FAILED(SqMod_GetULongValue(_SqVM, -1, &longint)))
if (SQ_FAILED(SqMod_GetULongValue(DefaultVM::Get(), -1, &longint)))
{
STHROWF("Invalid long integer specified");
}
// Push a long integer instance with the requested value on the stack
SqMod_PushULongObject(_SqVM, m_Text.as_ullong(longint));
SqMod_PushULongObject(DefaultVM::Get(), m_Text.as_ullong(longint));
// Obtain the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ------------------------------------------------------------------------------------------------
bool Text::ApplyLong(Object & value)
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push the specified object onto the stack
Var< Object & >::push(_SqVM, value);
Var< Object & >::push(DefaultVM::Get(), value);
// The resulted long integer value
Int64 longint = 0;
// Attempt to get the numeric value inside the specified object
if (SQ_FAILED(SqMod_GetSLongValue(_SqVM, -1, &longint)))
if (SQ_FAILED(SqMod_GetSLongValue(DefaultVM::Get(), -1, &longint)))
{
STHROWF("Invalid long integer specified");
}
@ -95,13 +95,13 @@ bool Text::ApplyLong(Object & value)
bool Text::ApplyUlong(Object & value)
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push the specified object onto the stack
Var< Object & >::push(_SqVM, value);
Var< Object & >::push(DefaultVM::Get(), value);
// The resulted long integer value
Uint64 longint = 0;
// Attempt to get the numeric value inside the specified object
if (SQ_FAILED(SqMod_GetULongValue(_SqVM, -1, &longint)))
if (SQ_FAILED(SqMod_GetULongValue(DefaultVM::Get(), -1, &longint)))
{
STHROWF("Invalid long integer specified");
}
@ -113,24 +113,24 @@ bool Text::ApplyUlong(Object & value)
Object Text::GetLong() const
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push a long integer instance with the requested value on the stack
SqMod_PushSLongObject(_SqVM, m_Text.as_llong());
SqMod_PushSLongObject(DefaultVM::Get(), m_Text.as_llong());
// Obtain the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ------------------------------------------------------------------------------------------------
void Text::SetLong(Object & value)
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push the specified object onto the stack
Var< Object & >::push(_SqVM, value);
Var< Object & >::push(DefaultVM::Get(), value);
// The resulted long integer value
Int64 longint = 0;
// Attempt to get the numeric value inside the specified object
if (SQ_FAILED(SqMod_GetSLongValue(_SqVM, -1, &longint)))
if (SQ_FAILED(SqMod_GetSLongValue(DefaultVM::Get(), -1, &longint)))
{
STHROWF("Invalid long integer specified");
}
@ -142,24 +142,24 @@ void Text::SetLong(Object & value)
Object Text::GetUlong() const
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push a long integer instance with the requested value on the stack
SqMod_PushULongObject(_SqVM, m_Text.as_ullong());
SqMod_PushULongObject(DefaultVM::Get(), m_Text.as_ullong());
// Obtain the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ------------------------------------------------------------------------------------------------
void Text::SetUlong(Object & value)
{
// Obtain the initial stack size
const StackGuard sg(_SqVM);
const StackGuard sg;
// Push the specified object onto the stack
Var< Object & >::push(_SqVM, value);
Var< Object & >::push(DefaultVM::Get(), value);
// The resulted long integer value
Uint64 longint = 0;
// Attempt to get the numeric value inside the specified object
if (SQ_FAILED(SqMod_GetULongValue(_SqVM, -1, &longint)))
if (SQ_FAILED(SqMod_GetULongValue(DefaultVM::Get(), -1, &longint)))
{
STHROWF("Invalid long integer specified");
}