From 38e5290b4e172716f04056d1faf557e2d58d05b1 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Sun, 12 Jun 2016 18:05:56 +0000 Subject: MirLua: fix ContactIterator, fix tonumber, added AddEvent function git-svn-id: http://svn.miranda-ng.org/main/trunk@16957 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/m_database.cpp | 46 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'plugins/MirLua/src/m_database.cpp') 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 }, -- cgit v1.2.3