summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/script_loader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/MirLua/src/script_loader.cpp')
-rw-r--r--plugins/MirLua/src/script_loader.cpp44
1 files changed, 35 insertions, 9 deletions
diff --git a/plugins/MirLua/src/script_loader.cpp b/plugins/MirLua/src/script_loader.cpp
index 998fffc376..cf9c194ec1 100644
--- a/plugins/MirLua/src/script_loader.cpp
+++ b/plugins/MirLua/src/script_loader.cpp
@@ -15,31 +15,44 @@ void CMLuaScriptLoader::SetPaths()
lua_getglobal(L, LUA_LOADLIBNAME);
FoldersGetCustomPathT(g_hCLibsFolder, path, _countof(path), VARSW(MIRLUA_PATHT));
- lua_pushfstring(L, "%s\\?.dll", T2Utf(path));
+ lua_pushfstring(L, "%s\\?.%s", T2Utf(path), _T2A(LUACLIBSCRIPTEXT));
lua_setfield(L, -2, "cpath");
FoldersGetCustomPathT(g_hScriptsFolder, path, _countof(path), VARSW(MIRLUA_PATHT));
- lua_pushfstring(L, "%s\\?.lua", T2Utf(path));
+ lua_pushfstring(L, "%s\\?.%s", T2Utf(path), _T2A(LUATEXTSCRIPTEXT));
+ lua_setfield(L, -2, "path");
+
+ lua_pushfstring(L, "%s\\?.%s", T2Utf(path), _T2A(LUAPRECSCRIPTEXT));
lua_setfield(L, -2, "path");
lua_pop(L, 1);
}
-void CMLuaScriptLoader::LoadScript(const wchar_t *scriptDir, const wchar_t *file)
+void CMLuaScriptLoader::LoadScript(const wchar_t *scriptDir, const wchar_t *fileName)
{
- wchar_t fullPath[MAX_PATH], path[MAX_PATH];
- mir_snwprintf(fullPath, L"%s\\%s", scriptDir, file);
+ wchar_t fullPath[MAX_PATH];
+ wchar_t path[MAX_PATH];
+ mir_snwprintf(fullPath, L"%s\\%s", scriptDir, fileName);
PathToRelativeW(fullPath, path);
CMLuaScript *script = new CMLuaScript(L, path);
- g_plugin.Scripts.insert(script);
+
+ const CMLuaScript *found = g_plugin.Scripts.find(script);
+ if (found != nullptr) {
+ Log(L"%s:PASS", script->GetFilePath());
+ delete script;
+ return;
+ }
if (!script->IsEnabled()) {
Log(L"%s:PASS", path);
return;
}
- script->Load();
+ g_plugin.Scripts.insert(script);
+
+ if (script->Load())
+ Log(L"%s:OK", path);
}
void CMLuaScriptLoader::LoadScripts()
@@ -51,10 +64,11 @@ void CMLuaScriptLoader::LoadScripts()
Log(L"Loading scripts from %s", scriptDir);
+ WIN32_FIND_DATA fd;
wchar_t searchMask[MAX_PATH];
- mir_snwprintf(searchMask, L"%s\\%s", scriptDir, L"*.lua");
- WIN32_FIND_DATA fd;
+ // load compiled scripts
+ mir_snwprintf(searchMask, L"%s\\*.%s", scriptDir, LUAPRECSCRIPTEXT);
HANDLE hFind = FindFirstFile(searchMask, &fd);
if (hFind != INVALID_HANDLE_VALUE) {
do {
@@ -64,6 +78,18 @@ void CMLuaScriptLoader::LoadScripts()
} while (FindNextFile(hFind, &fd));
FindClose(hFind);
}
+
+ // load text scripts
+ mir_snwprintf(searchMask, L"%s\\*.%s", scriptDir, LUATEXTSCRIPTEXT);
+ hFind = FindFirstFile(searchMask, &fd);
+ if (hFind != INVALID_HANDLE_VALUE) {
+ do {
+ if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ continue;
+ LoadScript(scriptDir, fd.cFileName);
+ } while (FindNextFile(hFind, &fd));
+ FindClose(hFind);
+ }
}
void CMLuaScriptLoader::Load(lua_State *L)