diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2016-01-14 20:53:02 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2016-01-14 20:53:02 +0000 |
commit | 069eaba45e1f12ba72939ae735e4fa493df5b02b (patch) | |
tree | 216f81af50c33194c50c4f333577dec1c62fdda4 /plugins/MirLua/src | |
parent | 55ca0ecfa502004ebb473cb5997d9985c0547d33 (diff) |
MirLua: extended WriteSetting in m_database
git-svn-id: http://svn.miranda-ng.org/main/trunk@16091 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/src')
-rw-r--r-- | plugins/MirLua/src/m_database.cpp | 70 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_script.cpp | 2 |
2 files changed, 46 insertions, 26 deletions
diff --git a/plugins/MirLua/src/m_database.cpp b/plugins/MirLua/src/m_database.cpp index 2c0f89a695..57846c99de 100644 --- a/plugins/MirLua/src/m_database.cpp +++ b/plugins/MirLua/src/m_database.cpp @@ -321,29 +321,56 @@ static int lua_WriteSetting(lua_State *L) LPCSTR szSetting = luaL_checkstring(L, 3);
DBVARIANT dbv = { 0 };
- int type = lua_type(L, 4);
- switch (type)
+ if (lua_isnoneornil(L, 5))
{
- case LUA_TBOOLEAN:
- dbv.bVal = lua_toboolean(L, 4);
- dbv.type = DBVT_BYTE;
- break;
- case LUA_TNUMBER:
- dbv.dVal = lua_tonumber(L, 4);
- dbv.type = DBVT_DWORD;
- break;
- case LUA_TSTRING:
- dbv.pszVal = (char*)lua_tostring(L, 4);
- dbv.type = DBVT_UTF8;
- break;
- case LUA_TTABLE:
+ int type = lua_type(L, 4);
+ switch (type)
{
+ case LUA_TBOOLEAN:
+ dbv.type = DBVT_BYTE;
+ break;
+ case LUA_TNUMBER:
+ dbv.type = DBVT_DWORD;
+ break;
+ case LUA_TSTRING:
+ dbv.type = DBVT_UTF8;
+ break;
+ case LUA_TTABLE:
dbv.type = DBVT_BLOB;
- dbv.cpbVal = luaM_table_to_bytearray(L, 4, &(dbv.pbVal));
+ break;
+ default:
+ lua_pushboolean(L, false);
+ return 1;
}
+ }
+ else
+ dbv.type = luaL_checkinteger(L, 5);
+
+ switch (dbv.type)
+ {
+ case DBVT_BYTE:
+ dbv.bVal = lua_isboolean(L, 4)
+ ? lua_toboolean(L, 4)
+ : luaL_checknumber(L, 4);
+ break;
+ case DBVT_WORD:
+ dbv.wVal = luaL_checknumber(L, 4);
+ break;
+ case DBVT_DWORD:
+ dbv.dVal = luaL_checknumber(L, 4);
+ break;
+ case DBVT_UTF8:
+ dbv.pszVal = mir_strdup(luaL_checkstring(L, 4));
+ case DBVT_ASCIIZ:
+ dbv.pszVal = mir_utf8decodeA(luaL_checkstring(L, 4));
+ case DBVT_WCHAR:
+ dbv.pwszVal = mir_utf8decodeW(luaL_checkstring(L, 4));
+ break;
+ case DBVT_BLOB:
+ dbv.cpbVal = (WORD)luaM_table_to_bytearray(L, 4, &(dbv.pbVal));
break;
default:
- lua_pushinteger(L, 1);
+ lua_pushboolean(L, false);
return 1;
}
@@ -533,7 +560,7 @@ void MT<CONTACTINFO>::Init(lua_State *L, CONTACTINFO **ci) hContact = (MCONTACT)lua_touserdata(L, 1);
break;
default:
- const char *msg = lua_pushfstring(L, "hContact expected, got %s", lua_typename(L, lua_type(L, 1)));
+ const char *msg = lua_pushfstring(L, "hContact expected, got %s", luaL_typename(L, 1));
luaL_argerror(L, 1, msg);
}
@@ -629,13 +656,6 @@ static int ci__index(lua_State *L) /***********************************************/
-static int dbei__test(lua_State *L)
-{
- int type = lua_type(L, 1);
-
- return 0;
-}
-
LUAMOD_API int luaopen_m_database(lua_State *L)
{
luaL_newlib(L, databaseApi);
diff --git a/plugins/MirLua/src/mlua_script.cpp b/plugins/MirLua/src/mlua_script.cpp index 27f972aaf4..3023d8c71e 100644 --- a/plugins/MirLua/src/mlua_script.cpp +++ b/plugins/MirLua/src/mlua_script.cpp @@ -97,7 +97,7 @@ void CMLuaScript::Unload() if (lua_isfunction(L, -1))
luaM_pcall(L);
luaL_unref(L, LUA_REGISTRYINDEX, unloadRef);
- status == None;
+ status = None;
}
luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED");
|