From 2b16df81fe835d441e4dde275c3894a1fcdc66d3 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Wed, 15 Jun 2016 07:54:27 +0000 Subject: MirLua: AddEvent support string as blob git-svn-id: http://svn.miranda-ng.org/main/trunk@16974 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/m_database.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/MirLua/src/m_database.cpp b/plugins/MirLua/src/m_database.cpp index a4ac7f1de6..588e27af82 100644 --- a/plugins/MirLua/src/m_database.cpp +++ b/plugins/MirLua/src/m_database.cpp @@ -254,8 +254,10 @@ void MakeDbEvent(lua_State *L, DBEVENTINFO &dbei) lua_pop(L, 1); lua_getfield(L, -1, "Blob"); - if (lua_istable(L, -1)) + + switch (lua_type(L, -1)) { + case LUA_TTABLE: dbei.cbBlob = lua_rawlen(L, 4); dbei.pBlob = (BYTE*)mir_calloc(dbei.cbBlob); for (DWORD i = 0; i < dbei.cbBlob; i++) @@ -264,6 +266,14 @@ void MakeDbEvent(lua_State *L, DBEVENTINFO &dbei) dbei.pBlob[i] = lua_tointeger(L, -1); lua_pop(L, 1); } + break; + case LUA_TSTRING: + size_t nLen; + const char *str = lua_tolstring(L, -1, &nLen); + dbei.cbBlob = nLen; + dbei.pBlob = (BYTE*)mir_alloc(nLen); + memcpy(dbei.pBlob, str, nLen); + break; } lua_pop(L, 1); } @@ -272,7 +282,7 @@ static int db_AddEvent(lua_State *L) { MCONTACT hContact = luaL_checkinteger(L, 1); - DBEVENTINFO dbei; + DBEVENTINFO dbei = {}; MakeDbEvent(L, dbei); MEVENT hDbEvent = db_event_add(hContact, &dbei); -- cgit v1.2.3