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/src/mlua_script_loader.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'plugins/MirLua/src/mlua_script_loader.cpp') 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 -- cgit v1.2.3