diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-07-18 19:43:12 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-07-18 19:43:12 +0000 |
commit | 059a7ea5928d49d81ed1d884e59c60f152983539 (patch) | |
tree | 8d4065bfa11f5cba5714d131842108c6a1286922 /plugins/MirLua/src/mlua_script_loader.cpp | |
parent | 952154728cfc9a390f9f7b2e3326ea32d76e0003 (diff) |
MirLua:
- removed OnScriptLoaded/OnScriptUnload
- removed second script path
- module loading and options refactoring
- version bump
git-svn-id: http://svn.miranda-ng.org/main/trunk@14587 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/src/mlua_script_loader.cpp')
-rw-r--r-- | plugins/MirLua/src/mlua_script_loader.cpp | 71 |
1 files changed, 11 insertions, 60 deletions
diff --git a/plugins/MirLua/src/mlua_script_loader.cpp b/plugins/MirLua/src/mlua_script_loader.cpp index 3a25345c93..bdcca3c9f4 100644 --- a/plugins/MirLua/src/mlua_script_loader.cpp +++ b/plugins/MirLua/src/mlua_script_loader.cpp @@ -18,35 +18,20 @@ void CLuaScriptLoader::RegisterScriptsFolder(const char *path) lua_pop(L, 1);
}
-void CLuaScriptLoader::LoadScript(const TCHAR *path)
+void CLuaScriptLoader::LoadScript(const TCHAR *path, int iGroup)
{
-
- if (luaL_loadfile(L, T2Utf(path)))
- {
- CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1));
- return;
- }
-
- if (lua_pcall(L, 0, 1, 0))
- {
- CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1));
- return;
- }
-
- TCHAR buf[4096];
- mir_sntprintf(buf, _T("%s:OK"), path);
- CallService(MS_NETLIB_LOGW, (WPARAM)hNetlib, (LPARAM)buf);
+ CMLuaScript *script = new CMLuaScript(L, path, 0);
+ g_mLua->Scripts.insert(script);
- if (lua_istable(L, -1))
+ if (script->Load())
{
- lua_pushliteral(L, "Load");
- lua_gettable(L, -2);
- if (lua_isfunction(L, -1) && lua_pcall(L, 0, 0, 0))
- CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1));
+ TCHAR buf[4096];
+ mir_sntprintf(buf, _T("%s:OK"), path);
+ CallService(MS_NETLIB_LOGW, (WPARAM)hNetlib, (LPARAM)buf);
}
}
-void CLuaScriptLoader::LoadScripts(const TCHAR *scriptDir)
+void CLuaScriptLoader::LoadScripts(const TCHAR *scriptDir, int iGroup)
{
TCHAR buf[4096];
mir_sntprintf(buf, _T("Loading scripts from %s"), scriptDir);
@@ -70,52 +55,18 @@ void CLuaScriptLoader::LoadScripts(const TCHAR *scriptDir) mir_sntprintf(fullPath, _T("%s\\%s"), scriptDir, fd.cFileName);
PathToRelativeT(fullPath, path);
if (db_get_b(NULL, MODULE, _T2A(fd.cFileName), 1))
- LoadScript(fullPath);
+ LoadScript(fullPath, iGroup);
}
} while (FindNextFile(hFind, &fd));
FindClose(hFind);
}
}
-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];
CLuaScriptLoader loader(L);
- FoldersGetCustomPathT(g_hCommonFolderPath, scriptDir, _countof(scriptDir), VARST(COMMON_SCRIPTS_PATHT));
- loader.LoadScripts(scriptDir);
-
- 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);
+ FoldersGetCustomPathT(g_hCommonScriptFolder, scriptDir, _countof(scriptDir), VARST(COMMON_SCRIPTS_PATHT));
+ loader.LoadScripts(scriptDir, 0);
}
\ No newline at end of file |