diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2016-01-07 13:17:33 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2016-01-07 13:17:33 +0000 |
commit | 2826ce96c351ae3d5fc7dea6b4bc60e92b23e550 (patch) | |
tree | 2a6ae22de1c6107e5a3fe52f4dd1de2001c78afc /plugins | |
parent | 8a22b1b13cbd23e4d0a0a1cf3da9c84596b55280 (diff) |
MirLua: fixed module loading
git-svn-id: http://svn.miranda-ng.org/main/trunk@16046 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/MirLua/src/m_clist.cpp | 71 | ||||
-rw-r--r-- | plugins/MirLua/src/m_hotkeys.cpp | 42 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_module_loader.cpp | 5 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_script.cpp | 15 |
4 files changed, 67 insertions, 66 deletions
diff --git a/plugins/MirLua/src/m_clist.cpp b/plugins/MirLua/src/m_clist.cpp index 1a43b298ab..a39534c0da 100644 --- a/plugins/MirLua/src/m_clist.cpp +++ b/plugins/MirLua/src/m_clist.cpp @@ -2,29 +2,22 @@ static int clist_AddMainMenuItem(lua_State *L)
{
- if (lua_type(L, 1) != LUA_TTABLE)
+ HGENMENU res = NULL;
+
+ if (lua_type(L, 1) == LUA_TSTRING)
{
- lua_pushlightuserdata(L, 0);
- return 1;
+ const char *name = luaL_checkstring(L, 1);
+ int position = lua_tointeger(L, 2);
+ HANDLE hIcon = (HANDLE)lua_touserdata(L, 3);
+ res = Menu_CreateRoot(MO_MAIN, ptrT(Utf8DecodeT(name)), position, hIcon);
+ }
+ else if (lua_type(L, 1) == LUA_TTABLE)
+ {
+ CMenuItem mi;
+ MakeMenuItem(L, mi);
+ res = Menu_AddMainMenuItem(&mi);
}
- CMenuItem mi;
- MakeMenuItem(L, mi);
-
- HGENMENU res = Menu_AddMainMenuItem(&mi);
- lua_pushlightuserdata(L, res);
-
- return 1;
-}
-
-static int clist_CreateMainMenuRoot(lua_State *L)
-{
- int hMenuObject = luaL_checkinteger(L, 1);
- const char *name = luaL_checkstring(L, 2);
- int position = lua_tointeger(L, 3);
- HANDLE hIcon = (HANDLE)lua_touserdata(L, 4);
-
- HGENMENU res = Menu_CreateRoot(MO_MAIN, ptrT(Utf8DecodeT(name)), position, hIcon);
lua_pushlightuserdata(L, res);
return 1;
@@ -32,31 +25,23 @@ static int clist_CreateMainMenuRoot(lua_State *L) static int clist_AddContactMenuItem(lua_State *L)
{
- if (lua_type(L, 1) != LUA_TTABLE)
+ HGENMENU res = NULL;
+
+ if (lua_type(L, 1) == LUA_TSTRING)
{
- lua_pushlightuserdata(L, 0);
- return 1;
+ const char *name = luaL_checkstring(L, 1);
+ int position = lua_tointeger(L, 2);
+ HANDLE hIcon = (HANDLE)lua_touserdata(L, 3);
+ res = Menu_CreateRoot(MO_MAIN, ptrT(Utf8DecodeT(name)), position, hIcon);
+ }
+ else if (lua_type(L, 1) == LUA_TTABLE)
+ {
+ CMenuItem mi;
+ MakeMenuItem(L, mi);
+ ptrA szProto(mir_utf8decode((char*)lua_tostring(L, 2), NULL));
+ res = Menu_AddContactMenuItem(&mi, szProto);
}
-
- CMenuItem mi;
- MakeMenuItem(L, mi);
-
- ptrA szProto(mir_utf8decode((char*)lua_tostring(L, 2), NULL));
-
- HGENMENU res = Menu_AddContactMenuItem(&mi, szProto);
- lua_pushlightuserdata(L, res);
-
- return 1;
-}
-
-static int clist_CreateContactMenuRoot(lua_State *L)
-{
- int hMenuObject = luaL_checkinteger(L, 1);
- const char *name = luaL_checkstring(L, 2);
- int position = lua_tointeger(L, 3);
- HANDLE hIcon = (HANDLE)lua_touserdata(L, 4);
- HGENMENU res = Menu_CreateRoot(MO_CONTACT, ptrT(Utf8DecodeT(name)), position, hIcon);
lua_pushlightuserdata(L, res);
return 1;
@@ -82,9 +67,7 @@ static int clist_AddTrayMenuItem(lua_State *L) static luaL_Reg clistApi[] =
{
{ "AddMainMenuItem", clist_AddMainMenuItem },
- { "CreateMainMenuRoot", clist_CreateMainMenuRoot },
{ "AddContactMenuItem", clist_AddContactMenuItem },
- { "CreateContactMenuRoot", clist_CreateContactMenuRoot },
{ "AddTrayMenuItem", clist_AddTrayMenuItem },
{ NULL, NULL }
diff --git a/plugins/MirLua/src/m_hotkeys.cpp b/plugins/MirLua/src/m_hotkeys.cpp index 030107ebb6..9cd4ad3aa7 100644 --- a/plugins/MirLua/src/m_hotkeys.cpp +++ b/plugins/MirLua/src/m_hotkeys.cpp @@ -36,7 +36,7 @@ void MakeHotkey(lua_State *L, HOTKEYDESC &hk) lua_pop(L, 1);
}
-static int lua_Register(lua_State *L)
+static int hotkeys_Register(lua_State *L)
{
if (lua_type(L, 1) != LUA_TTABLE)
{
@@ -46,25 +46,47 @@ static int lua_Register(lua_State *L) HOTKEYDESC hk;
MakeHotkey(L, hk);
- INT_PTR res = ::CallService("CoreHotkeys/Register", (WPARAM)hLangpack, (LPARAM)&hk);
+
+ INT_PTR res = ::CallService("CoreHotkeys/Register", (WPARAM)g_mLua->GetHLangpack(), (LPARAM)&hk);
lua_pushboolean(L, res);
return 1;
}
-static int lua_Unregister(lua_State *L)
+static int hotkeys_Unregister(lua_State *L)
{
const char *name = luaL_checkstring(L, 1);
- ::CallService(MS_HOTKEY_UNREGISTER, 0, (LPARAM)name);
+ CallService(MS_HOTKEY_UNREGISTER, 0, (LPARAM)name);
return 0;
}
-static int lua_MakeHotkey(lua_State *L)
+static const char *mods[] = { "shift", "ctrl", "alt", "ext", NULL };
+
+static int hotkeys_MakeHotkey(lua_State *L)
{
- int mod = luaL_checkinteger(L, 1);
- int vk = luaL_checkinteger(L, 2);
+ int mod = 0;
+ switch (lua_type(L, 1))
+ {
+ case LUA_TNUMBER:
+ mod = luaL_checkinteger(L, 1);
+ break;
+ case LUA_TSTRING:
+ mod = (1 << (luaL_checkoption(L, 1, NULL, mods) - 1));
+ break;
+ case LUA_TTABLE:
+ lua_pushnil(L);
+ while (lua_next(L, 1) != 0)
+ {
+ mod |= (1 << (luaL_checkoption(L, -1, NULL, mods) - 1));
+ lua_pop(L, 1);
+ }
+ break;
+ default:
+ luaL_argerror(L, 1, luaL_typename(L, 1));
+ }
+ int vk = luaL_checknumber(L, 2);
WORD res = HOTKEYCODE(mod, vk);
lua_pushinteger(L, res);
@@ -74,9 +96,9 @@ static int lua_MakeHotkey(lua_State *L) static luaL_Reg hotkeysApi[] =
{
- { "MakeHotkey", lua_MakeHotkey },
- { "Register", lua_Register },
- { "Unregister", lua_Unregister },
+ { "MakeHotkey", hotkeys_MakeHotkey },
+ { "Register", hotkeys_Register },
+ { "Unregister", hotkeys_Unregister },
{ NULL, NULL }
};
diff --git a/plugins/MirLua/src/mlua_module_loader.cpp b/plugins/MirLua/src/mlua_module_loader.cpp index 426f7bd9e6..063d554367 100644 --- a/plugins/MirLua/src/mlua_module_loader.cpp +++ b/plugins/MirLua/src/mlua_module_loader.cpp @@ -7,16 +7,11 @@ CLuaModuleLoader::CLuaModuleLoader(lua_State *L) : L(L) void CLuaModuleLoader::Load(const char *name, lua_CFunction loader)
{
luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED");
- lua_getfield(L, -1, name);
- if (lua_toboolean(L, -1))
- Log("Module %s will be replaced with new one");
- lua_pop(L, 1);
lua_pushcfunction(L, loader);
lua_pushstring(L, name);
luaM_pcall(L, 1, 1);
lua_setfield(L, -2, name);
lua_pop(L, 1);
- lua_pop(L, 1);
}
void CLuaModuleLoader::Preload(const char *name, lua_CFunction loader)
diff --git a/plugins/MirLua/src/mlua_script.cpp b/plugins/MirLua/src/mlua_script.cpp index 3d99429ec2..ae44fc4e6e 100644 --- a/plugins/MirLua/src/mlua_script.cpp +++ b/plugins/MirLua/src/mlua_script.cpp @@ -8,7 +8,7 @@ CMLuaScript::CMLuaScript(lua_State *L, const TCHAR *path) fileName = _tcsrchr(filePath, '\\') + 1;
TCHAR *dot = _tcsrchr(fileName, '.');
- size_t length = mir_tstrlen(fileName) - mir_tstrlen(dot);
+ size_t length = mir_tstrlen(fileName) - mir_tstrlen(dot) + 1;
ptrT name((TCHAR*)mir_calloc(sizeof(TCHAR) * (length + 1)));
mir_tstrncpy(name, fileName, length);
@@ -57,12 +57,13 @@ bool CMLuaScript::Load() luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED");
lua_getfield(L, -1, moduleName);
- if (lua_toboolean(L, -1))
- Log("Module %s will be replaced with new one");
- lua_pop(L, 1);
- lua_pushvalue(L, -2);
- lua_setfield(L, -2, moduleName);
- lua_pop(L, 1);
+ if (!lua_toboolean(L, -1))
+ {
+ lua_pop(L, 1);
+ lua_pushvalue(L, -2);
+ lua_setfield(L, -2, moduleName);
+ }
+ lua_remove(L, -2);
if (!lua_istable(L, -1))
return true;
|