From 698d42653792cc74e24ff73d55c1946cf856b147 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Sat, 9 Jan 2016 19:53:32 +0000 Subject: MirLua: writing blobs to db git-svn-id: http://svn.miranda-ng.org/main/trunk@16073 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/m_database.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'plugins/MirLua') diff --git a/plugins/MirLua/src/m_database.cpp b/plugins/MirLua/src/m_database.cpp index 4feab11e57..2c0f89a695 100644 --- a/plugins/MirLua/src/m_database.cpp +++ b/plugins/MirLua/src/m_database.cpp @@ -293,6 +293,27 @@ static int lua_Settings(lua_State *L) return 1; } +static size_t luaM_table_to_bytearray(lua_State *L, int index, BYTE **res) +{ + size_t result = 0; + lua_pushvalue(L, index); + lua_pushnil(L); + + while (lua_next(L, -2)) + { + result++; + if (*res == nullptr) *res = (BYTE*)mir_alloc(1); + else *res = (BYTE*)mir_realloc(*res, result); + + lua_pushvalue(L, -2); + char val = lua_tonumber(L, -2); + (*res)[result - 1] = val; + lua_pop(L, 2); + } + lua_pop(L, 1); + return result; +} + static int lua_WriteSetting(lua_State *L) { MCONTACT hContact = lua_tointeger(L, 1); @@ -316,7 +337,10 @@ static int lua_WriteSetting(lua_State *L) dbv.type = DBVT_UTF8; break; case LUA_TTABLE: - //this is blob, should be converted to BYTE* + { + dbv.type = DBVT_BLOB; + dbv.cpbVal = luaM_table_to_bytearray(L, 4, &(dbv.pbVal)); + } break; default: lua_pushinteger(L, 1); -- cgit v1.2.3