summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/m_msg_buttonsbar.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-10-21 18:29:50 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-10-21 18:29:50 +0000
commitc99bbd2ef7f9fb2295ff2ec07bb690c4d7351a71 (patch)
treea760bc80000499732a80034d32bdd02cb3e9b885 /plugins/MirLua/src/m_msg_buttonsbar.cpp
parentdd4878e302ae384f7b51b9ef60ff3a06dbd11a11 (diff)
MirLua:
- added totable to cast userdata to metatable - all modules hooks are marked as obsolete - version bumb git-svn-id: http://svn.miranda-ng.org/main/trunk@15586 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/src/m_msg_buttonsbar.cpp')
-rw-r--r--plugins/MirLua/src/m_msg_buttonsbar.cpp53
1 files changed, 52 insertions, 1 deletions
diff --git a/plugins/MirLua/src/m_msg_buttonsbar.cpp b/plugins/MirLua/src/m_msg_buttonsbar.cpp
index 3973badba7..b7824e78aa 100644
--- a/plugins/MirLua/src/m_msg_buttonsbar.cpp
+++ b/plugins/MirLua/src/m_msg_buttonsbar.cpp
@@ -132,7 +132,7 @@ int ButtonPressedHookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPAR
lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
lua_pushnumber(L, wParam);
-
+
CustomButtonClickData *bcd = (CustomButtonClickData*)lParam;
lua_newtable(L);
@@ -159,6 +159,8 @@ int ButtonPressedHookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPAR
static int lua_OnMsgToolBarButtonPressed(lua_State *L)
{
+ ObsoleteMethod(L, "Use m.HookEvent instead");
+
if (!lua_isfunction(L, 1))
{
lua_pushlightuserdata(L, NULL);
@@ -210,9 +212,58 @@ static luaL_Reg msgbuttinsbarApi[] =
{ NULL, NULL }
};
+#define MT_CUSTOMBUTTONCLICKDATA "CustomButtonClickData"
+
+static int bcd__init(lua_State *L)
+{
+ CustomButtonClickData *udata = (CustomButtonClickData*)lua_touserdata(L, 1);
+ if (udata == NULL)
+ {
+ lua_pushnil(L);
+ return 1;
+ }
+
+ CustomButtonClickData **bcd = (CustomButtonClickData**)lua_newuserdata(L, sizeof(CustomButtonClickData*));
+ *bcd = udata;
+
+ luaL_setmetatable(L, MT_CUSTOMBUTTONCLICKDATA);
+
+ return 1;
+}
+
+static int bcd__index(lua_State *L)
+{
+ CustomButtonClickData *bcd = *(CustomButtonClickData**)luaL_checkudata(L, 1, MT_CUSTOMBUTTONCLICKDATA);
+ const char *key = lua_tostring(L, 2);
+
+ if (!mir_strcmpi(key, "Module"))
+ lua_pushstring(L, ptrA(mir_utf8encode(bcd->pszModule)));
+ else if (!mir_strcmpi(key, "ButtonID"))
+ lua_pushinteger(L, bcd->dwButtonId);
+ else if (!mir_strcmpi(key, "hContact"))
+ lua_pushinteger(L, bcd->hContact);
+ else if (!mir_strcmpi(key, "Flags"))
+ lua_pushinteger(L, bcd->flags);
+ else
+ lua_pushnil(L);
+
+ return 1;
+}
+
+static luaL_Reg bcdMeta[] =
+{
+ { "__init", bcd__init },
+ { "__index", bcd__index },
+ { NULL, NULL }
+};
+
LUAMOD_API int luaopen_m_msg_buttonsbar(lua_State *L)
{
luaL_newlib(L, msgbuttinsbarApi);
+
+ luaL_newmetatable(L, MT_CUSTOMBUTTONCLICKDATA);
+ luaL_setfuncs(L, bcdMeta, 0);
+ lua_pop(L, 1);
return 1;
}