summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikalaiR <nikolay.romanovich@narod.ru>2016-06-12 18:05:56 +0000
committerMikalaiR <nikolay.romanovich@narod.ru>2016-06-12 18:05:56 +0000
commit38e5290b4e172716f04056d1faf557e2d58d05b1 (patch)
tree791dfec229f62fe79aeedc4d1fd3c424d9da1e05
parentd92aff2ff6b35191b2c32f7f5aaaa62acf37931b (diff)
MirLua: fix ContactIterator, fix tonumber, added AddEvent function
git-svn-id: http://svn.miranda-ng.org/main/trunk@16957 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--plugins/MirLua/src/m_database.cpp46
-rw-r--r--plugins/MirLua/src/mlua_utils.cpp8
2 files changed, 52 insertions, 2 deletions
diff --git a/plugins/MirLua/src/m_database.cpp b/plugins/MirLua/src/m_database.cpp
index 081ba1dd95..4c7ed97a1e 100644
--- a/plugins/MirLua/src/m_database.cpp
+++ b/plugins/MirLua/src/m_database.cpp
@@ -34,7 +34,7 @@ static int db_ContactIterator(lua_State *L)
{
lua_pushinteger(L, hContact);
lua_pushvalue(L, -1);
- lua_replace(L, lua_upvalueindex(2));
+ lua_replace(L, lua_upvalueindex(1));
}
else
lua_pushnil(L);
@@ -233,6 +233,49 @@ static int db_EventsFromEnd(lua_State *L)
return 1;
}
+void MakeDbEvent(lua_State *L, DBEVENTINFO &dbei)
+{
+ dbei.cbSize = sizeof(dbei);
+
+
+ lua_getfield(L, -1, "Module");
+ dbei.szModule = mir_strdup(lua_tostring(L, -1));
+ lua_pop(L, 1);
+
+ lua_getfield(L, -1, "Type");
+ dbei.eventType = lua_tointeger(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, -1, "Timestamp");
+ dbei.timestamp = lua_tonumber(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, -1, "Flags");
+ dbei.flags = lua_tointeger(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, -1, "Length");
+ dbei.cbBlob = lua_tonumber(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, -1, "Blob");
+
+ dbei.pBlob = ((BLOB*)lua_touserdata(L, -1))->pBlobData;
+
+ lua_pop(L, 1);
+}
+
+static int db_AddEvent(lua_State *L)
+{
+ MCONTACT hContact = luaL_checkinteger(L, 1);
+
+ DBEVENTINFO dbei;
+ MakeDbEvent(L, dbei);
+ lua_pushnumber(L, db_event_add(hContact, &dbei));
+ return 1;
+}
+
+
/***********************************************/
static int db_GetSetting(lua_State *L)
@@ -464,6 +507,7 @@ static luaL_Reg databaseApi[] =
{ "GetLastEvent", db_GetLastEvent },
{ "Events", db_Events },
{ "EventsFromEnd", db_EventsFromEnd },
+ { "AddEvent", db_AddEvent },
{ "WriteSetting", db_WriteSetting },
{ "SetSetting", db_WriteSetting },
diff --git a/plugins/MirLua/src/mlua_utils.cpp b/plugins/MirLua/src/mlua_utils.cpp
index 26bcf22657..d3002cb04c 100644
--- a/plugins/MirLua/src/mlua_utils.cpp
+++ b/plugins/MirLua/src/mlua_utils.cpp
@@ -167,13 +167,19 @@ int luaM_tonumber(lua_State *L)
lua_Integer value = (lua_Integer)lua_touserdata(L, 1);
lua_pushinteger(L, value);
}
- else
+ else if (lua_gettop(L) == 2)
{
lua_getglobal(L, "_tonumber");
lua_pushvalue(L, 1);
lua_pushvalue(L, 2);
luaM_pcall(L, 2, 1);
}
+ else
+ {
+ lua_getglobal(L, "_tonumber");
+ lua_pushvalue(L, 1);
+ luaM_pcall(L, 1, 1);
+ }
return 1;
}