summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/mlua_script_loader.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-07-14 11:37:39 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-07-14 11:37:39 +0000
commita5983f7d5999e6488e4b21fb17fa1d7702ecfb03 (patch)
tree1efe77345af957e40fc9bdc90b3824903708a2fb /plugins/MirLua/src/mlua_script_loader.cpp
parente13b6b468a19ab498231c338bdda07f7028fb1df (diff)
MirLua: added single script reloading
git-svn-id: http://svn.miranda-ng.org/main/trunk@14557 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/src/mlua_script_loader.cpp')
-rw-r--r--plugins/MirLua/src/mlua_script_loader.cpp30
1 files changed, 30 insertions, 0 deletions
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