From ee57d99782d0a3a789b673f13cfdf96e1a77de23 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Mon, 13 Jul 2015 08:32:15 +0000 Subject: MirLua: added GetIniValue, SetIniValue to m_windows git-svn-id: http://svn.miranda-ng.org/main/trunk@14549 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/m_windows.cpp | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'plugins') diff --git a/plugins/MirLua/src/m_windows.cpp b/plugins/MirLua/src/m_windows.cpp index e42c9ece7b..26be06b0f2 100644 --- a/plugins/MirLua/src/m_windows.cpp +++ b/plugins/MirLua/src/m_windows.cpp @@ -25,10 +25,56 @@ static int lua_ShellExecute(lua_State *L) return 0; } +static int lua_GetIniValue(lua_State *L) +{ + ptrT path(mir_utf8decodeT(luaL_checkstring(L, 1))); + ptrT section(mir_utf8decodeT(luaL_checkstring(L, 2))); + ptrT key(mir_utf8decodeT(luaL_checkstring(L, 3))); + + if (lua_isinteger(L, 4)) + { + int default = lua_tointeger(L, 4); + + UINT res = ::GetPrivateProfileInt(section, key, default, path); + lua_pushinteger(L, res); + + return 1; + } + + ptrT default(mir_utf8decodeT(lua_tostring(L, 4))); + + TCHAR value[MAX_PATH] = { 0 }; + if (!::GetPrivateProfileString(section, key, default, value, _countof(value), path)) + { + lua_pushvalue(L, 4); + } + + ptrA res(mir_utf8encodeT(value)); + lua_pushstring(L, res); + + return 1; +} + +static int lua_SetIniValue(lua_State *L) +{ + ptrT path(mir_utf8decodeT(luaL_checkstring(L, 1))); + ptrT section(mir_utf8decodeT(luaL_checkstring(L, 2))); + ptrT key(mir_utf8decodeT(luaL_checkstring(L, 3))); + ptrT value(mir_utf8decodeT(lua_tostring(L, 4))); + + bool res = ::WritePrivateProfileString(section, key, value, path) != 0; + lua_pushboolean(L, res); + + return 1; +} + static luaL_Reg winApi[] = { { "MessageBox", lua_MessageBox }, + { "GetIniValue", lua_GetIniValue }, + { "SetIniValue", lua_SetIniValue }, + { "ShellExecute", lua_ShellExecute }, { NULL, NULL } -- cgit v1.2.3