summaryrefslogtreecommitdiff
path: root/plugins/MirLua
diff options
context:
space:
mode:
authoraunsane <aunsane@gmail.com>2017-09-02 17:14:46 +0300
committeraunsane <aunsane@gmail.com>2017-09-02 17:28:15 +0300
commit68a501d70e6006464aae627326eda297ebb728eb (patch)
treea6eac3a46db867f43175f6e01ac16aa3c5960bc0 /plugins/MirLua
parentd8b2d58e284e2d77354ab99913901b31ee5d2eeb (diff)
MirLua: m_protocols:
- added ability to iterate accounts by protocol name - PROTOCOLDESCRIPTOR is now a valid parameter for CallService and Accounts methods - CallService and Accounts added to PROTOCOLDESCRIPTOR metatable methods
Diffstat (limited to 'plugins/MirLua')
-rw-r--r--plugins/MirLua/src/m_genmenu.cpp45
-rw-r--r--plugins/MirLua/src/m_protocols.cpp71
-rw-r--r--plugins/MirLua/src/mlua_metatable.h1
-rw-r--r--plugins/MirLua/src/mlua_utils.cpp4
4 files changed, 67 insertions, 54 deletions
diff --git a/plugins/MirLua/src/m_genmenu.cpp b/plugins/MirLua/src/m_genmenu.cpp
index 2359549fb5..b4d42521c6 100644
--- a/plugins/MirLua/src/m_genmenu.cpp
+++ b/plugins/MirLua/src/m_genmenu.cpp
@@ -38,42 +38,6 @@ void MakeMenuItem(lua_State *L, CMenuItem &mi)
lua_pop(L, 1);
}
-/*static int genmenu_CreateRoot(lua_State *L)
-{
- ObsoleteMethod(L, "use m_clist module instead");
-
- int hMenuObject = luaL_checkinteger(L, 1);
- const char *name = luaL_checkstring(L, 2);
- int position = lua_tointeger(L, 3);
- HANDLE hIcon = (HANDLE)lua_touserdata(L, 4);
-
- HGENMENU res = Menu_CreateRoot(hMenuObject, ptrW(Utf8DecodeW(name)), position, hIcon);
- lua_pushlightuserdata(L, res);
-
- return 1;
-}
-
-static int genmenu_AddMenuItem(lua_State *L)
-{
- ObsoleteMethod(L, "use m_clist module instead");
-
- int hMenuObject = luaL_checkinteger(L, 1);
-
- if (lua_type(L, 2) != LUA_TTABLE)
- {
- lua_pushlightuserdata(L, 0);
- return 1;
- }
-
- CMenuItem mi;
- MakeMenuItem(L, mi);
-
- HGENMENU res = Menu_AddItem(hMenuObject, &mi, NULL);
- lua_pushlightuserdata(L, res);
-
- return 1;
-}*/
-
static int genmenu_ModifyMenuItem(lua_State *L)
{
luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
@@ -150,8 +114,6 @@ static int genmenu_RemoveMenuItem(lua_State *L)
static luaL_Reg genmenuApi[] =
{
- //{ "CreateRoot", genmenu_CreateRoot },
- //{ "AddMenuItem", genmenu_AddMenuItem },
{ "ModifyMenuItem", genmenu_ModifyMenuItem },
{ "ConfigureMenuItem", genmenu_ConfigureMenuItem },
{ "ShowMenuItem", genmenu_ShowMenuItem },
@@ -159,19 +121,12 @@ static luaL_Reg genmenuApi[] =
{ "CheckMenuItem", genmenu_CheckMenuItem },
{ "RemoveMenuItem", genmenu_RemoveMenuItem },
- //{ "MO_MAIN", NULL },
- //{ "MO_CONTACT", NULL },
-
{ NULL, NULL }
};
LUAMOD_API int luaopen_m_genmenu(lua_State *L)
{
luaL_newlib(L, genmenuApi);
- /*lua_pushinteger(L, MO_MAIN);
- lua_setfield(L, -2, "MO_MAIN");
- lua_pushinteger(L, MO_CONTACT);
- lua_setfield(L, -2, "MO_CONTACT");*/
return 1;
}
diff --git a/plugins/MirLua/src/m_protocols.cpp b/plugins/MirLua/src/m_protocols.cpp
index 889be34a42..f4b246a0cf 100644
--- a/plugins/MirLua/src/m_protocols.cpp
+++ b/plugins/MirLua/src/m_protocols.cpp
@@ -66,15 +66,21 @@ static int lua_Protocols(lua_State *L)
static int lua_CallService(lua_State *L)
{
- const char *module = NULL;
+ const char *szProto = NULL;
switch (lua_type(L, 1))
{
case LUA_TNUMBER:
- module = GetContactProto(lua_tonumber(L, 1));
- break;
+ szProto = GetContactProto(lua_tonumber(L, 1));
+ break;
case LUA_TSTRING:
- module = lua_tostring(L, 1);
+ 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));
@@ -84,7 +90,7 @@ static int lua_CallService(lua_State *L)
WPARAM wParam = (WPARAM)luaM_tomparam(L, 3);
LPARAM lParam = (LPARAM)luaM_tomparam(L, 4);
- INT_PTR res = CallProtoService(module, service, wParam, lParam);
+ INT_PTR res = CallProtoService(szProto, service, wParam, lParam);
lua_pushinteger(L, res);
return 1;
@@ -148,6 +154,11 @@ static int lua_AccountIterator(lua_State *L)
int i = lua_tointeger(L, lua_upvalueindex(1));
int count = lua_tointeger(L, lua_upvalueindex(2));
PROTOACCOUNT **accounts = (PROTOACCOUNT**)lua_touserdata(L, lua_upvalueindex(3));
+ const char *szProto = lua_tostring(L, lua_upvalueindex(4));
+
+ if (szProto)
+ while (i < count && mir_strcmp(szProto, accounts[i]->szProtoName))
+ i++;
if (i < count)
{
@@ -163,14 +174,35 @@ static int lua_AccountIterator(lua_State *L)
static int lua_Accounts(lua_State *L)
{
+ const char *szProto = NULL;
+
+ switch (lua_type(L, 1))
+ {
+ case LUA_TNONE:
+ 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));
+ }
+
int count;
PROTOACCOUNT **accounts;
Proto_EnumAccounts(&count, &accounts);
+
lua_pushinteger(L, 0);
lua_pushinteger(L, count);
lua_pushlightuserdata(L, accounts);
- lua_pushcclosure(L, lua_AccountIterator, 3);
+ lua_pushstring(L, szProto);
+ lua_pushcclosure(L, lua_AccountIterator, 4);
return 1;
}
@@ -203,11 +235,36 @@ static luaL_Reg protocolsApi[] =
/***********************************************/
+#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, "PROTOCOLDESCRIPTOR")
+ MT<PROTOCOLDESCRIPTOR>(L, MT_PROTOCOLDESCRIPTOR)
.Field(&PROTOCOLDESCRIPTOR::szName, "Name", LUA_TSTRINGA)
.Field(&PROTOCOLDESCRIPTOR::type, "Type", LUA_TINTEGER);
diff --git a/plugins/MirLua/src/mlua_metatable.h b/plugins/MirLua/src/mlua_metatable.h
index 103c8b95d1..b918971077 100644
--- a/plugins/MirLua/src/mlua_metatable.h
+++ b/plugins/MirLua/src/mlua_metatable.h
@@ -169,6 +169,7 @@ private:
return 1;
}
+
static int lua__gc(lua_State *L)
{
T **obj = (T**)luaL_checkudata(L, 1, MT::name);
diff --git a/plugins/MirLua/src/mlua_utils.cpp b/plugins/MirLua/src/mlua_utils.cpp
index 5c84fb5c74..f21bd8fcbf 100644
--- a/plugins/MirLua/src/mlua_utils.cpp
+++ b/plugins/MirLua/src/mlua_utils.cpp
@@ -92,10 +92,10 @@ int luaM_print(lua_State *L)
data.AppendFormat("%s(0x%p)", luaL_typename(L, i), lua_topointer(L, i));
break;
}
- data += '\t';
+ data.Append(", ");
}
if (data.GetLength() >= 1)
- data.Delete(data.GetLength() - 1, 1);
+ data.Delete(data.GetLength() - 2, 2);
Log(data.GetBuffer());