summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/m_database.cpp
diff options
context:
space:
mode:
authorMikalaiR <nikolay.romanovich@narod.ru>2016-01-09 19:53:32 +0000
committerMikalaiR <nikolay.romanovich@narod.ru>2016-01-09 19:53:32 +0000
commit698d42653792cc74e24ff73d55c1946cf856b147 (patch)
treea019520eefd4f41e14b0c44f7720d8fec650d9b3 /plugins/MirLua/src/m_database.cpp
parent3712107a333f03a415c38991cd078167e34d2c59 (diff)
MirLua: writing blobs to db
git-svn-id: http://svn.miranda-ng.org/main/trunk@16073 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/src/m_database.cpp')
-rw-r--r--plugins/MirLua/src/m_database.cpp26
1 files changed, 25 insertions, 1 deletions
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);