summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-06-10 13:43:07 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-06-10 13:43:07 +0000
commit22ecdc28ebf053a6b335b802949f4f774af97d26 (patch)
tree980abced379dcc5a3c0021eac4ccdd20358387bc
parent61eb66b5f8be46f1e5fe148aefb0364e3ceb9d59 (diff)
MirLua:
- removed unwanted paths to script searching - fixed crash on event hook/service call - code cleanup git-svn-id: http://svn.miranda-ng.org/main/trunk@14103 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--plugins/MirLua/docs/examples/menus.lua3
-rw-r--r--plugins/MirLua/src/main.cpp2
-rw-r--r--plugins/MirLua/src/mlua.cpp23
-rw-r--r--plugins/MirLua/src/mlua.h6
-rw-r--r--plugins/MirLua/src/mlua_core.cpp26
-rw-r--r--plugins/MirLua/src/mlua_icons.cpp2
-rw-r--r--plugins/MirLua/src/mlua_menus.cpp4
-rw-r--r--plugins/MirLua/src/stdafx.h1
8 files changed, 43 insertions, 24 deletions
diff --git a/plugins/MirLua/docs/examples/menus.lua b/plugins/MirLua/docs/examples/menus.lua
index f3e279efad..b2a3f222d2 100644
--- a/plugins/MirLua/docs/examples/menus.lua
+++ b/plugins/MirLua/docs/examples/menus.lua
@@ -1,5 +1,6 @@
--- include m_menus module
require('m_menus')
+require('m_icons')
--- Add icon for menu items
local hIcon = M.Icons.AddIcon('testMenuIcon', 'Lua icon for menus')
@@ -28,4 +29,4 @@ local hMenuItem = M.Menus.AddContactMenuItem('testRemove', 0, 0, 0, 'Srv/TestRem
--- Remove menu item from parent menu
-- @param handle The handle of menu item
-- @return 0 on success
-M.Menus.RemoveMenuItem(hMenuItem);
+M.Menus.RemoveMenuItem(hMenuItem)
diff --git a/plugins/MirLua/src/main.cpp b/plugins/MirLua/src/main.cpp
index 59ba4fda87..36c64e2572 100644
--- a/plugins/MirLua/src/main.cpp
+++ b/plugins/MirLua/src/main.cpp
@@ -41,6 +41,8 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
void LoadScripts(const TCHAR *scriptDir)
{
+ mLua->AddPath(ptrA(mir_utf8encodeT(scriptDir)));
+
TCHAR searchMask[MAX_PATH];
mir_sntprintf(searchMask, _T("%s\\%s"), scriptDir, _T("*.lua"));
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp
index fc73ee3496..b6d3895940 100644
--- a/plugins/MirLua/src/mlua.cpp
+++ b/plugins/MirLua/src/mlua.cpp
@@ -5,7 +5,15 @@ CMLua::CMLua()
L = luaL_newstate();
luaL_openlibs(L);
- luaopen_m(L);
+ lua_getglobal(L, "package");
+ lua_pushstring(L, "");
+ lua_setfield(L, -2, "path");
+ lua_pushstring(L, "");
+ lua_setfield(L, -2, "cpath");
+ lua_pop(L, 1);
+
+ luaL_newlib(L, coreLib);
+ lua_setglobal(L, "M");
Preload(M_ICONSLIBNAME, luaopen_m_icons);
Preload(M_MENUSLIBNAME, luaopen_m_menus);
@@ -16,9 +24,20 @@ CMLua::~CMLua()
lua_close(L);
}
+void CMLua::AddPath(const char *path)
+{
+ lua_getglobal(L, "package");
+ lua_getfield(L, -1, "path");
+ const char *oldPath = luaL_checkstring(L, -1);
+ lua_pop(L, 1);
+ lua_pushfstring(L, "%s;%s\\?.lua", oldPath, path);
+ lua_setfield(L, -2, "path");
+ lua_pop(L, 1);
+}
+
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 f4378c1c57..54f6c4d987 100644
--- a/plugins/MirLua/src/mlua.h
+++ b/plugins/MirLua/src/mlua.h
@@ -5,9 +5,7 @@ class CMLua
{
private:
lua_State *L;
- HANDLE hConsole;
-
- int luaopen_m(lua_State *L);
+ static luaL_Reg coreLib[10];
void Preload(const char *name, lua_CFunction func);
@@ -15,6 +13,8 @@ public:
CMLua();
~CMLua();
+ void AddPath(const char *path);
+
void Load(const char *name);
};
diff --git a/plugins/MirLua/src/mlua_core.cpp b/plugins/MirLua/src/mlua_core.cpp
index cb80255eb7..7e26e8b354 100644
--- a/plugins/MirLua/src/mlua_core.cpp
+++ b/plugins/MirLua/src/mlua_core.cpp
@@ -41,10 +41,12 @@ static int HookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM par
lua_pushnumber(L, wParam);
lua_pushnumber(L, lParam);
- lua_call(L, 2, 1);
- int res = (int)luaL_checkinteger(L, 1);
+ if(lua_pcall(L, 2, 1, 0))
+ printf("%s\n", lua_tostring(L, -1));
+
+ int res = (int)lua_tointeger(L, 1);
- luaL_unref(L, LUA_REGISTRYINDEX, ref);
+ //luaL_unref(L, LUA_REGISTRYINDEX, ref);
return res;
}
@@ -81,10 +83,12 @@ static INT_PTR ServiceFunctionObjParam(void *obj, WPARAM wParam, LPARAM lParam,
lua_pushnumber(L, wParam);
lua_pushnumber(L, lParam);
- lua_call(L, 2, 1);
- INT_PTR res = (INT_PTR)luaL_checkinteger(L, 1);
+ if (lua_pcall(L, 2, 1, 0))
+ printf("%s\n", lua_tostring(L, -1));
- luaL_unref(L, LUA_REGISTRYINDEX, ref);
+ INT_PTR res = (INT_PTR)lua_tointeger(L, 1);
+
+ //luaL_unref(L, LUA_REGISTRYINDEX, ref);
return res;
}
@@ -135,7 +139,7 @@ static int lua_CallService(lua_State *L)
return 1;
}
-static luaL_Reg coreLib[] =
+luaL_Reg CMLua::coreLib[] =
{
{ "CreateHookableEvent", lua_CreateHookableEvent },
{ "DestroyHookableEvent", lua_DestroyHookableEvent },
@@ -153,11 +157,3 @@ static luaL_Reg coreLib[] =
{ NULL, NULL }
};
-
-int CMLua::luaopen_m(lua_State *L)
-{
- luaL_newlib(L, coreLib);
- lua_setglobal(L, "M");
-
- return 1;
-}
diff --git a/plugins/MirLua/src/mlua_icons.cpp b/plugins/MirLua/src/mlua_icons.cpp
index 71219e4b96..5c53694f15 100644
--- a/plugins/MirLua/src/mlua_icons.cpp
+++ b/plugins/MirLua/src/mlua_icons.cpp
@@ -71,5 +71,7 @@ int luaopen_m_icons(lua_State *L)
luaL_setfuncs(L, iconsLib, 0);
lua_setfield(L, -2, "Icons");
+ lua_pop(L, 1);
+
return 1;
}
diff --git a/plugins/MirLua/src/mlua_menus.cpp b/plugins/MirLua/src/mlua_menus.cpp
index d3078fc5b3..e59bc33a0f 100644
--- a/plugins/MirLua/src/mlua_menus.cpp
+++ b/plugins/MirLua/src/mlua_menus.cpp
@@ -51,8 +51,6 @@ static luaL_Reg menusLib[] =
int luaopen_m_menus(lua_State *L)
{
- //luaL_newlib(L, CMLua::clistLib);
-
lua_getglobal(L, "M");
luaL_checktype(L, -1, LUA_TTABLE);
@@ -60,5 +58,7 @@ int luaopen_m_menus(lua_State *L)
luaL_setfuncs(L, menusLib, 0);
lua_setfield(L, -2, "Menus");
+ lua_pop(L, 1);
+
return 1;
}
diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h
index ef742b73ad..f2e484e579 100644
--- a/plugins/MirLua/src/stdafx.h
+++ b/plugins/MirLua/src/stdafx.h
@@ -11,7 +11,6 @@
#include <m_clist.h>
#include <m_genmenu.h>
#include <m_icolib.h>
-#include <m_skin.h>
extern "C"
{