summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/m_protocols.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-07-20 20:35:35 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-07-20 20:35:35 +0000
commit7d46e610c0c93d68cb28e51f42691b3a404f2f7e (patch)
tree54549257352c650dfdea3dcaec5e67abafff257b /plugins/MirLua/src/m_protocols.cpp
parentab51bf5672d02978906a59ddf070ccc3f80921b8 (diff)
MirLua:
- added iterators in m_database and m_protocols - added more short aliases for functions in m_database - added some examples in m_database - version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@14590 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/src/m_protocols.cpp')
-rw-r--r--plugins/MirLua/src/m_protocols.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/plugins/MirLua/src/m_protocols.cpp b/plugins/MirLua/src/m_protocols.cpp
index 9e121b8a66..c095f44470 100644
--- a/plugins/MirLua/src/m_protocols.cpp
+++ b/plugins/MirLua/src/m_protocols.cpp
@@ -25,6 +25,38 @@ static int lua_GetProto(lua_State *L)
return 1;
}
+static int lua_ProtoIterator(lua_State *L)
+{
+ int i = lua_tointeger(L, lua_upvalueindex(1));
+ int count = lua_tointeger(L, lua_upvalueindex(2));
+ PROTOCOLDESCRIPTOR** protos = (PROTOCOLDESCRIPTOR**)lua_touserdata(L, lua_upvalueindex(3));
+
+ if (i < count)
+ {
+ lua_pushinteger(L, (i + 1));
+ lua_replace(L, lua_upvalueindex(1));
+ MapToTable(L, protos[i]);
+ }
+ else
+ lua_pushnil(L);
+
+ return 1;
+}
+
+static int lua_AllProtos(lua_State *L)
+{
+ int count;
+ PROTOCOLDESCRIPTOR** protos;
+ Proto_EnumProtocols(&count, &protos);
+
+ lua_pushinteger(L, 0);
+ lua_pushinteger(L, count);
+ lua_pushlightuserdata(L, protos);
+ lua_pushcclosure(L, lua_ProtoIterator, 3);
+
+ return 1;
+}
+
static int lua_EnumProtos(lua_State *L)
{
if (!lua_isfunction(L, 1))
@@ -94,6 +126,38 @@ static int lua_GetAccount(lua_State *L)
return 1;
}
+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));
+
+ if (i < count)
+ {
+ lua_pushinteger(L, (i + 1));
+ lua_replace(L, lua_upvalueindex(1));
+ MapToTable(L, accounts[i]);
+ }
+ else
+ lua_pushnil(L);
+
+ return 1;
+}
+
+static int lua_AllAccounts(lua_State *L)
+{
+ 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);
+
+ return 1;
+}
+
static int lua_EnumAccounts(lua_State *L)
{
if (!lua_isfunction(L, 1))
@@ -126,9 +190,11 @@ static int lua_EnumAccounts(lua_State *L)
static luaL_Reg protocolsApi[] =
{
{ "GetProto", lua_GetProto },
+ { "AllProtos", lua_AllProtos },
{ "EnumProtos", lua_EnumProtos },
{ "GetAccount", lua_GetAccount },
+ { "AllAccounts", lua_AllAccounts },
{ "EnumAccounts", lua_EnumAccounts },
{ NULL, NULL }