summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/MirLua/src')
-rw-r--r--plugins/MirLua/src/m_core.cpp (renamed from plugins/MirLua/src/mlua_core.cpp)48
-rw-r--r--plugins/MirLua/src/m_genmenu.cpp (renamed from plugins/MirLua/src/mlua_menus.cpp)13
-rw-r--r--plugins/MirLua/src/m_icolib.cpp (renamed from plugins/MirLua/src/mlua_icons.cpp)13
-rw-r--r--plugins/MirLua/src/mlua.cpp8
-rw-r--r--plugins/MirLua/src/mlua.h2
-rw-r--r--plugins/MirLua/src/stdafx.h8
6 files changed, 63 insertions, 29 deletions
diff --git a/plugins/MirLua/src/mlua_core.cpp b/plugins/MirLua/src/m_core.cpp
index 7e26e8b354..21cd25ce80 100644
--- a/plugins/MirLua/src/mlua_core.cpp
+++ b/plugins/MirLua/src/m_core.cpp
@@ -55,6 +55,12 @@ static int lua_HookEvent(lua_State *L)
{
const char *name = luaL_checkstring(L, 1);
+ if (!lua_isfunction(L, 2))
+ {
+ lua_pushlightuserdata(L, NULL);
+ return 1;
+ }
+
lua_pushvalue(L, 2);
int ref = luaL_ref(L, LUA_REGISTRYINDEX);
@@ -74,6 +80,40 @@ static int lua_UnhookEvent(lua_State *L)
return 1;
}
+static int lua_OnModulesLoaded(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_SYSTEM_MODULESLOADED, HookEventObjParam, L, ref);
+ lua_pushlightuserdata(L, res);
+
+ return 1;
+}
+
+static int lua_OnPreShutdown(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_SYSTEM_PRESHUTDOWN, HookEventObjParam, L, ref);
+ lua_pushlightuserdata(L, res);
+
+ return 1;
+}
+
static INT_PTR ServiceFunctionObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM param)
{
lua_State *L = (lua_State*)obj;
@@ -97,6 +137,12 @@ static int lua_CreateServiceFunction(lua_State *L)
{
const char *name = luaL_checkstring(L, 1);
+ if (!lua_isfunction(L, 2))
+ {
+ lua_pushlightuserdata(L, NULL);
+ return 1;
+ }
+
lua_pushvalue(L, 2);
int ref = luaL_ref(L, LUA_REGISTRYINDEX);
@@ -148,6 +194,8 @@ luaL_Reg CMLua::coreLib[] =
{ "HookEvent", lua_HookEvent },
{ "UnhookEvent", lua_UnhookEvent },
+ { "OnModulesLoaded", lua_OnModulesLoaded },
+ { "OnPreShutdown", lua_OnPreShutdown },
{ "CreateServiceFunction", lua_CreateServiceFunction },
{ "DestroyServiceFunction", lua_DestroyServiceFunction },
diff --git a/plugins/MirLua/src/mlua_menus.cpp b/plugins/MirLua/src/m_genmenu.cpp
index e59bc33a0f..5a185f64bd 100644
--- a/plugins/MirLua/src/mlua_menus.cpp
+++ b/plugins/MirLua/src/m_genmenu.cpp
@@ -40,7 +40,7 @@ static int lua_RemoveMenuItem(lua_State *L)
return 1;
}
-static luaL_Reg menusLib[] =
+static luaL_Reg genmenuApi[] =
{
{ "AddMainMenuItem", lua_AddMainMenuItem },
{ "AddContactMenuItem", lua_AddContactMenuItem },
@@ -49,16 +49,9 @@ static luaL_Reg menusLib[] =
{ NULL, NULL }
};
-int luaopen_m_menus(lua_State *L)
+LUAMOD_API int luaopen_m_genmenu(lua_State *L)
{
- lua_getglobal(L, "M");
- luaL_checktype(L, -1, LUA_TTABLE);
-
- lua_newtable(L);
- luaL_setfuncs(L, menusLib, 0);
- lua_setfield(L, -2, "Menus");
-
- lua_pop(L, 1);
+ luaL_newlib(L, genmenuApi);
return 1;
}
diff --git a/plugins/MirLua/src/mlua_icons.cpp b/plugins/MirLua/src/m_icolib.cpp
index 5c53694f15..cc8808aa0e 100644
--- a/plugins/MirLua/src/mlua_icons.cpp
+++ b/plugins/MirLua/src/m_icolib.cpp
@@ -53,7 +53,7 @@ static int lua_RemoveIcon(lua_State *L)
return 1;
}
-static luaL_Reg iconsLib[] =
+static luaL_Reg icolibApi[] =
{
{ "AddIcon", lua_AddIcon },
{ "GetIcon", lua_GetIcon },
@@ -62,16 +62,9 @@ static luaL_Reg iconsLib[] =
{ NULL, NULL }
};
-int luaopen_m_icons(lua_State *L)
+LUAMOD_API int luaopen_m_icolib(lua_State *L)
{
- lua_getglobal(L, "M");
- luaL_checktype(L, -1, LUA_TTABLE);
-
- lua_newtable(L);
- luaL_setfuncs(L, iconsLib, 0);
- lua_setfield(L, -2, "Icons");
-
- lua_pop(L, 1);
+ luaL_newlib(L, icolibApi);
return 1;
}
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp
index b6d3895940..c600ad058e 100644
--- a/plugins/MirLua/src/mlua.cpp
+++ b/plugins/MirLua/src/mlua.cpp
@@ -13,10 +13,10 @@ CMLua::CMLua()
lua_pop(L, 1);
luaL_newlib(L, coreLib);
- lua_setglobal(L, "M");
+ lua_setglobal(L, "m");
- Preload(M_ICONSLIBNAME, luaopen_m_icons);
- Preload(M_MENUSLIBNAME, luaopen_m_menus);
+ Preload(MLUA_ICOLIB, luaopen_m_icolib);
+ Preload(MLUA_GENMENU, luaopen_m_genmenu);
}
CMLua::~CMLua()
@@ -37,7 +37,7 @@ void CMLua::AddPath(const char *path)
void CMLua::Load(const char *path)
{
- if (luaL_dofile(L, path));
+ if (luaL_dofile(L, path))
printf("%s\n", lua_tostring(L, -1));
}
diff --git a/plugins/MirLua/src/mlua.h b/plugins/MirLua/src/mlua.h
index 54f6c4d987..8abc839bd0 100644
--- a/plugins/MirLua/src/mlua.h
+++ b/plugins/MirLua/src/mlua.h
@@ -5,7 +5,7 @@ class CMLua
{
private:
lua_State *L;
- static luaL_Reg coreLib[10];
+ static luaL_Reg coreLib[12];
void Preload(const char *name, lua_CFunction func);
diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h
index f2e484e579..6d206f7644 100644
--- a/plugins/MirLua/src/stdafx.h
+++ b/plugins/MirLua/src/stdafx.h
@@ -38,10 +38,10 @@ extern HINSTANCE g_hInstance;
#define CUSTOM_SCRIPTS_PATHT MIRANDA_USERDATA "\\Scripts"
#endif
-#define M_ICONSLIBNAME "m_icons"
-int luaopen_m_icons(lua_State *L);
+#define MLUA_ICOLIB "m_icolib"
+LUAMOD_API int (luaopen_m_icolib)(lua_State *L);
-#define M_MENUSLIBNAME "m_menus"
-int luaopen_m_menus(lua_State *L);
+#define MLUA_GENMENU "m_genmenu"
+LUAMOD_API int (luaopen_m_genmenu)(lua_State *L);
#endif //_COMMON_H_