summaryrefslogtreecommitdiff
path: root/plugins/MirLua
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-07-12 12:57:37 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-07-12 12:57:37 +0000
commit9677b394a0977382ed4a406de039ef370cfd29a2 (patch)
treef5585e9ca4e6a755308680100e46f3aa5f6ffce4 /plugins/MirLua
parenta36fb8e8cdc86ef569c4e75eebabbf341f801ffb (diff)
MirLua:
- lua_Utf8DecodeA SHOULD return pointer - added OnContactSettingChanged to m_database - extended lua print logging git-svn-id: http://svn.miranda-ng.org/main/trunk@14541 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua')
-rw-r--r--plugins/MirLua/src/m_core.cpp2
-rw-r--r--plugins/MirLua/src/m_database.cpp167
-rw-r--r--plugins/MirLua/src/mlua_utils.cpp20
3 files changed, 124 insertions, 65 deletions
diff --git a/plugins/MirLua/src/m_core.cpp b/plugins/MirLua/src/m_core.cpp
index 1ce4c6fcdb..2a5564a07b 100644
--- a/plugins/MirLua/src/m_core.cpp
+++ b/plugins/MirLua/src/m_core.cpp
@@ -165,7 +165,7 @@ static int lua_Utf8DecodeA(lua_State *L)
const char *string = luaL_checkstring(L, 1);
char *res = mir_utf8decodeA(string);
- lua_pushstring(L, res);
+ lua_pushlightuserdata(L, res);
return 1;
}
diff --git a/plugins/MirLua/src/m_database.cpp b/plugins/MirLua/src/m_database.cpp
index 2410dec01f..3f553c983f 100644
--- a/plugins/MirLua/src/m_database.cpp
+++ b/plugins/MirLua/src/m_database.cpp
@@ -198,6 +198,66 @@ static int lua_GetContactSetting(lua_State *L)
return 1;
}
+typedef struct
+{
+ int arrlen;
+ char **pszSettingName;
+}
+enumDBSettingsParam;
+
+static int SettingsEnumProc(const char* szSetting, LPARAM lParam)
+{
+ if (szSetting)
+ {
+ enumDBSettingsParam* p = (enumDBSettingsParam*)lParam;
+
+ p->arrlen++;
+ p->pszSettingName = (char**)mir_realloc(p->pszSettingName, p->arrlen * sizeof(char*));
+ p->pszSettingName[p->arrlen - 1] = mir_strdup(szSetting);
+ }
+ return 0;
+}
+
+static int lua_EnumSettings(lua_State *L)
+{
+ MCONTACT hContact = lua_tointeger(L, 1);
+ LPCSTR szModule = luaL_checkstring(L, 2);
+
+ if (!lua_isfunction(L, 3))
+ {
+ lua_pushlightuserdata(L, NULL);
+ return 1;
+ }
+
+ lua_pushvalue(L, 3);
+ int ref = luaL_ref(L, LUA_REGISTRYINDEX);
+
+ enumDBSettingsParam param = { 0, NULL };
+
+ DBCONTACTENUMSETTINGS dbces = { 0 };
+ dbces.pfnEnumProc = SettingsEnumProc;
+ dbces.szModule = szModule;
+ dbces.ofsSettings = 0;
+ dbces.lParam = (LPARAM)&param;
+ INT_PTR res = ::CallService(MS_DB_CONTACT_ENUMSETTINGS, hContact, (LPARAM)&dbces);
+
+ for (int i = 0; i < param.arrlen; i++)
+ {
+ lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
+ lua_pushstring(L, mir_utf8encode(param.pszSettingName[i]));
+ if (lua_pcall(L, 1, 0, 0))
+ CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1));
+
+ mir_free(param.pszSettingName[i]);
+ }
+ mir_free(param.pszSettingName);
+
+ luaL_unref(L, LUA_REGISTRYINDEX, ref);
+ lua_pushinteger(L, res);
+
+ return 1;
+}
+
static int lua_DeleteContactSetting(lua_State *L)
{
MCONTACT hContact = lua_tointeger(L, 1);
@@ -221,6 +281,46 @@ static int lua_DeleteModule(lua_State *L)
return 1;
}
+static int SettingsChangedHookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM param)
+{
+ lua_State *L = (lua_State*)obj;
+
+ int ref = param;
+ lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
+
+ lua_pushnumber(L, wParam);
+
+ DBCONTACTWRITESETTING *dbcws = (DBCONTACTWRITESETTING*)lParam;
+
+
+ if (lua_pcall(L, 2, 1, 0))
+ printf("%s\n", lua_tostring(L, -1));
+
+ int res = (int)lua_tointeger(L, 1);
+
+ return res;
+}
+
+static int lua_OnContactSettingChanged(lua_State *L)
+{
+ if (!lua_isfunction(L, 1))
+ {
+ lua_pushlightuserdata(L, NULL);
+ return 1;
+ }
+
+ lua_pushvalue(L, 1);
+ int ref = luaL_ref(L, LUA_REGISTRYINDEX);
+
+ HANDLE res = ::HookEventObjParam(ME_DB_CONTACT_SETTINGCHANGED, SettingsChangedHookEventObjParam, L, ref);
+ lua_pushlightuserdata(L, res);
+
+ CMLua::Hooks.insert(res);
+ CMLua::HookRefs.insert(new HandleRefParam(L, res, ref));
+
+ return 1;
+}
+
static int lua_DecodeDBCONTACTWRITESETTING(lua_State *L)
{
DBCONTACTWRITESETTING *pDBCWS = (DBCONTACTWRITESETTING*)lua_tointeger(L, 1);
@@ -262,66 +362,6 @@ static int lua_DecodeDBCONTACTWRITESETTING(lua_State *L)
return 1;
}
-typedef struct
-{
- int arrlen;
- char **pszSettingName;
-}
-enumDBSettingsParam;
-
-static int SettingsEnumProc(const char* szSetting, LPARAM lParam)
-{
- if (szSetting)
- {
- enumDBSettingsParam* p = (enumDBSettingsParam*)lParam;
-
- p->arrlen++;
- p->pszSettingName = (char**)mir_realloc(p->pszSettingName, p->arrlen * sizeof(char*));
- p->pszSettingName[p->arrlen - 1] = mir_strdup(szSetting);
- }
- return 0;
-}
-
-static int lua_EnumSettings(lua_State *L)
-{
- MCONTACT hContact = lua_tointeger(L, 1);
- LPCSTR szModule = luaL_checkstring(L, 2);
-
- if (!lua_isfunction(L, 3))
- {
- lua_pushlightuserdata(L, NULL);
- return 1;
- }
-
- lua_pushvalue(L, 3);
- int ref = luaL_ref(L, LUA_REGISTRYINDEX);
-
- enumDBSettingsParam param = { 0, NULL };
-
- DBCONTACTENUMSETTINGS dbces = { 0 };
- dbces.pfnEnumProc = SettingsEnumProc;
- dbces.szModule = szModule;
- dbces.ofsSettings = 0;
- dbces.lParam = (LPARAM)&param;
- INT_PTR res = ::CallService(MS_DB_CONTACT_ENUMSETTINGS, hContact, (LPARAM)&dbces);
-
- for (int i = 0; i < param.arrlen; i++)
- {
- lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
- lua_pushstring(L, mir_utf8encode(param.pszSettingName[i]));
- if (lua_pcall(L, 1, 0, 0))
- CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1));
-
- mir_free(param.pszSettingName[i]);
- }
- mir_free(param.pszSettingName);
-
- luaL_unref(L, LUA_REGISTRYINDEX, ref);
- lua_pushinteger(L, res);
-
- return 1;
-}
-
static luaL_Reg databaseApi[] =
{
{ "FindFirstContact", lua_FindFirstContact },
@@ -337,13 +377,14 @@ static luaL_Reg databaseApi[] =
{ "GetEvent", lua_GetEvent },
{ "WriteContactSetting", lua_WriteContactSetting },
+
{ "GetContactSetting", lua_GetContactSetting },
- { "DeleteContactSetting", lua_DeleteContactSetting },
+ { "EnumSettings", lua_EnumSettings },
+ { "DeleteContactSetting", lua_DeleteContactSetting },
{ "DeleteModule", lua_DeleteModule },
- { "EnumSettings", lua_EnumSettings },
-
+ { "OnContactSettingChanged", lua_OnContactSettingChanged },
{ "DecodeDBCONTACTWRITESETTING", lua_DecodeDBCONTACTWRITESETTING },
{ NULL, NULL }
diff --git a/plugins/MirLua/src/mlua_utils.cpp b/plugins/MirLua/src/mlua_utils.cpp
index 3a58867171..7fa59212c5 100644
--- a/plugins/MirLua/src/mlua_utils.cpp
+++ b/plugins/MirLua/src/mlua_utils.cpp
@@ -5,7 +5,25 @@ int luaM_print(lua_State *L)
CMStringA data;
int nargs = lua_gettop(L);
for (int i = 1; i <= nargs; ++i)
- data.AppendFormat("%s ", lua_tostring(L, i));
+ {
+ switch (lua_type(L, i))
+ {
+ case LUA_TNIL:
+ data.AppendFormat("%s ", "nil");
+ break;
+ case LUA_TBOOLEAN:
+ case LUA_TNUMBER:
+ case LUA_TSTRING:
+ data.AppendFormat("%s ", lua_tostring(L, i));
+ break;
+ case LUA_TTABLE:
+ data.AppendFormat("%s ", "table");
+ break;
+ default:
+ data.AppendFormat("0x%p ", lua_topointer(L, i));
+ break;
+ }
+ }
data.Delete(data.GetLength() - 3, 3);
CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)data.GetBuffer());