diff options
author | aunsane <aunsane@gmail.com> | 2017-09-12 22:02:30 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2017-09-12 22:03:37 +0300 |
commit | 6f99f13cf590c323fd5bd5b4d6855e59f582fb0e (patch) | |
tree | 4b9a66758433be8273c7c20e06ab305901b4fdfb /plugins/MirLua/src/m_protocols.cpp | |
parent | 6611ef6791a897d23cb79ab7b56eb48d49452b80 (diff) |
MirLua: massive refactoring
- m_msg_buttonbar moved to m_srrm
- version bump
Diffstat (limited to 'plugins/MirLua/src/m_protocols.cpp')
-rw-r--r-- | plugins/MirLua/src/m_protocols.cpp | 124 |
1 files changed, 51 insertions, 73 deletions
diff --git a/plugins/MirLua/src/m_protocols.cpp b/plugins/MirLua/src/m_protocols.cpp index f4b246a0cf..979388eed6 100644 --- a/plugins/MirLua/src/m_protocols.cpp +++ b/plugins/MirLua/src/m_protocols.cpp @@ -4,26 +4,26 @@ HANDLE hRecvMessage = NULL; static int lua_GetProtocol(lua_State *L)
{
- const char *name = NULL;
+ const char *szProto = NULL;
switch (lua_type(L, 1))
{
case LUA_TNUMBER:
{
- const char *proto = GetContactProto(lua_tonumber(L, 1));
- PROTOACCOUNT *pa = Proto_GetAccount(proto);
+ const char *szModule = GetContactProto(lua_tonumber(L, 1));
+ PROTOACCOUNT *pa = Proto_GetAccount(szModule);
if (pa)
- name = pa->szProtoName;
- }
+ szProto = pa->szProtoName;
break;
+ }
case LUA_TSTRING:
- name = lua_tostring(L, 1);
+ szProto = lua_tostring(L, 1);
break;
default:
luaL_argerror(L, 1, luaL_typename(L, 1));
}
- PROTOCOLDESCRIPTOR *pd = Proto_IsProtocolLoaded(name);
+ PROTOCOLDESCRIPTOR *pd = Proto_IsProtocolLoaded(szProto);
if (pd)
MT<PROTOCOLDESCRIPTOR>::Set(L, pd);
else
@@ -64,38 +64,6 @@ static int lua_Protocols(lua_State *L) return 1;
}
-static int lua_CallService(lua_State *L)
-{
- const char *szProto = NULL;
-
- switch (lua_type(L, 1))
- {
- case LUA_TNUMBER:
- szProto = GetContactProto(lua_tonumber(L, 1));
- break;
- case LUA_TSTRING:
- szProto = lua_tostring(L, 1);
- break;
- case LUA_TUSERDATA:
- luaL_checkudata(L, 1, "PROTOCOLDESCRIPTOR");
- lua_getfield(L, 1, "Name");
- szProto = lua_tostring(L, -1);
- lua_pop(L, 1);
- break;
- default:
- luaL_argerror(L, 1, luaL_typename(L, 1));
- }
-
- const char *service = luaL_checkstring(L, 2);
- WPARAM wParam = (WPARAM)luaM_tomparam(L, 3);
- LPARAM lParam = (LPARAM)luaM_tomparam(L, 4);
-
- INT_PTR res = CallProtoService(szProto, service, wParam, lParam);
- lua_pushinteger(L, res);
-
- return 1;
-}
-
static int lua_ChainSend(lua_State *L)
{
MCONTACT hContact = luaL_checknumber(L, 1);
@@ -184,11 +152,11 @@ static int lua_Accounts(lua_State *L) szProto = lua_tostring(L, 1);
break;
case LUA_TUSERDATA:
- luaL_checkudata(L, 1, "PROTOCOLDESCRIPTOR");
- lua_getfield(L, 1, "Name");
- szProto = lua_tostring(L, -1);
- lua_pop(L, 1);
+ {
+ PROTOCOLDESCRIPTOR **pd = (PROTOCOLDESCRIPTOR**)luaL_checkudata(L, 1, MT_PROTOCOLDESCRIPTOR);
+ szProto = (*pd)->szName;
break;
+ }
default:
luaL_argerror(L, 1, luaL_typename(L, 1));
}
@@ -196,7 +164,6 @@ static int lua_Accounts(lua_State *L) int count;
PROTOACCOUNT **accounts;
Proto_EnumAccounts(&count, &accounts);
-
lua_pushinteger(L, 0);
lua_pushinteger(L, count);
@@ -207,6 +174,38 @@ static int lua_Accounts(lua_State *L) return 1;
}
+static int lua_CallService(lua_State *L)
+{
+ const char *szModule = NULL;
+
+ switch (lua_type(L, 1))
+ {
+ case LUA_TNUMBER:
+ szModule = GetContactProto(lua_tonumber(L, 1));
+ break;
+ case LUA_TSTRING:
+ szModule = lua_tostring(L, 1);
+ break;
+ case LUA_TUSERDATA:
+ {
+ PROTOACCOUNT **pa = (PROTOACCOUNT**)luaL_checkudata(L, 1, MT_PROTOACCOUNT);
+ szModule = (*pa)->szModuleName;
+ break;
+ }
+ default:
+ luaL_argerror(L, 1, luaL_typename(L, 1));
+ }
+
+ const char *service = luaL_checkstring(L, 2);
+ WPARAM wParam = (WPARAM)luaM_tomparam(L, 3);
+ LPARAM lParam = (LPARAM)luaM_tomparam(L, 4);
+
+ INT_PTR res = CallProtoService(szModule, service, wParam, lParam);
+ lua_pushinteger(L, res);
+
+ return 1;
+}
+
/***********************************************/
INT_PTR FilterRecvMessage(WPARAM wParam, LPARAM lParam)
@@ -223,59 +222,38 @@ static luaL_Reg protocolsApi[] = {
{ "GetProtocol", lua_GetProtocol },
{ "Protocols", lua_Protocols },
- { "CallService", lua_CallService },
+
{ "CallSendChain", lua_ChainSend },
{ "CallReceiveChain", lua_ChainRecv },
{ "GetAccount", lua_GetAccount },
{ "Accounts", lua_Accounts },
+ { "CallService", lua_CallService },
+
{ NULL, NULL }
};
/***********************************************/
-#define MT_PROTOCOLDESCRIPTOR "PROTOCOLDESCRIPTOR"
-
-template <>
-int MT<PROTOCOLDESCRIPTOR>::Index(lua_State *L, PROTOCOLDESCRIPTOR *proto)
-{
- const char *key = luaL_checkstring(L, 2);
-
- if (mir_strcmpi(key, "CallService") == 0)
- {
- lua_pushstring(L, proto->szName);
- lua_pushcfunction(L, lua_CallService);
- }
- else if (mir_strcmpi(key, "Accounts") == 0)
- {
- lua_pushstring(L, proto->szName);
- lua_pushcfunction(L, lua_Accounts);
- }
- else
- lua_pushnil(L);
-
- return 1;
-}
-
-/***********************************************/
-
LUAMOD_API int luaopen_m_protocols(lua_State *L)
{
luaL_newlib(L, protocolsApi);
MT<PROTOCOLDESCRIPTOR>(L, MT_PROTOCOLDESCRIPTOR)
.Field(&PROTOCOLDESCRIPTOR::szName, "Name", LUA_TSTRINGA)
- .Field(&PROTOCOLDESCRIPTOR::type, "Type", LUA_TINTEGER);
+ .Field(&PROTOCOLDESCRIPTOR::type, "Type", LUA_TINTEGER)
+ .Field(lua_Accounts, "Accounts");
- MT<PROTOACCOUNT>(L, "PROTOACCOUNT")
+ MT<PROTOACCOUNT>(L, MT_PROTOACCOUNT)
.Field(&PROTOACCOUNT::szModuleName, "ModuleName", LUA_TSTRINGA)
.Field(&PROTOACCOUNT::tszAccountName, "AccountName", LUA_TSTRINGW)
.Field(&PROTOACCOUNT::szProtoName, "ProtoName", LUA_TSTRINGA)
.Field(&PROTOACCOUNT::bIsEnabled, "IsEnabled", LUA_TBOOLEAN)
.Field(&PROTOACCOUNT::bIsVisible, "IsVisible", LUA_TBOOLEAN)
.Field(&PROTOACCOUNT::bIsVirtual, "IsVirtual", LUA_TBOOLEAN)
- .Field(&PROTOACCOUNT::bOldProto, "IsOldProto", LUA_TBOOLEAN);
+ .Field(&PROTOACCOUNT::bOldProto, "IsOldProto", LUA_TBOOLEAN)
+ .Field(lua_CallService, "CallService");
MT<ACKDATA>(L, "ACKDATA")
.Field(&ACKDATA::szModule, "Module", LUA_TSTRINGA)
|