mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01: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:
parent
5ddb222903
commit
66d1110733
@ -434,6 +434,7 @@
|
||||
</Unit>
|
||||
<Unit filename="../modules/irc/Common.cpp" />
|
||||
<Unit filename="../modules/irc/Common.hpp" />
|
||||
<Unit filename="../modules/irc/Constants.cpp" />
|
||||
<Unit filename="../modules/irc/Module.cpp" />
|
||||
<Unit filename="../modules/irc/Session.cpp" />
|
||||
<Unit filename="../modules/irc/Session.hpp" />
|
||||
|
@ -114,9 +114,9 @@
|
||||
<Option type="3" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-fPIC" />
|
||||
<Add option="-m32" />
|
||||
<Add option="-g" />
|
||||
<Add option="-fPIC" />
|
||||
<Add option="-D_DEBUG" />
|
||||
<Add directory="../config/gcc32" />
|
||||
<Add directory="/usr/include/mysql" />
|
||||
|
@ -91,11 +91,11 @@
|
||||
<Add option="-m32" />
|
||||
<Add option="-g" />
|
||||
<Add option="-D_DEBUG" />
|
||||
<Add directory="../config/mingw32" />
|
||||
<Add directory="../config/gcc32" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-m32" />
|
||||
<Add directory="../lib/mingw32-d" />
|
||||
<Add directory="../lib/gcc32-d" />
|
||||
</Linker>
|
||||
</Target>
|
||||
<Target title="Linux32 Release Executable">
|
||||
@ -109,12 +109,12 @@
|
||||
<Add option="-O3" />
|
||||
<Add option="-m32" />
|
||||
<Add option="-DNDEBUG" />
|
||||
<Add directory="../config/mingw32" />
|
||||
<Add directory="../config/gcc32" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-s" />
|
||||
<Add option="-m32" />
|
||||
<Add directory="../lib/mingw32" />
|
||||
<Add directory="../lib/gcc32" />
|
||||
</Linker>
|
||||
</Target>
|
||||
<Target title="Linux64 Debug Executable">
|
||||
@ -128,11 +128,11 @@
|
||||
<Add option="-m64" />
|
||||
<Add option="-g" />
|
||||
<Add option="-D_DEBUG" />
|
||||
<Add directory="../config/mingw32" />
|
||||
<Add directory="../config/gcc64" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-m64" />
|
||||
<Add directory="../lib/mingw32-d" />
|
||||
<Add directory="../lib/gcc64-d" />
|
||||
</Linker>
|
||||
</Target>
|
||||
<Target title="Linux64 Release Executable">
|
||||
@ -146,12 +146,12 @@
|
||||
<Add option="-O3" />
|
||||
<Add option="-m64" />
|
||||
<Add option="-DNDEBUG" />
|
||||
<Add directory="../config/mingw32" />
|
||||
<Add directory="../config/gcc64" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-s" />
|
||||
<Add option="-m64" />
|
||||
<Add directory="../lib/mingw32" />
|
||||
<Add directory="../lib/gcc64" />
|
||||
</Linker>
|
||||
</Target>
|
||||
</Build>
|
||||
|
@ -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
244
modules/irc/Constants.cpp
Normal 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
|
@ -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
|
||||
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))
|
||||
{
|
||||
OnSquirrelInitialize();
|
||||
if (CheckModuleAPIVer(message, SQIRC_NAME))
|
||||
{
|
||||
try
|
||||
{
|
||||
ImportModuleAPI(_Func, SQIRC_NAME);
|
||||
}
|
||||
break;
|
||||
catch (const Sqrat::Exception & e)
|
||||
{
|
||||
OutputError("%s", e.what());
|
||||
// Failed to initialize
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} 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
|
||||
|
@ -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, µseconds)))
|
||||
if (SQ_FAILED(SqMod_GetTimestamp(DefaultVM::Get(), -1, µseconds)))
|
||||
{
|
||||
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
|
||||
|
@ -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))
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -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
|
||||
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))
|
||||
{
|
||||
OnSquirrelInitialize();
|
||||
if (CheckModuleAPIVer(message, SQJSON_NAME))
|
||||
{
|
||||
try
|
||||
{
|
||||
ImportModuleAPI(_Func, SQJSON_NAME);
|
||||
}
|
||||
break;
|
||||
catch (const Sqrat::Exception & e)
|
||||
{
|
||||
OutputError("%s", e.what());
|
||||
// Failed to initialize
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} 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
|
||||
|
@ -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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* 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
|
||||
OutputError("%s: Cannot register API without a valid virtual machine", SQMG_NAME);
|
||||
// Registration failed
|
||||
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;
|
||||
}
|
||||
Table mgns;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* 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))
|
||||
@ -260,6 +128,130 @@ void RegisterAPI(HSQUIRRELVM vm)
|
||||
.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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -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);
|
||||
static bool RegisterAPI()
|
||||
{
|
||||
// Make sure there's a valid virtual machine before proceeding
|
||||
if (!DefaultVM::Get())
|
||||
{
|
||||
OutputError("%s: Cannot register API without a valid virtual machine", SQMMDB_NAME);
|
||||
// Registration failed
|
||||
return false;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Initialize the plug-in by obtaining the API provided by the host plug-in.
|
||||
*/
|
||||
void OnSquirrelInitialize()
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
// 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
|
||||
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))
|
||||
{
|
||||
OnSquirrelInitialize();
|
||||
if (CheckModuleAPIVer(message, SQMMDB_NAME))
|
||||
{
|
||||
try
|
||||
{
|
||||
ImportModuleAPI(_Func, SQMMDB_NAME);
|
||||
}
|
||||
break;
|
||||
catch (const Sqrat::Exception & e)
|
||||
{
|
||||
OutputError("%s", e.what());
|
||||
// Failed to initialize
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} 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
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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
|
||||
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))
|
||||
{
|
||||
OnSquirrelInitialize();
|
||||
if (CheckModuleAPIVer(message, SQMYSQL_NAME))
|
||||
{
|
||||
try
|
||||
{
|
||||
ImportModuleAPI(_Func, SQMYSQL_NAME);
|
||||
}
|
||||
break;
|
||||
catch (const Sqrat::Exception & e)
|
||||
{
|
||||
OutputError("%s", e.what());
|
||||
// Failed to initialize
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} 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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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);
|
||||
static bool RegisterAPI()
|
||||
{
|
||||
// Make sure there's a valid virtual machine before proceeding
|
||||
if (!DefaultVM::Get())
|
||||
{
|
||||
OutputError("%s: Cannot register API without a valid virtual machine", SQSAMPLE_NAME);
|
||||
// Registration failed
|
||||
return false;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Initialize the plug-in by obtaining the API provided by the host plug-in.
|
||||
*/
|
||||
void OnSquirrelInitialize()
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
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
|
||||
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))
|
||||
{
|
||||
OnSquirrelInitialize();
|
||||
if (CheckModuleAPIVer(message, SQSAMPLE_NAME))
|
||||
{
|
||||
try
|
||||
{
|
||||
ImportModuleAPI(_Func, SQSAMPLE_NAME);
|
||||
}
|
||||
break;
|
||||
catch (const Sqrat::Exception & e)
|
||||
{
|
||||
OutputError("%s", e.what());
|
||||
// Failed to initialize
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} 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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -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
|
||||
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))
|
||||
{
|
||||
OnSquirrelInitialize();
|
||||
if (CheckModuleAPIVer(message, SQSQLITE_NAME))
|
||||
{
|
||||
try
|
||||
{
|
||||
ImportModuleAPI(_Func, SQSQLITE_NAME);
|
||||
}
|
||||
break;
|
||||
catch (const Sqrat::Exception & e)
|
||||
{
|
||||
OutputError("%s", e.what());
|
||||
// Failed to initialize
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} 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
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* 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
|
||||
OutputError("%s: Cannot register API without a valid virtual machine", SQXML_NAME);
|
||||
// Registration failed
|
||||
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;
|
||||
}
|
||||
Table xmlns;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* 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
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -33,18 +33,6 @@ extern PluginFuncs* _Func;
|
||||
extern PluginCallbacks* _Clbk;
|
||||
extern PluginInfo* _Info;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#ifdef SQMOD_PLUGIN_API
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Proxies to comunicate with the Squirrel plug-in.
|
||||
*/
|
||||
extern HSQAPI _SqAPI;
|
||||
extern HSQEXPORTS _SqMod;
|
||||
extern HSQUIRRELVM _SqVM;
|
||||
|
||||
#endif // SQMOD_PLUGIN_API
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the temporary buffer.
|
||||
*/
|
||||
@ -1542,6 +1530,26 @@ Int64 PopStackSLong(HSQUIRRELVM vm, SQInteger idx);
|
||||
*/
|
||||
Uint64 PopStackULong(HSQUIRRELVM vm, SQInteger idx);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#ifdef SQMOD_PLUGIN_API
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Validate the module API to make sure we don't run into issues.
|
||||
*/
|
||||
bool CheckModuleAPIVer(CCStr ver, CCStr mod);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Make sure that the module was loaded after the host plug-in.
|
||||
*/
|
||||
bool CheckModuleOrder(PluginFuncs * vcapi, Uint32 mod_id, CCStr mod);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Used by the modules to import the API from the host plug-in.
|
||||
*/
|
||||
void ImportModuleAPI(PluginFuncs * vcapi, CCStr mod);
|
||||
|
||||
#endif // SQMOD_PLUGIN_API
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _BASE_UTILITY_HPP_
|
||||
|
@ -29,15 +29,6 @@ PluginFuncs* _Func = nullptr;
|
||||
PluginCallbacks* _Clbk = nullptr;
|
||||
PluginInfo* _Info = nullptr;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#ifdef SQMOD_PLUGIN_API
|
||||
|
||||
HSQAPI _SqAPI = nullptr;
|
||||
HSQEXPORTS _SqMod = nullptr;
|
||||
HSQUIRRELVM _SqVM = nullptr;
|
||||
|
||||
#endif // SQMOD_PLUGIN_API
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Common buffers to reduce memory allocations. To be immediately copied upon return!
|
||||
*/
|
||||
@ -1383,4 +1374,136 @@ Uint64 PopStackULong(HSQUIRRELVM vm, SQInteger idx)
|
||||
#endif // SQMOD_PLUGIN_API
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#ifdef SQMOD_PLUGIN_API
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool CheckModuleAPIVer(CCStr ver, CCStr mod)
|
||||
{
|
||||
// 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", mod);
|
||||
OutputMessage("=> Requested: %ld Have: %ld", vernum, SQMOD_API_VER);
|
||||
// Invoker should not attempt to communicate through the module API
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool CheckModuleOrder(PluginFuncs * vcapi, Uint32 mod_id, CCStr mod)
|
||||
{
|
||||
// Make sure a valid server API was provided
|
||||
if (!vcapi)
|
||||
{
|
||||
OutputError("Invalid pointer to server API structure");
|
||||
// Validation failed!
|
||||
return false;
|
||||
}
|
||||
// Attempt to find the host plug-in identifier
|
||||
const int plugin_id = vcapi->FindPlugin(SQMOD_HOST_NAME);
|
||||
// See if our module was loaded after the host plug-in
|
||||
if (plugin_id < 0)
|
||||
{
|
||||
OutputError("%s: could find the host plug-in", mod);
|
||||
// Validation failed!
|
||||
return false;
|
||||
}
|
||||
// Should never reach this point but just in case
|
||||
else if (static_cast< Uint32 >(plugin_id) > mod_id)
|
||||
{
|
||||
OutputError("%s: loaded after the host plug-in", mod);
|
||||
// Validation failed!
|
||||
return false;
|
||||
}
|
||||
// Loaded in the correct order
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ImportModuleAPI(PluginFuncs * vcapi, CCStr mod)
|
||||
{
|
||||
// Make sure a valid server API was provided
|
||||
if (!vcapi)
|
||||
{
|
||||
STHROWF("%s: Invalid pointer to server API structure", mod);
|
||||
}
|
||||
|
||||
size_t exports_struct_size;
|
||||
|
||||
// Attempt to find the host plug-in identifier
|
||||
int plugin_id = vcapi->FindPlugin(SQMOD_HOST_NAME);
|
||||
// Validate the obtained plug-in identifier
|
||||
if (plugin_id < 0)
|
||||
{
|
||||
STHROWF("%s: Unable to obtain the host plug-in identifier", mod);
|
||||
}
|
||||
|
||||
// Attempt to retrieve the host plug-in exports
|
||||
const void ** raw_plugin_exports = vcapi->GetPluginExports(plugin_id, &exports_struct_size);
|
||||
// See if the size of the exports structure matches
|
||||
if (exports_struct_size <= 0)
|
||||
{
|
||||
STHROWF("%s: Incompatible host plug-in exports structure", mod);
|
||||
}
|
||||
// See if we have any exports from the host plug-in
|
||||
else if (raw_plugin_exports == nullptr)
|
||||
{
|
||||
STHROWF("%s: Unable to obtain pointer host plug-in exports", mod);
|
||||
}
|
||||
|
||||
// Obtain pointer to the exports structure
|
||||
const SQMODEXPORTS * plugin_exports = *reinterpret_cast< const SQMODEXPORTS ** >(raw_plugin_exports);
|
||||
// See if we have a valid pointer to the exports structure
|
||||
if (plugin_exports == nullptr)
|
||||
{
|
||||
STHROWF("%s: Invalid pointer to host plug-in exports structure", mod);
|
||||
}
|
||||
else if (plugin_exports->PopulateModuleAPI == nullptr || plugin_exports->PopulateSquirrelAPI == nullptr)
|
||||
{
|
||||
STHROWF("%s: Invalid pointer to host plug-in import functions", mod);
|
||||
}
|
||||
|
||||
// Prepare a structure to obtain the module API
|
||||
SQMODAPI sqmodapi;
|
||||
// Attempt to populate the structure
|
||||
switch (plugin_exports->PopulateModuleAPI(&sqmodapi, sizeof(SQMODAPI)))
|
||||
{
|
||||
case -1: STHROWF("%s: Incompatible module API structure", mod);
|
||||
case 0: STHROWF("%s: Invalid pointer to module API structure", mod);
|
||||
}
|
||||
|
||||
// Prepare a structure to obtain the squirrel API
|
||||
SQLIBAPI sqlibapi;
|
||||
// Attempt to populate the structure
|
||||
switch (plugin_exports->PopulateSquirrelAPI(&sqlibapi, sizeof(SQLIBAPI)))
|
||||
{
|
||||
case -1: STHROWF("%s: Incompatible squirrel API structure", mod);
|
||||
case 0: STHROWF("%s: Invalid pointer to squirrel API structure", mod);
|
||||
}
|
||||
|
||||
// Attempt to expand the obtained API
|
||||
if (!sqmod_api_expand(&sqmodapi))
|
||||
{
|
||||
// Collapse the API first
|
||||
sqmod_api_collapse();
|
||||
// Now it's safe to throw the exception
|
||||
STHROWF("%s: Unable to expand module API structure", mod);
|
||||
}
|
||||
else if (!sqlib_api_expand(&sqlibapi))
|
||||
{
|
||||
// Collapse the API first
|
||||
sqmod_api_collapse();
|
||||
sqlib_api_collapse();
|
||||
// Now it's safe to throw the exception
|
||||
STHROWF("%s: Unable to expand module API structure", mod);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SQMOD_PLUGIN_API
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
1104
shared/SqAPI.h
1104
shared/SqAPI.h
File diff suppressed because it is too large
Load Diff
288
shared/SqMod.h
288
shared/SqMod.h
@ -62,204 +62,206 @@ extern "C" {
|
||||
#define SQMOD_API_VER 1
|
||||
|
||||
//primitive functions
|
||||
typedef HSQAPI (*SqEx_GetSquirrelAPI) (void);
|
||||
typedef HSQUIRRELVM (*SqEx_GetSquirrelVM) (void);
|
||||
typedef HSQUIRRELVM (*SqModAPI_GetSquirrelVM) (void);
|
||||
//logging utilities
|
||||
typedef void (*SqEx_LogMessage) (const SQChar * fmt, ...);
|
||||
typedef void (*SqModAPI_LogMessage) (const SQChar * fmt, ...);
|
||||
//script loading
|
||||
typedef SQRESULT (*SqEx_LoadScript) (const SQChar * filepath, SQBool delay);
|
||||
typedef SQRESULT (*SqModAPI_LoadScript) (const SQChar * filepath, SQBool delay);
|
||||
//numeric utilities
|
||||
typedef SQRESULT (*SqEx_GetSLongValue) (HSQUIRRELVM vm, SQInteger idx, SqInt64 * num);
|
||||
typedef SQRESULT (*SqEx_PushSLongObject) (HSQUIRRELVM vm, SqInt64 num);
|
||||
typedef SQRESULT (*SqEx_GetULongValue) (HSQUIRRELVM vm, SQInteger idx, SqUint64 * num);
|
||||
typedef SQRESULT (*SqEx_PushULongObject) (HSQUIRRELVM vm, SqUint64 num);
|
||||
typedef SQRESULT (*SqModAPI_GetSLongValue) (HSQUIRRELVM vm, SQInteger idx, SqInt64 * num);
|
||||
typedef SQRESULT (*SqModAPI_PushSLongObject) (HSQUIRRELVM vm, SqInt64 num);
|
||||
typedef SQRESULT (*SqModAPI_GetULongValue) (HSQUIRRELVM vm, SQInteger idx, SqUint64 * num);
|
||||
typedef SQRESULT (*SqModAPI_PushULongObject) (HSQUIRRELVM vm, SqUint64 num);
|
||||
//time utilities
|
||||
typedef SqInt64 (*SqEx_GetCurrentSysTime) (void);
|
||||
typedef SqInt64 (*SqEx_GetEpochTimeMicro) (void);
|
||||
typedef SqInt64 (*SqEx_GetEpochTimeMilli) (void);
|
||||
typedef SQBool (*SqEx_ValidDate) (uint16_t year, uint8_t month, uint8_t day);
|
||||
typedef SQBool (*SqEx_IsLeapYear) (uint16_t year);
|
||||
typedef uint16_t (*SqEx_DaysInYear) (uint16_t year);
|
||||
typedef uint8_t (*SqEx_DaysInMonth) (uint16_t year, uint8_t month);
|
||||
typedef uint16_t (*SqEx_DayOfYear) (uint16_t year, uint8_t month, uint8_t day);
|
||||
typedef SqInt64 (*SqEx_DateRangeToSeconds) (uint16_t lyear, uint8_t lmonth, uint8_t lday, uint16_t ryear, uint8_t rmonth, uint8_t rday);
|
||||
typedef SQRESULT (*SqEx_GetTimestamp) (HSQUIRRELVM vm, SQInteger idx, SqInt64 * num);
|
||||
typedef SQRESULT (*SqEx_PushTimestamp) (HSQUIRRELVM vm, SqInt64 num);
|
||||
typedef SQRESULT (*SqEx_GetDate) (HSQUIRRELVM vm, SQInteger idx, uint16_t * year, uint8_t * month, uint8_t * day);
|
||||
typedef SQRESULT (*SqEx_PushDate) (HSQUIRRELVM vm, uint16_t year, uint8_t month, uint8_t day);
|
||||
typedef SQRESULT (*SqEx_GetTime) (HSQUIRRELVM vm, SQInteger idx, uint8_t * hour, uint8_t * minute, uint8_t * second, uint16_t * millisecond);
|
||||
typedef SQRESULT (*SqEx_PushTime) (HSQUIRRELVM vm, uint8_t hour, uint8_t minute, uint8_t second, uint16_t millisecond);
|
||||
typedef SQRESULT (*SqEx_GetDatetime) (HSQUIRRELVM vm, SQInteger idx, uint16_t * year, uint8_t * month, uint8_t * day, uint8_t * hour, uint8_t * minute, uint8_t * second, uint16_t * millisecond);
|
||||
typedef SQRESULT (*SqEx_PushDatetime) (HSQUIRRELVM vm, uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint16_t millisecond);
|
||||
typedef SqInt64 (*SqModAPI_GetCurrentSysTime) (void);
|
||||
typedef SqInt64 (*SqModAPI_GetEpochTimeMicro) (void);
|
||||
typedef SqInt64 (*SqModAPI_GetEpochTimeMilli) (void);
|
||||
typedef SQBool (*SqModAPI_ValidDate) (uint16_t year, uint8_t month, uint8_t day);
|
||||
typedef SQBool (*SqModAPI_IsLeapYear) (uint16_t year);
|
||||
typedef uint16_t (*SqModAPI_DaysInYear) (uint16_t year);
|
||||
typedef uint8_t (*SqModAPI_DaysInMonth) (uint16_t year, uint8_t month);
|
||||
typedef uint16_t (*SqModAPI_DayOfYear) (uint16_t year, uint8_t month, uint8_t day);
|
||||
typedef SqInt64 (*SqModAPI_DateRangeToSeconds) (uint16_t lyear, uint8_t lmonth, uint8_t lday, uint16_t ryear, uint8_t rmonth, uint8_t rday);
|
||||
typedef SQRESULT (*SqModAPI_GetTimestamp) (HSQUIRRELVM vm, SQInteger idx, SqInt64 * num);
|
||||
typedef SQRESULT (*SqModAPI_PushTimestamp) (HSQUIRRELVM vm, SqInt64 num);
|
||||
typedef SQRESULT (*SqModAPI_GetDate) (HSQUIRRELVM vm, SQInteger idx, uint16_t * year, uint8_t * month, uint8_t * day);
|
||||
typedef SQRESULT (*SqModAPI_PushDate) (HSQUIRRELVM vm, uint16_t year, uint8_t month, uint8_t day);
|
||||
typedef SQRESULT (*SqModAPI_GetTime) (HSQUIRRELVM vm, SQInteger idx, uint8_t * hour, uint8_t * minute, uint8_t * second, uint16_t * millisecond);
|
||||
typedef SQRESULT (*SqModAPI_PushTime) (HSQUIRRELVM vm, uint8_t hour, uint8_t minute, uint8_t second, uint16_t millisecond);
|
||||
typedef SQRESULT (*SqModAPI_GetDatetime) (HSQUIRRELVM vm, SQInteger idx, uint16_t * year, uint8_t * month, uint8_t * day, uint8_t * hour, uint8_t * minute, uint8_t * second, uint16_t * millisecond);
|
||||
typedef SQRESULT (*SqModAPI_PushDatetime) (HSQUIRRELVM vm, uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint16_t millisecond);
|
||||
//stack utilities
|
||||
typedef SQInteger (*SqEx_PopStackInteger) (HSQUIRRELVM vm, SQInteger idx);
|
||||
typedef SQFloat (*SqEx_PopStackFloat) (HSQUIRRELVM vm, SQInteger idx);
|
||||
typedef SqInt64 (*SqEx_PopStackSLong) (HSQUIRRELVM vm, SQInteger idx);
|
||||
typedef SqUint64 (*SqEx_PopStackULong) (HSQUIRRELVM vm, SQInteger idx);
|
||||
typedef SQInteger (*SqModAPI_PopStackInteger) (HSQUIRRELVM vm, SQInteger idx);
|
||||
typedef SQFloat (*SqModAPI_PopStackFloat) (HSQUIRRELVM vm, SQInteger idx);
|
||||
typedef SqInt64 (*SqModAPI_PopStackSLong) (HSQUIRRELVM vm, SQInteger idx);
|
||||
typedef SqUint64 (*SqModAPI_PopStackULong) (HSQUIRRELVM vm, SQInteger idx);
|
||||
//buffer utilities
|
||||
typedef SQRESULT (*SqEx_PushBuffer) (HSQUIRRELVM vm, SQInteger size, SQInteger cursor);
|
||||
typedef SQRESULT (*SqEx_PushBufferData) (HSQUIRRELVM vm, const char * data, SQInteger size, SQInteger cursor);
|
||||
typedef SQRESULT (*SqEx_GetBufferInfo) (HSQUIRRELVM vm, SQInteger idx, const char ** ptr, SQInteger * size, SQInteger * cursor);
|
||||
typedef const char * (*SqEx_GetBufferData) (HSQUIRRELVM vm, SQInteger idx);
|
||||
typedef SQInteger (*SqEx_GetBufferSize) (HSQUIRRELVM vm, SQInteger idx);
|
||||
typedef SQInteger (*SqEx_GetBufferCursor) (HSQUIRRELVM vm, SQInteger idx);
|
||||
typedef SQRESULT (*SqModAPI_PushBuffer) (HSQUIRRELVM vm, SQInteger size, SQInteger cursor);
|
||||
typedef SQRESULT (*SqModAPI_PushBufferData) (HSQUIRRELVM vm, const char * data, SQInteger size, SQInteger cursor);
|
||||
typedef SQRESULT (*SqModAPI_GetBufferInfo) (HSQUIRRELVM vm, SQInteger idx, const char ** ptr, SQInteger * size, SQInteger * cursor);
|
||||
typedef const char * (*SqModAPI_GetBufferData) (HSQUIRRELVM vm, SQInteger idx);
|
||||
typedef SQInteger (*SqModAPI_GetBufferSize) (HSQUIRRELVM vm, SQInteger idx);
|
||||
typedef SQInteger (*SqModAPI_GetBufferCursor) (HSQUIRRELVM vm, SQInteger idx);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Allows modules to interface with the plug-in API without linking of any sorts
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
unsigned int StructSize;
|
||||
//primitive functions
|
||||
SqEx_GetSquirrelAPI GetSquirrelAPI;
|
||||
SqEx_GetSquirrelVM GetSquirrelVM;
|
||||
SqModAPI_GetSquirrelVM GetSquirrelVM;
|
||||
//logging utilities
|
||||
SqEx_LogMessage LogDbg;
|
||||
SqEx_LogMessage LogUsr;
|
||||
SqEx_LogMessage LogScs;
|
||||
SqEx_LogMessage LogInf;
|
||||
SqEx_LogMessage LogWrn;
|
||||
SqEx_LogMessage LogErr;
|
||||
SqEx_LogMessage LogFtl;
|
||||
SqEx_LogMessage LogSDbg;
|
||||
SqEx_LogMessage LogSUsr;
|
||||
SqEx_LogMessage LogSScs;
|
||||
SqEx_LogMessage LogSInf;
|
||||
SqEx_LogMessage LogSWrn;
|
||||
SqEx_LogMessage LogSErr;
|
||||
SqEx_LogMessage LogSFtl;
|
||||
SqModAPI_LogMessage LogDbg;
|
||||
SqModAPI_LogMessage LogUsr;
|
||||
SqModAPI_LogMessage LogScs;
|
||||
SqModAPI_LogMessage LogInf;
|
||||
SqModAPI_LogMessage LogWrn;
|
||||
SqModAPI_LogMessage LogErr;
|
||||
SqModAPI_LogMessage LogFtl;
|
||||
SqModAPI_LogMessage LogSDbg;
|
||||
SqModAPI_LogMessage LogSUsr;
|
||||
SqModAPI_LogMessage LogSScs;
|
||||
SqModAPI_LogMessage LogSInf;
|
||||
SqModAPI_LogMessage LogSWrn;
|
||||
SqModAPI_LogMessage LogSErr;
|
||||
SqModAPI_LogMessage LogSFtl;
|
||||
//script loading
|
||||
SqEx_LoadScript LoadScript;
|
||||
SqModAPI_LoadScript LoadScript;
|
||||
//numeric utilities
|
||||
SqEx_GetSLongValue GetSLongValue;
|
||||
SqEx_PushSLongObject PushSLongObject;
|
||||
SqEx_GetULongValue GetULongValue;
|
||||
SqEx_PushULongObject PushULongObject;
|
||||
SqModAPI_GetSLongValue GetSLongValue;
|
||||
SqModAPI_PushSLongObject PushSLongObject;
|
||||
SqModAPI_GetULongValue GetULongValue;
|
||||
SqModAPI_PushULongObject PushULongObject;
|
||||
//time utilities
|
||||
SqEx_GetCurrentSysTime GetCurrentSysTime;
|
||||
SqEx_GetEpochTimeMicro GetEpochTimeMicro;
|
||||
SqEx_GetEpochTimeMilli GetEpochTimeMilli;
|
||||
SqEx_ValidDate ValidDate;
|
||||
SqEx_IsLeapYear IsLeapYear;
|
||||
SqEx_DaysInYear DaysInYear;
|
||||
SqEx_DaysInMonth DaysInMonth;
|
||||
SqEx_DayOfYear DayOfYear;
|
||||
SqEx_DateRangeToSeconds DateRangeToSeconds;
|
||||
SqEx_GetTimestamp GetTimestamp;
|
||||
SqEx_PushTimestamp PushTimestamp;
|
||||
SqEx_GetDate GetDate;
|
||||
SqEx_PushDate PushDate;
|
||||
SqEx_GetTime GetTime;
|
||||
SqEx_PushTime PushTime;
|
||||
SqEx_GetDatetime GetDatetime;
|
||||
SqEx_PushDatetime PushDatetime;
|
||||
SqModAPI_GetCurrentSysTime GetCurrentSysTime;
|
||||
SqModAPI_GetEpochTimeMicro GetEpochTimeMicro;
|
||||
SqModAPI_GetEpochTimeMilli GetEpochTimeMilli;
|
||||
SqModAPI_ValidDate ValidDate;
|
||||
SqModAPI_IsLeapYear IsLeapYear;
|
||||
SqModAPI_DaysInYear DaysInYear;
|
||||
SqModAPI_DaysInMonth DaysInMonth;
|
||||
SqModAPI_DayOfYear DayOfYear;
|
||||
SqModAPI_DateRangeToSeconds DateRangeToSeconds;
|
||||
SqModAPI_GetTimestamp GetTimestamp;
|
||||
SqModAPI_PushTimestamp PushTimestamp;
|
||||
SqModAPI_GetDate GetDate;
|
||||
SqModAPI_PushDate PushDate;
|
||||
SqModAPI_GetTime GetTime;
|
||||
SqModAPI_PushTime PushTime;
|
||||
SqModAPI_GetDatetime GetDatetime;
|
||||
SqModAPI_PushDatetime PushDatetime;
|
||||
//stack utilities
|
||||
SqEx_PopStackInteger PopStackInteger;
|
||||
SqEx_PopStackFloat PopStackFloat;
|
||||
SqEx_PopStackSLong PopStackSLong;
|
||||
SqEx_PopStackULong PopStackULong;
|
||||
SqModAPI_PopStackInteger PopStackInteger;
|
||||
SqModAPI_PopStackFloat PopStackFloat;
|
||||
SqModAPI_PopStackSLong PopStackSLong;
|
||||
SqModAPI_PopStackULong PopStackULong;
|
||||
//buffer utilities
|
||||
SqEx_PushBuffer PushBuffer;
|
||||
SqEx_PushBufferData PushBufferData;
|
||||
SqEx_GetBufferInfo GetBufferInfo;
|
||||
SqEx_GetBufferData GetBufferData;
|
||||
SqEx_GetBufferSize GetBufferSize;
|
||||
SqEx_GetBufferCursor GetBufferCursor;
|
||||
} sq_exports, SQEXPORTS, *HSQEXPORTS;
|
||||
SqModAPI_PushBuffer PushBuffer;
|
||||
SqModAPI_PushBufferData PushBufferData;
|
||||
SqModAPI_GetBufferInfo GetBufferInfo;
|
||||
SqModAPI_GetBufferData GetBufferData;
|
||||
SqModAPI_GetBufferSize GetBufferSize;
|
||||
SqModAPI_GetBufferCursor GetBufferCursor;
|
||||
} sq_modapi, SQMODAPI, *HSQMODAPI;
|
||||
|
||||
#ifdef SQMOD_PLUGIN_API
|
||||
|
||||
//primitive functions
|
||||
extern SqEx_GetSquirrelAPI SqMod_GetSquirrelAPI;
|
||||
extern SqEx_GetSquirrelVM SqMod_GetSquirrelVM;
|
||||
extern SqModAPI_GetSquirrelVM SqMod_GetSquirrelVM;
|
||||
|
||||
//logging utilities
|
||||
extern SqEx_LogMessage SqMod_LogDbg;
|
||||
extern SqEx_LogMessage SqMod_LogUsr;
|
||||
extern SqEx_LogMessage SqMod_LogScs;
|
||||
extern SqEx_LogMessage SqMod_LogInf;
|
||||
extern SqEx_LogMessage SqMod_LogWrn;
|
||||
extern SqEx_LogMessage SqMod_LogErr;
|
||||
extern SqEx_LogMessage SqMod_LogFtl;
|
||||
extern SqEx_LogMessage SqMod_LogSDbg;
|
||||
extern SqEx_LogMessage SqMod_LogSUsr;
|
||||
extern SqEx_LogMessage SqMod_LogSScs;
|
||||
extern SqEx_LogMessage SqMod_LogSInf;
|
||||
extern SqEx_LogMessage SqMod_LogSWrn;
|
||||
extern SqEx_LogMessage SqMod_LogSErr;
|
||||
extern SqEx_LogMessage SqMod_LogSFtl;
|
||||
extern SqModAPI_LogMessage SqMod_LogDbg;
|
||||
extern SqModAPI_LogMessage SqMod_LogUsr;
|
||||
extern SqModAPI_LogMessage SqMod_LogScs;
|
||||
extern SqModAPI_LogMessage SqMod_LogInf;
|
||||
extern SqModAPI_LogMessage SqMod_LogWrn;
|
||||
extern SqModAPI_LogMessage SqMod_LogErr;
|
||||
extern SqModAPI_LogMessage SqMod_LogFtl;
|
||||
extern SqModAPI_LogMessage SqMod_LogSDbg;
|
||||
extern SqModAPI_LogMessage SqMod_LogSUsr;
|
||||
extern SqModAPI_LogMessage SqMod_LogSScs;
|
||||
extern SqModAPI_LogMessage SqMod_LogSInf;
|
||||
extern SqModAPI_LogMessage SqMod_LogSWrn;
|
||||
extern SqModAPI_LogMessage SqMod_LogSErr;
|
||||
extern SqModAPI_LogMessage SqMod_LogSFtl;
|
||||
|
||||
//script loading
|
||||
extern SqEx_LoadScript SqMod_LoadScript;
|
||||
extern SqModAPI_LoadScript SqMod_LoadScript;
|
||||
|
||||
//numeric utilities
|
||||
extern SqEx_GetSLongValue SqMod_GetSLongValue;
|
||||
extern SqEx_PushSLongObject SqMod_PushSLongObject;
|
||||
extern SqEx_GetULongValue SqMod_GetULongValue;
|
||||
extern SqEx_PushULongObject SqMod_PushULongObject;
|
||||
extern SqModAPI_GetSLongValue SqMod_GetSLongValue;
|
||||
extern SqModAPI_PushSLongObject SqMod_PushSLongObject;
|
||||
extern SqModAPI_GetULongValue SqMod_GetULongValue;
|
||||
extern SqModAPI_PushULongObject SqMod_PushULongObject;
|
||||
|
||||
//time utilities
|
||||
extern SqEx_GetCurrentSysTime SqMod_GetCurrentSysTime;
|
||||
extern SqEx_GetEpochTimeMicro SqMod_GetEpochTimeMicro;
|
||||
extern SqEx_GetEpochTimeMilli SqMod_GetEpochTimeMilli;
|
||||
extern SqEx_ValidDate SqMod_ValidDate;
|
||||
extern SqEx_IsLeapYear SqMod_IsLeapYear;
|
||||
extern SqEx_DaysInYear SqMod_DaysInYear;
|
||||
extern SqEx_DaysInMonth SqMod_DaysInMonth;
|
||||
extern SqEx_DayOfYear SqMod_DayOfYear;
|
||||
extern SqEx_DateRangeToSeconds SqMod_DateRangeToSeconds;
|
||||
extern SqEx_GetTimestamp SqMod_GetTimestamp;
|
||||
extern SqEx_PushTimestamp SqMod_PushTimestamp;
|
||||
extern SqEx_GetDate SqMod_GetDate;
|
||||
extern SqEx_PushDate SqMod_PushDate;
|
||||
extern SqEx_GetTime SqMod_GetTime;
|
||||
extern SqEx_PushTime SqMod_PushTime;
|
||||
extern SqEx_GetDatetime SqMod_GetDatetime;
|
||||
extern SqEx_PushDatetime SqMod_PushDatetime;
|
||||
extern SqModAPI_GetCurrentSysTime SqMod_GetCurrentSysTime;
|
||||
extern SqModAPI_GetEpochTimeMicro SqMod_GetEpochTimeMicro;
|
||||
extern SqModAPI_GetEpochTimeMilli SqMod_GetEpochTimeMilli;
|
||||
extern SqModAPI_ValidDate SqMod_ValidDate;
|
||||
extern SqModAPI_IsLeapYear SqMod_IsLeapYear;
|
||||
extern SqModAPI_DaysInYear SqMod_DaysInYear;
|
||||
extern SqModAPI_DaysInMonth SqMod_DaysInMonth;
|
||||
extern SqModAPI_DayOfYear SqMod_DayOfYear;
|
||||
extern SqModAPI_DateRangeToSeconds SqMod_DateRangeToSeconds;
|
||||
extern SqModAPI_GetTimestamp SqMod_GetTimestamp;
|
||||
extern SqModAPI_PushTimestamp SqMod_PushTimestamp;
|
||||
extern SqModAPI_GetDate SqMod_GetDate;
|
||||
extern SqModAPI_PushDate SqMod_PushDate;
|
||||
extern SqModAPI_GetTime SqMod_GetTime;
|
||||
extern SqModAPI_PushTime SqMod_PushTime;
|
||||
extern SqModAPI_GetDatetime SqMod_GetDatetime;
|
||||
extern SqModAPI_PushDatetime SqMod_PushDatetime;
|
||||
|
||||
//stack utilities
|
||||
extern SqEx_PopStackInteger SqMod_PopStackInteger;
|
||||
extern SqEx_PopStackFloat SqMod_PopStackFloat;
|
||||
extern SqEx_PopStackSLong SqMod_PopStackSLong;
|
||||
extern SqEx_PopStackULong SqMod_PopStackULong;
|
||||
extern SqModAPI_PopStackInteger SqMod_PopStackInteger;
|
||||
extern SqModAPI_PopStackFloat SqMod_PopStackFloat;
|
||||
extern SqModAPI_PopStackSLong SqMod_PopStackSLong;
|
||||
extern SqModAPI_PopStackULong SqMod_PopStackULong;
|
||||
|
||||
//buffer utilities
|
||||
extern SqEx_PushBuffer SqMod_PushBuffer;
|
||||
extern SqEx_PushBufferData SqMod_PushBufferData;
|
||||
extern SqEx_GetBufferInfo SqMod_GetBufferInfo;
|
||||
extern SqEx_GetBufferData SqMod_GetBufferData;
|
||||
extern SqEx_GetBufferSize SqMod_GetBufferSize;
|
||||
extern SqEx_GetBufferCursor SqMod_GetBufferCursor;
|
||||
extern SqModAPI_PushBuffer SqMod_PushBuffer;
|
||||
extern SqModAPI_PushBufferData SqMod_PushBufferData;
|
||||
extern SqModAPI_GetBufferInfo SqMod_GetBufferInfo;
|
||||
extern SqModAPI_GetBufferData SqMod_GetBufferData;
|
||||
extern SqModAPI_GetBufferSize SqMod_GetBufferSize;
|
||||
extern SqModAPI_GetBufferCursor SqMod_GetBufferCursor;
|
||||
|
||||
#endif // SQMOD_PLUGIN_API
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Import the functions from the main squirrel plug-in.
|
||||
* The structure exported by the host plug-in to import the module and squirrel API.
|
||||
*/
|
||||
SQUIRREL_API HSQEXPORTS sq_api_import(PluginFuncs * vcapi);
|
||||
typedef struct
|
||||
{
|
||||
unsigned int StructSize;
|
||||
//base functions
|
||||
int32_t (*PopulateModuleAPI) (HSQMODAPI api, size_t size);
|
||||
int32_t (*PopulateSquirrelAPI) (HSQLIBAPI api, size_t size);
|
||||
} sq_modexports, SQMODEXPORTS, *HSQMODEXPORTS;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Assign the functions from the specified API structure into the global functions.
|
||||
*/
|
||||
SQUIRREL_API SQRESULT sq_api_expand(HSQAPI sqapi);
|
||||
SQUIRREL_API uint8_t sqmod_api_expand(HSQMODAPI sqmodapi);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Assign the functions from the specified API structure into the global functions.
|
||||
*/
|
||||
SQUIRREL_API SQRESULT sqmod_api_expand(HSQEXPORTS sqmodapi);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Undo changes done by sq_api_expand.
|
||||
*/
|
||||
SQUIRREL_API void sq_api_collapse();
|
||||
SQUIRREL_API uint8_t sqlib_api_expand(HSQLIBAPI sqlibapi);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Undo changes done by sqmod_api_expand.
|
||||
*/
|
||||
SQUIRREL_API void sqmod_api_collapse();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Undo changes done by sq_api_expand.
|
||||
*/
|
||||
SQUIRREL_API void sqlib_api_collapse();
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*_SQ_API_H_*/
|
||||
#endif /*_SQ_MOD_H_*/
|
||||
|
1266
shared/SqMod.inl
1266
shared/SqMod.inl
File diff suppressed because it is too large
Load Diff
@ -24,16 +24,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static SQAPI g_SqAPI;
|
||||
static SQEXPORTS g_SqExports;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static HSQAPI GetSquirrelAPI()
|
||||
{
|
||||
return &g_SqAPI;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static HSQUIRRELVM GetSquirrelVM()
|
||||
{
|
||||
@ -48,7 +38,7 @@ static SQRESULT SqEx_LoadScript(const SQChar * filepath, SQBool delay)
|
||||
{
|
||||
return SQ_OK; // The script as added or already existed
|
||||
}
|
||||
// The path was invalied or was unable to pool the script
|
||||
// The path was invalid or was unable to pool the script
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
@ -220,7 +210,7 @@ static SQRESULT SqEx_GetTimestamp(HSQUIRRELVM vm, SQInteger idx, Int64 * num)
|
||||
{
|
||||
return SQ_ERROR; // Nowhere to save
|
||||
}
|
||||
// Is this an instance that we can treat as a Timestamp type?
|
||||
// Is this an instance that we can treat as a Time-stamp type?
|
||||
else if (sq_gettype(vm, idx) == OT_INSTANCE)
|
||||
{
|
||||
// Attempt to obtain the time-stamp and it's value from the stack
|
||||
@ -413,7 +403,7 @@ SQRESULT SqEx_PushTime(HSQUIRRELVM vm, uint8_t hour, uint8_t minute, uint8_t sec
|
||||
SQRESULT SqEx_GetDatetime(HSQUIRRELVM vm, SQInteger idx, uint16_t * year, uint8_t * month, uint8_t * day,
|
||||
uint8_t * hour, uint8_t * minute, uint8_t * second, uint16_t * millisecond)
|
||||
{
|
||||
// Is this an instance that we can treat as a Datetime type?
|
||||
// Is this an instance that we can treat as a Date-time type?
|
||||
if (sq_gettype(vm, idx) == OT_INSTANCE)
|
||||
{
|
||||
// Attempt to obtain the time-stamp and it's value from the stack
|
||||
@ -644,258 +634,293 @@ SQInteger SqEx_GetBufferCursor(HSQUIRRELVM vm, SQInteger idx)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void InitExports()
|
||||
static int32_t SqExport_PopulateModuleAPI(HSQMODAPI api, size_t size)
|
||||
{
|
||||
static HSQEXPORTS sqexports = &g_SqExports;
|
||||
if (!api)
|
||||
{
|
||||
return 0; // Nothing to populate!
|
||||
}
|
||||
else if (size != sizeof(SQMODAPI))
|
||||
{
|
||||
return -1; // Incompatible API!
|
||||
}
|
||||
|
||||
// Assign the functions that should be exported
|
||||
g_SqExports.StructSize = sizeof(SQEXPORTS);
|
||||
g_SqExports.GetSquirrelAPI = GetSquirrelAPI;
|
||||
g_SqExports.GetSquirrelVM = GetSquirrelVM;
|
||||
//primitive functions
|
||||
api->GetSquirrelVM = GetSquirrelVM;
|
||||
|
||||
//logging utilities
|
||||
g_SqExports.LogDbg = LogDbg;
|
||||
g_SqExports.LogUsr = LogUsr;
|
||||
g_SqExports.LogScs = LogScs;
|
||||
g_SqExports.LogInf = LogInf;
|
||||
g_SqExports.LogWrn = LogWrn;
|
||||
g_SqExports.LogErr = LogErr;
|
||||
g_SqExports.LogFtl = LogFtl;
|
||||
g_SqExports.LogSDbg = LogSDbg;
|
||||
g_SqExports.LogSUsr = LogSUsr;
|
||||
g_SqExports.LogSScs = LogSScs;
|
||||
g_SqExports.LogSInf = LogSInf;
|
||||
g_SqExports.LogSWrn = LogSWrn;
|
||||
g_SqExports.LogSErr = LogSErr;
|
||||
g_SqExports.LogSFtl = LogSFtl;
|
||||
api->LogDbg = LogDbg;
|
||||
api->LogUsr = LogUsr;
|
||||
api->LogScs = LogScs;
|
||||
api->LogInf = LogInf;
|
||||
api->LogWrn = LogWrn;
|
||||
api->LogErr = LogErr;
|
||||
api->LogFtl = LogFtl;
|
||||
api->LogSDbg = LogSDbg;
|
||||
api->LogSUsr = LogSUsr;
|
||||
api->LogSScs = LogSScs;
|
||||
api->LogSInf = LogSInf;
|
||||
api->LogSWrn = LogSWrn;
|
||||
api->LogSErr = LogSErr;
|
||||
api->LogSFtl = LogSFtl;
|
||||
|
||||
//script loading
|
||||
g_SqExports.LoadScript = SqEx_LoadScript;
|
||||
api->LoadScript = SqEx_LoadScript;
|
||||
|
||||
//numeric utilities
|
||||
g_SqExports.GetSLongValue = SqEx_GetSLongValue;
|
||||
g_SqExports.PushSLongObject = SqEx_PushSLongObject;
|
||||
g_SqExports.GetULongValue = SqEx_GetULongValue;
|
||||
g_SqExports.PushULongObject = SqEx_PushULongObject;
|
||||
api->GetSLongValue = SqEx_GetSLongValue;
|
||||
api->PushSLongObject = SqEx_PushSLongObject;
|
||||
api->GetULongValue = SqEx_GetULongValue;
|
||||
api->PushULongObject = SqEx_PushULongObject;
|
||||
|
||||
//time utilities
|
||||
g_SqExports.GetCurrentSysTime = Chrono::GetCurrentSysTime;
|
||||
g_SqExports.GetEpochTimeMicro = Chrono::GetEpochTimeMicro;
|
||||
g_SqExports.GetEpochTimeMilli = Chrono::GetEpochTimeMilli;
|
||||
g_SqExports.ValidDate = SqEx_ValidDate;
|
||||
g_SqExports.IsLeapYear = SqEx_IsLeapYear;
|
||||
g_SqExports.DaysInYear = Chrono::DaysInYear;
|
||||
g_SqExports.DaysInMonth = Chrono::DaysInMonth;
|
||||
g_SqExports.DayOfYear = Chrono::DayOfYear;
|
||||
g_SqExports.DateRangeToSeconds = Chrono::DateRangeToSeconds;
|
||||
g_SqExports.GetTimestamp = SqEx_GetTimestamp;
|
||||
g_SqExports.PushTimestamp = SqEx_PushTimestamp;
|
||||
g_SqExports.GetDate = SqEx_GetDate;
|
||||
g_SqExports.PushDate = SqEx_PushDate;
|
||||
g_SqExports.GetTime = SqEx_GetTime;
|
||||
g_SqExports.PushTime = SqEx_PushTime;
|
||||
g_SqExports.GetDatetime = SqEx_GetDatetime;
|
||||
g_SqExports.PushDatetime = SqEx_PushDatetime;
|
||||
api->GetCurrentSysTime = Chrono::GetCurrentSysTime;
|
||||
api->GetEpochTimeMicro = Chrono::GetEpochTimeMicro;
|
||||
api->GetEpochTimeMilli = Chrono::GetEpochTimeMilli;
|
||||
api->ValidDate = SqEx_ValidDate;
|
||||
api->IsLeapYear = SqEx_IsLeapYear;
|
||||
api->DaysInYear = Chrono::DaysInYear;
|
||||
api->DaysInMonth = Chrono::DaysInMonth;
|
||||
api->DayOfYear = Chrono::DayOfYear;
|
||||
api->DateRangeToSeconds = Chrono::DateRangeToSeconds;
|
||||
api->GetTimestamp = SqEx_GetTimestamp;
|
||||
api->PushTimestamp = SqEx_PushTimestamp;
|
||||
api->GetDate = SqEx_GetDate;
|
||||
api->PushDate = SqEx_PushDate;
|
||||
api->GetTime = SqEx_GetTime;
|
||||
api->PushTime = SqEx_PushTime;
|
||||
api->GetDatetime = SqEx_GetDatetime;
|
||||
api->PushDatetime = SqEx_PushDatetime;
|
||||
|
||||
//stack utilities
|
||||
g_SqExports.PopStackInteger = PopStackInteger;
|
||||
g_SqExports.PopStackFloat = PopStackFloat;
|
||||
g_SqExports.PopStackSLong = PopStackSLong;
|
||||
g_SqExports.PopStackULong = PopStackULong;
|
||||
api->PopStackInteger = PopStackInteger;
|
||||
api->PopStackFloat = PopStackFloat;
|
||||
api->PopStackSLong = PopStackSLong;
|
||||
api->PopStackULong = PopStackULong;
|
||||
|
||||
//buffer utilities
|
||||
g_SqExports.PushBuffer = SqEx_PushBuffer;
|
||||
g_SqExports.PushBufferData = SqEx_PushBufferData;
|
||||
g_SqExports.GetBufferInfo = SqEx_GetBufferInfo;
|
||||
g_SqExports.GetBufferData = SqEx_GetBufferData;
|
||||
g_SqExports.GetBufferSize = SqEx_GetBufferSize;
|
||||
g_SqExports.GetBufferCursor = SqEx_GetBufferCursor;
|
||||
api->PushBuffer = SqEx_PushBuffer;
|
||||
api->PushBufferData = SqEx_PushBufferData;
|
||||
api->GetBufferInfo = SqEx_GetBufferInfo;
|
||||
api->GetBufferData = SqEx_GetBufferData;
|
||||
api->GetBufferSize = SqEx_GetBufferSize;
|
||||
api->GetBufferCursor = SqEx_GetBufferCursor;
|
||||
|
||||
// Export them to the server
|
||||
_Func->ExportFunctions(_Info->pluginId,
|
||||
const_cast< const void ** >(reinterpret_cast< void ** >(&sqexports)),
|
||||
sizeof(SQEXPORTS));
|
||||
return 1; // Successfully populated!
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static int32_t SqExport_PopulateSquirrelAPI(HSQLIBAPI api, size_t size)
|
||||
{
|
||||
if (!api)
|
||||
{
|
||||
return 0; // Nothing to populate!
|
||||
}
|
||||
else if (size != sizeof(SQLIBAPI))
|
||||
{
|
||||
return -1; // Incompatible API!
|
||||
}
|
||||
|
||||
//vm
|
||||
g_SqAPI.open = sq_open;
|
||||
g_SqAPI.newthread = sq_newthread;
|
||||
g_SqAPI.seterrorhandler = sq_seterrorhandler;
|
||||
g_SqAPI.close = sq_close;
|
||||
g_SqAPI.setforeignptr = sq_setforeignptr;
|
||||
g_SqAPI.getforeignptr = sq_getforeignptr;
|
||||
g_SqAPI.setsharedforeignptr = sq_setsharedforeignptr;
|
||||
g_SqAPI.getsharedforeignptr = sq_getsharedforeignptr;
|
||||
g_SqAPI.setvmreleasehook = sq_setvmreleasehook;
|
||||
g_SqAPI.getvmreleasehook = sq_getvmreleasehook;
|
||||
g_SqAPI.setsharedreleasehook = sq_setsharedreleasehook;
|
||||
g_SqAPI.getsharedreleasehook = sq_getsharedreleasehook;
|
||||
g_SqAPI.setprintfunc = sq_setprintfunc;
|
||||
g_SqAPI.getprintfunc = sq_getprintfunc;
|
||||
g_SqAPI.geterrorfunc = sq_geterrorfunc;
|
||||
g_SqAPI.suspendvm = sq_suspendvm;
|
||||
g_SqAPI.wakeupvm = sq_wakeupvm;
|
||||
g_SqAPI.getvmstate = sq_getvmstate;
|
||||
g_SqAPI.getversion = sq_getversion;
|
||||
api->open = sq_open;
|
||||
api->newthread = sq_newthread;
|
||||
api->seterrorhandler = sq_seterrorhandler;
|
||||
api->close = sq_close;
|
||||
api->setforeignptr = sq_setforeignptr;
|
||||
api->getforeignptr = sq_getforeignptr;
|
||||
api->setsharedforeignptr = sq_setsharedforeignptr;
|
||||
api->getsharedforeignptr = sq_getsharedforeignptr;
|
||||
api->setvmreleasehook = sq_setvmreleasehook;
|
||||
api->getvmreleasehook = sq_getvmreleasehook;
|
||||
api->setsharedreleasehook = sq_setsharedreleasehook;
|
||||
api->getsharedreleasehook = sq_getsharedreleasehook;
|
||||
api->setprintfunc = sq_setprintfunc;
|
||||
api->getprintfunc = sq_getprintfunc;
|
||||
api->geterrorfunc = sq_geterrorfunc;
|
||||
api->suspendvm = sq_suspendvm;
|
||||
api->wakeupvm = sq_wakeupvm;
|
||||
api->getvmstate = sq_getvmstate;
|
||||
api->getversion = sq_getversion;
|
||||
|
||||
//compiler
|
||||
g_SqAPI.compile = sq_compile;
|
||||
g_SqAPI.compilebuffer = sq_compilebuffer;
|
||||
g_SqAPI.enabledebuginfo = sq_enabledebuginfo;
|
||||
g_SqAPI.notifyallexceptions = sq_notifyallexceptions;
|
||||
g_SqAPI.setcompilererrorhandler = sq_setcompilererrorhandler;
|
||||
api->compile = sq_compile;
|
||||
api->compilebuffer = sq_compilebuffer;
|
||||
api->enabledebuginfo = sq_enabledebuginfo;
|
||||
api->notifyallexceptions = sq_notifyallexceptions;
|
||||
api->setcompilererrorhandler = sq_setcompilererrorhandler;
|
||||
|
||||
//stack operations
|
||||
g_SqAPI.push = sq_push;
|
||||
g_SqAPI.pop = sq_pop;
|
||||
g_SqAPI.poptop = sq_poptop;
|
||||
g_SqAPI.remove = sq_remove;
|
||||
g_SqAPI.gettop = sq_gettop;
|
||||
g_SqAPI.settop = sq_settop;
|
||||
g_SqAPI.reservestack = sq_reservestack;
|
||||
g_SqAPI.cmp = sq_cmp;
|
||||
g_SqAPI.move = sq_move;
|
||||
api->push = sq_push;
|
||||
api->pop = sq_pop;
|
||||
api->poptop = sq_poptop;
|
||||
api->remove = sq_remove;
|
||||
api->gettop = sq_gettop;
|
||||
api->settop = sq_settop;
|
||||
api->reservestack = sq_reservestack;
|
||||
api->cmp = sq_cmp;
|
||||
api->move = sq_move;
|
||||
|
||||
//object creation handling
|
||||
g_SqAPI.newuserdata = sq_newuserdata;
|
||||
g_SqAPI.newtable = sq_newtable;
|
||||
g_SqAPI.newtableex = sq_newtableex;
|
||||
g_SqAPI.newarray = sq_newarray;
|
||||
g_SqAPI.newclosure = sq_newclosure;
|
||||
g_SqAPI.setparamscheck = sq_setparamscheck;
|
||||
g_SqAPI.bindenv = sq_bindenv;
|
||||
g_SqAPI.setclosureroot = sq_setclosureroot;
|
||||
g_SqAPI.getclosureroot = sq_getclosureroot;
|
||||
g_SqAPI.pushstring = sq_pushstring;
|
||||
g_SqAPI.pushfloat = sq_pushfloat;
|
||||
g_SqAPI.pushinteger = sq_pushinteger;
|
||||
g_SqAPI.pushbool = sq_pushbool;
|
||||
g_SqAPI.pushuserpointer = sq_pushuserpointer;
|
||||
g_SqAPI.pushnull = sq_pushnull;
|
||||
g_SqAPI.pushthread = sq_pushthread;
|
||||
g_SqAPI.gettype = sq_gettype;
|
||||
g_SqAPI.typeof_ = sq_typeof;
|
||||
g_SqAPI.getsize = sq_getsize;
|
||||
g_SqAPI.gethash = sq_gethash;
|
||||
g_SqAPI.getbase = sq_getbase;
|
||||
g_SqAPI.instanceof = sq_instanceof;
|
||||
g_SqAPI.tostring = sq_tostring;
|
||||
g_SqAPI.tobool = sq_tobool;
|
||||
g_SqAPI.getstringandsize = sq_getstringandsize;
|
||||
g_SqAPI.getstring = sq_getstring;
|
||||
g_SqAPI.getinteger = sq_getinteger;
|
||||
g_SqAPI.getfloat = sq_getfloat;
|
||||
g_SqAPI.getbool = sq_getbool;
|
||||
g_SqAPI.getthread = sq_getthread;
|
||||
g_SqAPI.getuserpointer = sq_getuserpointer;
|
||||
g_SqAPI.getuserdata = sq_getuserdata;
|
||||
g_SqAPI.settypetag = sq_settypetag;
|
||||
g_SqAPI.gettypetag = sq_gettypetag;
|
||||
g_SqAPI.setreleasehook = sq_setreleasehook;
|
||||
g_SqAPI.getreleasehook = sq_getreleasehook;
|
||||
g_SqAPI.getscratchpad = sq_getscratchpad;
|
||||
g_SqAPI.getfunctioninfo = sq_getfunctioninfo;
|
||||
g_SqAPI.getclosureinfo = sq_getclosureinfo;
|
||||
g_SqAPI.getclosurename = sq_getclosurename;
|
||||
g_SqAPI.setnativeclosurename = sq_setnativeclosurename;
|
||||
g_SqAPI.setinstanceup = sq_setinstanceup;
|
||||
g_SqAPI.getinstanceup = sq_getinstanceup;
|
||||
g_SqAPI.setclassudsize = sq_setclassudsize;
|
||||
g_SqAPI.newclass = sq_newclass;
|
||||
g_SqAPI.createinstance = sq_createinstance;
|
||||
g_SqAPI.setattributes = sq_setattributes;
|
||||
g_SqAPI.getattributes = sq_getattributes;
|
||||
g_SqAPI.getclass = sq_getclass;
|
||||
g_SqAPI.weakref = sq_weakref;
|
||||
g_SqAPI.getdefaultdelegate = sq_getdefaultdelegate;
|
||||
g_SqAPI.getmemberhandle = sq_getmemberhandle;
|
||||
g_SqAPI.getbyhandle = sq_getbyhandle;
|
||||
g_SqAPI.setbyhandle = sq_setbyhandle;
|
||||
api->newuserdata = sq_newuserdata;
|
||||
api->newtable = sq_newtable;
|
||||
api->newtableex = sq_newtableex;
|
||||
api->newarray = sq_newarray;
|
||||
api->newclosure = sq_newclosure;
|
||||
api->setparamscheck = sq_setparamscheck;
|
||||
api->bindenv = sq_bindenv;
|
||||
api->setclosureroot = sq_setclosureroot;
|
||||
api->getclosureroot = sq_getclosureroot;
|
||||
api->pushstring = sq_pushstring;
|
||||
api->pushfloat = sq_pushfloat;
|
||||
api->pushinteger = sq_pushinteger;
|
||||
api->pushbool = sq_pushbool;
|
||||
api->pushuserpointer = sq_pushuserpointer;
|
||||
api->pushnull = sq_pushnull;
|
||||
api->pushthread = sq_pushthread;
|
||||
api->gettype = sq_gettype;
|
||||
api->typeof_ = sq_typeof;
|
||||
api->getsize = sq_getsize;
|
||||
api->gethash = sq_gethash;
|
||||
api->getbase = sq_getbase;
|
||||
api->instanceof = sq_instanceof;
|
||||
api->tostring = sq_tostring;
|
||||
api->tobool = sq_tobool;
|
||||
api->getstringandsize = sq_getstringandsize;
|
||||
api->getstring = sq_getstring;
|
||||
api->getinteger = sq_getinteger;
|
||||
api->getfloat = sq_getfloat;
|
||||
api->getbool = sq_getbool;
|
||||
api->getthread = sq_getthread;
|
||||
api->getuserpointer = sq_getuserpointer;
|
||||
api->getuserdata = sq_getuserdata;
|
||||
api->settypetag = sq_settypetag;
|
||||
api->gettypetag = sq_gettypetag;
|
||||
api->setreleasehook = sq_setreleasehook;
|
||||
api->getreleasehook = sq_getreleasehook;
|
||||
api->getscratchpad = sq_getscratchpad;
|
||||
api->getfunctioninfo = sq_getfunctioninfo;
|
||||
api->getclosureinfo = sq_getclosureinfo;
|
||||
api->getclosurename = sq_getclosurename;
|
||||
api->setnativeclosurename = sq_setnativeclosurename;
|
||||
api->setinstanceup = sq_setinstanceup;
|
||||
api->getinstanceup = sq_getinstanceup;
|
||||
api->setclassudsize = sq_setclassudsize;
|
||||
api->newclass = sq_newclass;
|
||||
api->createinstance = sq_createinstance;
|
||||
api->setattributes = sq_setattributes;
|
||||
api->getattributes = sq_getattributes;
|
||||
api->getclass = sq_getclass;
|
||||
api->weakref = sq_weakref;
|
||||
api->getdefaultdelegate = sq_getdefaultdelegate;
|
||||
api->getmemberhandle = sq_getmemberhandle;
|
||||
api->getbyhandle = sq_getbyhandle;
|
||||
api->setbyhandle = sq_setbyhandle;
|
||||
|
||||
//object manipulation
|
||||
g_SqAPI.pushroottable = sq_pushroottable;
|
||||
g_SqAPI.pushregistrytable = sq_pushregistrytable;
|
||||
g_SqAPI.pushconsttable = sq_pushconsttable;
|
||||
g_SqAPI.setroottable = sq_setroottable;
|
||||
g_SqAPI.setconsttable = sq_setconsttable;
|
||||
g_SqAPI.newslot = sq_newslot;
|
||||
g_SqAPI.deleteslot = sq_deleteslot;
|
||||
g_SqAPI.set = sq_set;
|
||||
g_SqAPI.get = sq_get;
|
||||
g_SqAPI.rawget = sq_rawget;
|
||||
g_SqAPI.rawset = sq_rawset;
|
||||
g_SqAPI.rawdeleteslot = sq_rawdeleteslot;
|
||||
g_SqAPI.newmember = sq_newmember;
|
||||
g_SqAPI.rawnewmember = sq_rawnewmember;
|
||||
g_SqAPI.arrayappend = sq_arrayappend;
|
||||
g_SqAPI.arraypop = sq_arraypop;
|
||||
g_SqAPI.arrayresize = sq_arrayresize;
|
||||
g_SqAPI.arrayreverse = sq_arrayreverse;
|
||||
g_SqAPI.arrayremove = sq_arrayremove;
|
||||
g_SqAPI.arrayinsert = sq_arrayinsert;
|
||||
g_SqAPI.setdelegate = sq_setdelegate;
|
||||
g_SqAPI.getdelegate = sq_getdelegate;
|
||||
g_SqAPI.clone = sq_clone;
|
||||
g_SqAPI.setfreevariable = sq_setfreevariable;
|
||||
g_SqAPI.next = sq_next;
|
||||
g_SqAPI.getweakrefval = sq_getweakrefval;
|
||||
g_SqAPI.clear = sq_clear;
|
||||
api->pushroottable = sq_pushroottable;
|
||||
api->pushregistrytable = sq_pushregistrytable;
|
||||
api->pushconsttable = sq_pushconsttable;
|
||||
api->setroottable = sq_setroottable;
|
||||
api->setconsttable = sq_setconsttable;
|
||||
api->newslot = sq_newslot;
|
||||
api->deleteslot = sq_deleteslot;
|
||||
api->set = sq_set;
|
||||
api->get = sq_get;
|
||||
api->rawget = sq_rawget;
|
||||
api->rawset = sq_rawset;
|
||||
api->rawdeleteslot = sq_rawdeleteslot;
|
||||
api->newmember = sq_newmember;
|
||||
api->rawnewmember = sq_rawnewmember;
|
||||
api->arrayappend = sq_arrayappend;
|
||||
api->arraypop = sq_arraypop;
|
||||
api->arrayresize = sq_arrayresize;
|
||||
api->arrayreverse = sq_arrayreverse;
|
||||
api->arrayremove = sq_arrayremove;
|
||||
api->arrayinsert = sq_arrayinsert;
|
||||
api->setdelegate = sq_setdelegate;
|
||||
api->getdelegate = sq_getdelegate;
|
||||
api->clone = sq_clone;
|
||||
api->setfreevariable = sq_setfreevariable;
|
||||
api->next = sq_next;
|
||||
api->getweakrefval = sq_getweakrefval;
|
||||
api->clear = sq_clear;
|
||||
|
||||
//calls
|
||||
g_SqAPI.call = sq_call;
|
||||
g_SqAPI.resume = sq_resume;
|
||||
g_SqAPI.getlocal = sq_getlocal;
|
||||
g_SqAPI.getcallee = sq_getcallee;
|
||||
g_SqAPI.getfreevariable = sq_getfreevariable;
|
||||
g_SqAPI.throwerror = sq_throwerror;
|
||||
g_SqAPI.throwobject = sq_throwobject;
|
||||
g_SqAPI.reseterror = sq_reseterror;
|
||||
g_SqAPI.getlasterror = sq_getlasterror;
|
||||
api->call = sq_call;
|
||||
api->resume = sq_resume;
|
||||
api->getlocal = sq_getlocal;
|
||||
api->getcallee = sq_getcallee;
|
||||
api->getfreevariable = sq_getfreevariable;
|
||||
api->throwerror = sq_throwerror;
|
||||
api->throwobject = sq_throwobject;
|
||||
api->reseterror = sq_reseterror;
|
||||
api->getlasterror = sq_getlasterror;
|
||||
|
||||
//raw object handling
|
||||
g_SqAPI.getstackobj = sq_getstackobj;
|
||||
g_SqAPI.pushobject = sq_pushobject;
|
||||
g_SqAPI.addref = sq_addref;
|
||||
g_SqAPI.release = sq_release;
|
||||
g_SqAPI.getrefcount = sq_getrefcount;
|
||||
g_SqAPI.resetobject = sq_resetobject;
|
||||
g_SqAPI.objtostring = sq_objtostring;
|
||||
g_SqAPI.objtobool = sq_objtobool;
|
||||
g_SqAPI.objtointeger = sq_objtointeger;
|
||||
g_SqAPI.objtofloat = sq_objtofloat;
|
||||
g_SqAPI.objtouserpointer = sq_objtouserpointer;
|
||||
g_SqAPI.getobjtypetag = sq_getobjtypetag;
|
||||
g_SqAPI.getvmrefcount = sq_getvmrefcount;
|
||||
api->getstackobj = sq_getstackobj;
|
||||
api->pushobject = sq_pushobject;
|
||||
api->addref = sq_addref;
|
||||
api->release = sq_release;
|
||||
api->getrefcount = sq_getrefcount;
|
||||
api->resetobject = sq_resetobject;
|
||||
api->objtostring = sq_objtostring;
|
||||
api->objtobool = sq_objtobool;
|
||||
api->objtointeger = sq_objtointeger;
|
||||
api->objtofloat = sq_objtofloat;
|
||||
api->objtouserpointer = sq_objtouserpointer;
|
||||
api->getobjtypetag = sq_getobjtypetag;
|
||||
api->getvmrefcount = sq_getvmrefcount;
|
||||
|
||||
//GC
|
||||
g_SqAPI.collectgarbage = sq_collectgarbage;
|
||||
g_SqAPI.resurrectunreachable = sq_resurrectunreachable;
|
||||
api->collectgarbage = sq_collectgarbage;
|
||||
api->resurrectunreachable = sq_resurrectunreachable;
|
||||
|
||||
//serialization
|
||||
g_SqAPI.writeclosure = sq_writeclosure;
|
||||
g_SqAPI.readclosure = sq_readclosure;
|
||||
api->writeclosure = sq_writeclosure;
|
||||
api->readclosure = sq_readclosure;
|
||||
|
||||
//mem allocation
|
||||
g_SqAPI.malloc = sq_malloc;
|
||||
g_SqAPI.realloc = sq_realloc;
|
||||
g_SqAPI.free = sq_free;
|
||||
api->malloc = sq_malloc;
|
||||
api->realloc = sq_realloc;
|
||||
api->free = sq_free;
|
||||
|
||||
//debug
|
||||
g_SqAPI.stackinfos = sq_stackinfos;
|
||||
g_SqAPI.setdebughook = sq_setdebughook;
|
||||
g_SqAPI.setnativedebughook = sq_setnativedebughook;
|
||||
api->stackinfos = sq_stackinfos;
|
||||
api->setdebughook = sq_setdebughook;
|
||||
api->setnativedebughook = sq_setnativedebughook;
|
||||
|
||||
//compiler helpers
|
||||
g_SqAPI.loadfile = sqstd_loadfile;
|
||||
g_SqAPI.dofile = sqstd_dofile;
|
||||
g_SqAPI.writeclosuretofile = sqstd_writeclosuretofile;
|
||||
api->loadfile = sqstd_loadfile;
|
||||
api->dofile = sqstd_dofile;
|
||||
api->writeclosuretofile = sqstd_writeclosuretofile;
|
||||
|
||||
//blob
|
||||
g_SqAPI.createblob = sqstd_createblob;
|
||||
g_SqAPI.getblob = sqstd_getblob;
|
||||
g_SqAPI.getblobsize = sqstd_getblobsize;
|
||||
api->createblob = sqstd_createblob;
|
||||
api->getblob = sqstd_getblob;
|
||||
api->getblobsize = sqstd_getblobsize;
|
||||
|
||||
//string
|
||||
g_SqAPI.format = sqstd_format;
|
||||
api->format = sqstd_format;
|
||||
|
||||
return 1; // Successfully populated!
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const SQMODEXPORTS g_SqModExports{
|
||||
sizeof(SQMODEXPORTS),
|
||||
SqExport_PopulateModuleAPI,
|
||||
SqExport_PopulateSquirrelAPI
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void InitExports()
|
||||
{
|
||||
// The server needs a pointer to a pointer, and a persistent one
|
||||
static const SQMODEXPORTS * sqmodexports = &g_SqModExports;
|
||||
|
||||
// Tell the server about the pointer to the exports structure
|
||||
_Func->ExportFunctions(_Info->pluginId, reinterpret_cast< const void ** >(&sqmodexports),
|
||||
sizeof(HSQMODEXPORTS));
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -257,7 +257,6 @@ static void OnPlayerDisconnect(int32_t player_id, vcmpDisconnectReason reason)
|
||||
// Attempt to forward the event
|
||||
try
|
||||
{
|
||||
printf("Disconnecting... %d\n", player_id);
|
||||
Core::Get().DisconnectPlayer(player_id, reason, NullObject());
|
||||
}
|
||||
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerDisconnect)
|
||||
|
Loading…
Reference in New Issue
Block a user