diff options
author | George Hazan <ghazan@miranda.im> | 2019-07-12 13:48:39 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-07-12 13:48:39 +0300 |
commit | d0c7ef4f48cdf9f1ad622fc84d10257c21bb91db (patch) | |
tree | b352641bcbaf04acc8a3b1f41d37fa151997baae /plugins/MirLua/src/Modules/m_extraIcon.cpp | |
parent | 6632ca13387288f6f2bb58d7f1aa9ea4730d9b43 (diff) |
MirLua: interface for extra icons added
Diffstat (limited to 'plugins/MirLua/src/Modules/m_extraIcon.cpp')
-rw-r--r-- | plugins/MirLua/src/Modules/m_extraIcon.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/plugins/MirLua/src/Modules/m_extraIcon.cpp b/plugins/MirLua/src/Modules/m_extraIcon.cpp new file mode 100644 index 0000000000..da25abbc12 --- /dev/null +++ b/plugins/MirLua/src/Modules/m_extraIcon.cpp @@ -0,0 +1,84 @@ +#include "../stdafx.h" + +struct EIHook +{ + EIHook(lua_State *_p1, int _p2) : + L(_p1), + ref(_p2) + {} + + lua_State *L; + int ref; +}; + +static int ei_hook(WPARAM hContact, LPARAM slot, LPARAM param) +{ + EIHook *pHook = (EIHook *)param; + if (pHook) { + auto *L = pHook->L; + lua_rawgeti(L, LUA_REGISTRYINDEX, pHook->ref); + + lua_pushinteger(L, hContact); + lua_pushinteger(L, slot); + luaM_pcall(L, 2, 0); + } + return 0; +} + +static int ei_Register(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + const char *descr = luaL_checkstring(L, 2); + HANDLE hIcolib = lua_touserdata(L, 3); + luaL_checktype(L, 4, LUA_TFUNCTION); + + lua_pushvalue(L, 4); + int ref = luaL_ref(L, LUA_REGISTRYINDEX); + + HANDLE res = ExtraIcon_RegisterIcolib(name, descr, hIcolib, ei_hook, (LPARAM)new EIHook(L, ref)); + lua_pushlightuserdata(L, res); + return 1; +} + +static int ei_SetIcon(lua_State *L) +{ + HANDLE hExtraIcon = lua_touserdata(L, 1); + int hContact = luaL_checkinteger(L, 2); + HANDLE hIcon = lua_touserdata(L, 3); + ExtraIcon_SetIcon(hExtraIcon, hContact, hIcon); + return 1; +} + +static int ei_SetByName(lua_State *L) +{ + HANDLE hExtraIcon = lua_touserdata(L, 1); + int hContact = luaL_checkinteger(L, 2); + const char *icon = luaL_checkstring(L, 3); + ExtraIcon_SetIconByName(hExtraIcon, hContact, icon); + return 1; +} + +static int ei_Clear(lua_State *L) +{ + HANDLE hExtraIcon = lua_touserdata(L, 1); + int hContact = luaL_checkinteger(L, 2); + ExtraIcon_Clear(hExtraIcon, hContact); + return 1; +} + +static luaL_Reg eiApi[] = +{ + { "Register", ei_Register }, + + { "SetIcon", ei_SetIcon }, + { "SetByName", ei_SetByName }, + { "Clear", ei_Clear }, + + { nullptr, nullptr } +}; + +LUAMOD_API int luaopen_m_extraIcon(lua_State *L) +{ + luaL_newlib(L, eiApi); + return 1; +} |