summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/m_core.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-11-25 18:17:36 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-11-25 18:17:36 +0000
commitf155980e50b5670593eb0857a061d16f708a362f (patch)
treedbf0c648b8db4eae88d7ce70bf3f8e7a4edf9ff9 /plugins/MirLua/src/m_core.cpp
parentb4132ae8daa7cb96ef49eca4827380c0e629a031 (diff)
MirLua: removed needless stuff
git-svn-id: http://svn.miranda-ng.org/main/trunk@15778 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/src/m_core.cpp')
-rw-r--r--plugins/MirLua/src/m_core.cpp89
1 files changed, 46 insertions, 43 deletions
diff --git a/plugins/MirLua/src/m_core.cpp b/plugins/MirLua/src/m_core.cpp
index d0986da3c6..133dfb119f 100644
--- a/plugins/MirLua/src/m_core.cpp
+++ b/plugins/MirLua/src/m_core.cpp
@@ -4,39 +4,14 @@ static int lua_CreateHookableEvent(lua_State *L)
{
const char *name = luaL_checkstring(L, 1);
- HANDLE res = ::CreateHookableEvent(name);
- if (!res)
+ HANDLE res = CreateHookableEvent(name);
+ if (res == NULL)
{
lua_pushnil(L);
+
return 1;
}
-
lua_pushlightuserdata(L, res);
- CMLua::Events.insert(res);
-
- return 1;
-}
-
-static int lua_DestroyHookableEvent(lua_State *L)
-{
- HANDLE hEvent = lua_touserdata(L, 1);
-
- int res = ::DestroyHookableEvent(hEvent);
- if (!res)
- CMLua::Events.remove(hEvent);
- lua_pushboolean(L, !res);
-
- return 1;
-}
-
-static int lua_NotifyEventHooks(lua_State *L)
-{
- HANDLE hEvent = lua_touserdata(L, 1);
- WPARAM wParam = luaM_towparam(L, 2);
- LPARAM lParam = luaM_tolparam(L, 3);
-
- int res = ::NotifyEventHooks(hEvent, wParam, lParam);
- lua_pushboolean(L, res != -1);
return 1;
}
@@ -48,14 +23,20 @@ int HookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM param)
int ref = param;
lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
- lua_pushlightuserdata(L, (void*)wParam);
- lua_pushlightuserdata(L, (void*)lParam);
+ if (wParam)
+ lua_pushlightuserdata(L, (void*)wParam);
+ else
+ lua_pushnil(L);
+
+ if (lParam)
+ lua_pushlightuserdata(L, (void*)lParam);
+ else
+ lua_pushnil(L);
+
if (lua_pcall(L, 2, 1, 0))
CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1));
- int res = (int)lua_tointeger(L, 1);
-
- return res;
+ return lua_tointeger(L, 1);
}
static int lua_HookEvent(lua_State *L)
@@ -67,16 +48,16 @@ static int lua_HookEvent(lua_State *L)
int ref = luaL_ref(L, LUA_REGISTRYINDEX);
HANDLE res = ::HookEventObjParam(name, HookEventObjParam, L, ref);
- if (!res)
+ if (res == NULL)
{
luaL_unref(L, LUA_REGISTRYINDEX, ref);
lua_pushnil(L);
+
return 1;
}
- CMLua::Hooks.insert(res);
CMLua::HookRefs.insert(new HandleRefParam(L, res, ref));
-
+
lua_pushlightuserdata(L, res);
return 1;
@@ -84,13 +65,12 @@ static int lua_HookEvent(lua_State *L)
static int lua_UnhookEvent(lua_State *L)
{
+ luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
HANDLE hEvent = lua_touserdata(L, 1);
- int res = ::UnhookEvent(hEvent);
+ int res = UnhookEvent(hEvent);
if (!res)
{
- CMLua::Hooks.remove(hEvent);
-
HandleRefParam *param = (HandleRefParam*)CMLua::HookRefs.find(hEvent);
if (param != NULL)
{
@@ -104,6 +84,32 @@ static int lua_UnhookEvent(lua_State *L)
return 1;
}
+static int lua_NotifyEventHooks(lua_State *L)
+{
+ luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+ HANDLE hEvent = lua_touserdata(L, 1);
+ WPARAM wParam = luaM_towparam(L, 2);
+ LPARAM lParam = luaM_tolparam(L, 3);
+
+ int res = NotifyEventHooks(hEvent, wParam, lParam);
+ lua_pushboolean(L, res != -1);
+
+ return 1;
+}
+
+static int lua_DestroyHookableEvent(lua_State *L)
+{
+ luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+ HANDLE hEvent = lua_touserdata(L, 1);
+
+ int res = DestroyHookableEvent(hEvent);
+ lua_pushboolean(L, !res);
+
+ return 1;
+}
+
+/***********************************************/
+
INT_PTR CreateServiceFunctionObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM param)
{
lua_State *L = (lua_State*)obj;
@@ -138,7 +144,6 @@ static int lua_CreateServiceFunction(lua_State *L)
return 1;
}
- CMLua::Services.insert(res);
CMLua::ServiceRefs.insert(new HandleRefParam(L, res, ref));
lua_pushlightuserdata(L, res);
@@ -150,8 +155,6 @@ static int lua_DestroyServiceFunction(lua_State *L)
{
HANDLE hService = lua_touserdata(L, 1);
- CMLua::Services.remove(hService);
-
HandleRefParam *param = (HandleRefParam*)CMLua::ServiceRefs.find(hService);
if (param != NULL)
{
@@ -262,7 +265,7 @@ luaL_Reg coreApi[] =
{ "UnhookEvent", lua_UnhookEvent },
{ "CreateServiceFunction", lua_CreateServiceFunction },
- { "DestroyServiceFunction", lua_DestroyServiceFunction },
+ //{ "DestroyServiceFunction", lua_DestroyServiceFunction },
{ "ServiceExists", lua_ServiceExists },
{ "CallService", lua_CallService },