From a5983f7d5999e6488e4b21fb17fa1d7702ecfb03 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Tue, 14 Jul 2015 11:37:39 +0000 Subject: MirLua: added single script reloading git-svn-id: http://svn.miranda-ng.org/main/trunk@14557 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/res/reload.ico | Bin 0 -> 2550 bytes plugins/MirLua/res/resource.rc | 1 + plugins/MirLua/src/mlua.cpp | 5 +++++ plugins/MirLua/src/mlua.h | 1 + plugins/MirLua/src/mlua_options.cpp | 18 +++++++++++++++--- plugins/MirLua/src/mlua_script_loader.cpp | 30 ++++++++++++++++++++++++++++++ plugins/MirLua/src/mlua_script_loader.h | 5 +++++ plugins/MirLua/src/resource.h | 5 +++-- plugins/MirLua/src/version.h | 2 +- 9 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 plugins/MirLua/res/reload.ico (limited to 'plugins/MirLua') diff --git a/plugins/MirLua/res/reload.ico b/plugins/MirLua/res/reload.ico new file mode 100644 index 0000000000..b5070a2bfe Binary files /dev/null and b/plugins/MirLua/res/reload.ico differ diff --git a/plugins/MirLua/res/resource.rc b/plugins/MirLua/res/resource.rc index 460294cf4d..af75d696b7 100644 --- a/plugins/MirLua/res/resource.rc +++ b/plugins/MirLua/res/resource.rc @@ -64,6 +64,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL // remains consistent on all systems. IDI_ICON ICON "icon.ico" IDI_OPEN ICON "open.ico" +IDI_RELOAD ICON "reload.ico" ///////////////////////////////////////////////////////////////////////////// // diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index 6ce1b2d3f0..2fabce2740 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -75,6 +75,11 @@ void CMLua::Reload() Load(); } +void CMLua::Reload(const TCHAR* path) +{ + CLuaScriptLoader::Reload(g_mLua->L, path); +} + void CMLua::KillModuleEventHooks() { while (Hooks.getCount()) diff --git a/plugins/MirLua/src/mlua.h b/plugins/MirLua/src/mlua.h index 5d771d8ea9..28fcff5b45 100644 --- a/plugins/MirLua/src/mlua.h +++ b/plugins/MirLua/src/mlua.h @@ -34,6 +34,7 @@ public: ~CMLua(); void Reload(); + void Reload(const TCHAR* path); static int OnScriptLoaded(lua_State *L); static int OnScriptUnload(lua_State *L); diff --git a/plugins/MirLua/src/mlua_options.cpp b/plugins/MirLua/src/mlua_options.cpp index 9c59e246e3..caca892e48 100644 --- a/plugins/MirLua/src/mlua_options.cpp +++ b/plugins/MirLua/src/mlua_options.cpp @@ -65,6 +65,7 @@ void CLuaOptions::LoadScripts(const TCHAR *scriptDir, int iGroup) if (db_get_b(NULL, MODULE, _T2A(fd.cFileName), 1)) m_scripts.SetCheckState(iItem, TRUE); m_scripts.SetItem(iItem, 1, _T(""), 0); + m_scripts.SetItem(iItem, 2, _T(""), 1); } } while (FindNextFile(hFind, &fd)); FindClose(hFind); @@ -93,12 +94,13 @@ void CLuaOptions::OnInitDialog() m_scripts.SetExtendedListViewStyle(LVS_EX_SUBITEMIMAGES | LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES | LVS_EX_INFOTIP); m_scripts.EnableGroupView(TRUE); - m_scripts.AddColumn(0, _T("Script"), 440); + m_scripts.AddColumn(0, _T("Script"), 420); m_scripts.AddColumn(1, NULL, 32 - GetSystemMetrics(SM_CXVSCROLL)); + m_scripts.AddColumn(2, NULL, 32 - GetSystemMetrics(SM_CXVSCROLL)); HIMAGELIST hImageList = m_scripts.CreateImageList(LVSIL_SMALL); - HICON icon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_OPEN)); - ImageList_AddIcon(hImageList, icon); + ImageList_AddIcon(hImageList, LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_OPEN))); + ImageList_AddIcon(hImageList, LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_RELOAD))); LoadScripts(); @@ -161,6 +163,16 @@ void CLuaOptions::OnScriptListClick(CCtrlListView::TEventInfo *evt) FoldersGetCustomPathT(g_hCustomFolderPath, path, _countof(path), VARST(CUSTOM_SCRIPTS_PATHT)); ShellExecute(m_hwnd, NULL, lvi.pszText, NULL, path, SW_SHOWNORMAL); } + else if (lvi.iSubItem == 2) + { + TCHAR path[MAX_PATH]; + if (lvi.iGroupId == 0) + FoldersGetCustomPathT(g_hCommonFolderPath, path, _countof(path), VARST(COMMON_SCRIPTS_PATHT)); + else + FoldersGetCustomPathT(g_hCustomFolderPath, path, _countof(path), VARST(CUSTOM_SCRIPTS_PATHT)); + mir_sntprintf(path, _T("%s\\%s"), path, lvi.pszText); + g_mLua->Reload(path); + } mir_free(lvi.pszText); } diff --git a/plugins/MirLua/src/mlua_script_loader.cpp b/plugins/MirLua/src/mlua_script_loader.cpp index c54c489d8b..7150ebdc48 100644 --- a/plugins/MirLua/src/mlua_script_loader.cpp +++ b/plugins/MirLua/src/mlua_script_loader.cpp @@ -63,6 +63,30 @@ void CLuaScriptLoader::LoadScripts(const TCHAR *scriptDir) } } +void CLuaScriptLoader::UnloadScript(const TCHAR *path) +{ + const TCHAR* p = _tcsrchr(path, '\\') + 1; + size_t length = mir_tstrlen(p) - 3; + + ptrT name((TCHAR*)mir_alloc(sizeof(TCHAR) * length)); + mir_tstrncpy(name, p, length); + + T2Utf moduleName(name); + + luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_pushnil(L); + lua_setfield(L, -2, moduleName); + lua_pop(L, 1); + lua_pushnil(L); + lua_setglobal(L, moduleName); +} + +void CLuaScriptLoader::ReloadScript(const TCHAR *path) +{ + UnloadScript(path); + LoadScript(path); +} + void CLuaScriptLoader::Load(lua_State *L) { TCHAR scriptDir[MAX_PATH]; @@ -73,4 +97,10 @@ void CLuaScriptLoader::Load(lua_State *L) FoldersGetCustomPathT(g_hCustomFolderPath, scriptDir, _countof(scriptDir), VARST(CUSTOM_SCRIPTS_PATHT)); loader.LoadScripts(scriptDir); +} + +void CLuaScriptLoader::Reload(lua_State *L, const TCHAR *path) +{ + CLuaScriptLoader loader(L); + loader.ReloadScript(path); } \ No newline at end of file diff --git a/plugins/MirLua/src/mlua_script_loader.h b/plugins/MirLua/src/mlua_script_loader.h index fe15bbc08b..0d229053d3 100644 --- a/plugins/MirLua/src/mlua_script_loader.h +++ b/plugins/MirLua/src/mlua_script_loader.h @@ -14,8 +14,13 @@ private: void LoadScript(const TCHAR *path); void LoadScripts(const TCHAR *scriptDir); + void UnloadScript(const TCHAR *path); + + void ReloadScript(const TCHAR *path); + public: static void Load(lua_State *L); + static void Reload(lua_State *L, const TCHAR* path); }; #endif //_LUA_SCRIPT_LOADER_H_ \ No newline at end of file diff --git a/plugins/MirLua/src/resource.h b/plugins/MirLua/src/resource.h index 6e93d57ad5..d94ef6d1b1 100644 --- a/plugins/MirLua/src/resource.h +++ b/plugins/MirLua/src/resource.h @@ -1,10 +1,11 @@ //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. -// Used by d:\Projects\MirandaNG\plugins\MirLua\res\resource.rc +// Used by D:\Projects\MirandaNG\plugins\MirLua\res\resource.rc // #define IDI_ICON 100 #define IDI_OPEN 105 #define IDD_OPTIONS 106 +#define IDI_RELOAD 107 #define IDC_SCRIPTS 1011 #define IDC_RELOAD 1012 @@ -12,7 +13,7 @@ // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 106 +#define _APS_NEXT_RESOURCE_VALUE 107 #define _APS_NEXT_COMMAND_VALUE 40001 #define _APS_NEXT_CONTROL_VALUE 1013 #define _APS_NEXT_SYMED_VALUE 101 diff --git a/plugins/MirLua/src/version.h b/plugins/MirLua/src/version.h index a3ff129847..3a38e21e9f 100644 --- a/plugins/MirLua/src/version.h +++ b/plugins/MirLua/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 11 #define __RELEASE_NUM 3 -#define __BUILD_NUM 3 +#define __BUILD_NUM 4 #include -- cgit v1.2.3