diff options
Diffstat (limited to 'plugins/MirLua/src')
-rw-r--r-- | plugins/MirLua/src/environment.h | 2 | ||||
-rw-r--r-- | plugins/MirLua/src/icons.cpp | 11 | ||||
-rw-r--r-- | plugins/MirLua/src/lua.cpp | 37 | ||||
-rw-r--r-- | plugins/MirLua/src/lua.h | 17 | ||||
-rw-r--r-- | plugins/MirLua/src/options.cpp | 39 | ||||
-rw-r--r-- | plugins/MirLua/src/plugin.cpp | 69 | ||||
-rw-r--r-- | plugins/MirLua/src/plugin.h | 2 | ||||
-rw-r--r-- | plugins/MirLua/src/resource.h | 7 | ||||
-rw-r--r-- | plugins/MirLua/src/script.cpp | 95 | ||||
-rw-r--r-- | plugins/MirLua/src/script.h | 33 | ||||
-rw-r--r-- | plugins/MirLua/src/script_loader.cpp | 44 | ||||
-rw-r--r-- | plugins/MirLua/src/script_loader.h | 2 | ||||
-rw-r--r-- | plugins/MirLua/src/stdafx.h | 5 | ||||
-rw-r--r-- | plugins/MirLua/src/version.h | 4 |
14 files changed, 270 insertions, 97 deletions
diff --git a/plugins/MirLua/src/environment.h b/plugins/MirLua/src/environment.h index 1c35c2073d..1f05f1f986 100644 --- a/plugins/MirLua/src/environment.h +++ b/plugins/MirLua/src/environment.h @@ -9,7 +9,7 @@ private: void CreateEnvironmentTable(); public: - lua_State * L; + lua_State *L; CMLuaEnvironment(lua_State *L); virtual ~CMLuaEnvironment(); diff --git a/plugins/MirLua/src/icons.cpp b/plugins/MirLua/src/icons.cpp index 5d5feacb3e..52940084f3 100644 --- a/plugins/MirLua/src/icons.cpp +++ b/plugins/MirLua/src/icons.cpp @@ -2,11 +2,12 @@ static IconItem Icons[] = { - { LPGEN("Script"), "script", IDI_SCRIPT }, - { LPGEN("Loaded"), "loaded", IDI_LOADED }, - { LPGEN("Failed"), "failed", IDI_FAILED }, - { LPGEN("Open"), "open", IDI_OPEN }, - { LPGEN("Reload"), "reload", IDI_RELOAD }, + { LPGEN("Script"), "script", IDI_SCRIPT }, + { LPGEN("Loaded"), "loaded", IDI_LOADED }, + { LPGEN("Failed"), "failed", IDI_FAILED }, + { LPGEN("Open"), "open", IDI_OPEN }, + { LPGEN("Reload"), "reload", IDI_RELOAD }, + { LPGEN("Compile"), "compile", IDI_COMPILE }, }; void LoadIcons() diff --git a/plugins/MirLua/src/lua.cpp b/plugins/MirLua/src/lua.cpp new file mode 100644 index 0000000000..dd2fd64606 --- /dev/null +++ b/plugins/MirLua/src/lua.cpp @@ -0,0 +1,37 @@ +#include "stdafx.h" + +CMLua::CMLua() : L(nullptr) +{ + //MUUID muidLast = MIID_LAST; + //g_hMLuaLangpack = GetPluginLangId(muidLast, 0); +} + +CMLua::~CMLua() +{ + Log("Unloading lua engine"); + + KillModuleIcons(g_hMLuaLangpack); + KillModuleSounds(g_hMLuaLangpack); + KillModuleMenus(g_hMLuaLangpack); + KillModuleHotkeys(g_hMLuaLangpack); + + KillObjectEventHooks(L); + KillObjectServices(L); + + lua_close(L); +} + +lua_State* CMLua::GetState() +{ + return L; +} + +void CMLua::Load() +{ + Log("Loading lua engine"); + L = luaL_newstate(); + Log("Loading standard modules"); + luaL_openlibs(L); + + lua_atpanic(L, luaM_atpanic); +} diff --git a/plugins/MirLua/src/lua.h b/plugins/MirLua/src/lua.h new file mode 100644 index 0000000000..5d64c65ff6 --- /dev/null +++ b/plugins/MirLua/src/lua.h @@ -0,0 +1,17 @@ +#pragma once + +class CMLua +{ + friend class CMPlugin; + +private: + lua_State *L; + +public: + CMLua(); + ~CMLua(); + + lua_State* GetState(); + + void Load(); +}; diff --git a/plugins/MirLua/src/options.cpp b/plugins/MirLua/src/options.cpp index 8f7ed53a87..f0a7827a93 100644 --- a/plugins/MirLua/src/options.cpp +++ b/plugins/MirLua/src/options.cpp @@ -15,15 +15,29 @@ CMLuaOptions::CMLuaOptions() m_reload.OnClick = Callback(this, &CMLuaOptions::OnReload);
}
+static int ScriptStatusToIcon(ScriptStatus status)
+{
+ switch (status)
+ {
+ case ScriptStatus::None:
+ return -1;
+ case ScriptStatus::Loaded:
+ return 0;
+ case ScriptStatus::Failed:
+ return 1;
+ }
+}
+
void CMLuaOptions::LoadScripts()
{
- for (auto &script : g_plugin.Scripts) {
- wchar_t *fileName = NEWWSTR_ALLOCA(script->GetFileName());
- int iIcon = script->GetStatus() - 1;
- int iItem = m_scripts.AddItem(fileName, iIcon, (LPARAM)script);
+ for (auto &script : g_plugin.Scripts.rev_iter()) {
+ int iIcon = ScriptStatusToIcon(script->GetStatus());
+ int iItem = m_scripts.AddItem(script->GetName(), iIcon, (LPARAM)script);
m_scripts.SetCheckState(iItem, script->IsEnabled());
m_scripts.SetItem(iItem, 1, TranslateT("Open"), 2);
m_scripts.SetItem(iItem, 2, TranslateT("Reload"), 3);
+ if (!script->IsBinary())
+ m_scripts.SetItem(iItem, 3, TranslateT("Compile"), 4);
}
}
@@ -38,10 +52,11 @@ void CMLuaOptions::OnInitDialog() ImageList_AddIcon(hImageList, GetIcon(IDI_FAILED));
ImageList_AddIcon(hImageList, GetIcon(IDI_OPEN));
ImageList_AddIcon(hImageList, GetIcon(IDI_RELOAD));
+ ImageList_AddIcon(hImageList, GetIcon(IDI_COMPILE));
wchar_t scriptDir[MAX_PATH];
FoldersGetCustomPathT(g_hScriptsFolder, scriptDir, _countof(scriptDir), VARSW(MIRLUA_PATHT));
-
+
wchar_t relativeScriptDir[MAX_PATH];
PathToRelativeW(scriptDir, relativeScriptDir, nullptr);
@@ -51,6 +66,7 @@ void CMLuaOptions::OnInitDialog() m_scripts.AddColumn(0, L"Script", 380);
m_scripts.AddColumn(1, nullptr, 32 - GetSystemMetrics(SM_CXVSCROLL));
m_scripts.AddColumn(2, nullptr, 32 - GetSystemMetrics(SM_CXVSCROLL));
+ m_scripts.AddColumn(3, nullptr, 32 - GetSystemMetrics(SM_CXVSCROLL));
LoadScripts();
@@ -112,7 +128,18 @@ void CMLuaOptions::OnScriptListClick(CCtrlListView::TEventInfo *evt) script->Reload();
lvi.mask = LVIF_IMAGE;
lvi.iSubItem = 0;
- lvi.iImage = script->GetStatus() - 1;
+ lvi.iImage = ScriptStatusToIcon(script->GetStatus());
+ m_scripts.SetItem(&lvi);
+ m_scripts.Update(lvi.iItem);
+ break;
+
+ case 3:
+ if (script->IsBinary())
+ break;
+ script->Compile();
+ lvi.mask = LVIF_IMAGE;
+ lvi.iSubItem = 0;
+ lvi.iImage = ScriptStatusToIcon(script->GetStatus());
m_scripts.SetItem(&lvi);
m_scripts.Update(lvi.iItem);
break;
diff --git a/plugins/MirLua/src/plugin.cpp b/plugins/MirLua/src/plugin.cpp index 9dd1e7c82e..02a849b2dd 100644 --- a/plugins/MirLua/src/plugin.cpp +++ b/plugins/MirLua/src/plugin.cpp @@ -17,10 +17,15 @@ PLUGININFOEX pluginInfoEx = { 0x27d41d81, 0x991f, 0x4dc6,{ 0x87, 0x49, 0xb0, 0x32, 0x1c, 0x87, 0xe6, 0x94 } } }; +static int ScriptsCompare(const CMLuaScript* p1, const CMLuaScript* p2) +{ + return mir_wstrcmpi(p1->GetName(), p2->GetName()); +} + CMPlugin::CMPlugin() : PLUGIN(MODULENAME, pluginInfoEx), - L(nullptr), - Scripts(1) + lua(nullptr), + Scripts(1, ScriptsCompare) { MUUID muidLast = MIID_LAST; g_hMLuaLangpack = GetPluginLangId(muidLast, 0); @@ -34,22 +39,15 @@ CMPlugin::CMPlugin() void CMPlugin::LoadLua() { - Log("Loading lua engine"); - L = luaL_newstate(); - Log("Loading standard modules"); - luaL_openlibs(L); - - lua_atpanic(L, luaM_atpanic); - - CMLuaFunctionLoader::Load(L); - CMLuaModuleLoader::Load(L); - CMLuaScriptLoader::Load(L); + lua = new CMLua(); + lua->Load(); + CMLuaFunctionLoader::Load(lua->L); + CMLuaModuleLoader::Load(lua->L); + CMLuaScriptLoader::Load(lua->L); } void CMPlugin::UnloadLua() { - Log("Unloading lua engine"); - Scripts.destroy(); KillModuleIcons(g_hMLuaLangpack); @@ -57,10 +55,13 @@ void CMPlugin::UnloadLua() KillModuleMenus(g_hMLuaLangpack); KillModuleHotkeys(g_hMLuaLangpack); - KillObjectEventHooks(L); - KillObjectServices(L); + KillObjectEventHooks(lua->L); + KillObjectServices(lua->L); - lua_close(L); + if (lua != nullptr) { + delete lua; + lua = nullptr; + } } void CMPlugin::Reload() @@ -126,17 +127,17 @@ INT_PTR CMPlugin::Call(WPARAM wParam, LPARAM lParam) const wchar_t *module = (const wchar_t*)wParam; const wchar_t *function = (const wchar_t*)lParam; - lua_pushstring(L, ptrA(mir_utf8encodeW(module))); - lua_pushstring(L, ptrA(mir_utf8encodeW(function))); + lua_pushstring(lua->L, ptrA(mir_utf8encodeW(module))); + lua_pushstring(lua->L, ptrA(mir_utf8encodeW(function))); - lua_newtable(L); - lua_pushcclosure(L, mlua_call, 1); + lua_newtable(lua->L); + lua_pushcclosure(lua->L, mlua_call, 1); - CMLuaEnvironment env(L); + CMLuaEnvironment env(lua->L); env.Load(); - wchar_t *result = mir_utf8decodeW(lua_tostring(L, -1)); - lua_pop(L, 1); + wchar_t *result = mir_utf8decodeW(lua_tostring(lua->L, -1)); + lua_pop(lua->L, 1); return (INT_PTR)result; } @@ -145,16 +146,16 @@ INT_PTR CMPlugin::Eval(WPARAM, LPARAM lParam) { const wchar_t *script = (const wchar_t*)lParam; - if (luaL_loadstring(L, ptrA(mir_utf8encodeW(script)))) { - ReportError(L); + if (luaL_loadstring(lua->L, ptrA(mir_utf8encodeW(script)))) { + ReportError(lua->L); return NULL; } - CMLuaEnvironment env(L); + CMLuaEnvironment env(lua->L); env.Load(); - wchar_t *result = mir_utf8decodeW(lua_tostring(L, -1)); - lua_pop(L, 1); + wchar_t *result = mir_utf8decodeW(lua_tostring(lua->L, -1)); + lua_pop(lua->L, 1); return (INT_PTR)result; } @@ -163,16 +164,16 @@ INT_PTR CMPlugin::Exec(WPARAM, LPARAM lParam) { const wchar_t *path = (const wchar_t*)lParam; - if (luaL_loadfile(L, ptrA(mir_utf8encodeW(path)))) { - ReportError(L); + if (luaL_loadfile(lua->L, ptrA(mir_utf8encodeW(path)))) { + ReportError(lua->L); return NULL; } - CMLuaEnvironment env(L); + CMLuaEnvironment env(lua->L); env.Load(); - wchar_t *result = mir_utf8decodeW(lua_tostring(L, -1)); - lua_pop(L, 1); + wchar_t *result = mir_utf8decodeW(lua_tostring(lua->L, -1)); + lua_pop(lua->L, 1); return (INT_PTR)result; } diff --git a/plugins/MirLua/src/plugin.h b/plugins/MirLua/src/plugin.h index 6339b36353..ac8b89142e 100644 --- a/plugins/MirLua/src/plugin.h +++ b/plugins/MirLua/src/plugin.h @@ -5,7 +5,7 @@ struct CMPlugin : public PLUGIN<CMPlugin> friend class CMLuaOptions; private: - lua_State *L; + CMLua *lua; void LoadLua(); void UnloadLua(); diff --git a/plugins/MirLua/src/resource.h b/plugins/MirLua/src/resource.h index b83d89d368..6085769a72 100644 --- a/plugins/MirLua/src/resource.h +++ b/plugins/MirLua/src/resource.h @@ -1,6 +1,6 @@ //{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
-// Used by D:\Projects\MirandaNG\plugins\MirLua\res\resource.rc
+// Used by D:\Projects\miranda-ng\miranda-ng\plugins\MirLua\res\resource.rc
//
#define IDI_ICON 100
#define IDI_SCRIPT 100
@@ -10,6 +10,7 @@ #define IDI_RELOAD 108
#define IDI_FAILED 109
#define IDI_LOADED 110
+#define IDI_COMPILE 111
#define IDC_SCRIPTS 1011
#define IDC_RELOAD 1012
#define IDC_POPUPONERROR 1013
@@ -19,9 +20,9 @@ //
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 111
+#define _APS_NEXT_RESOURCE_VALUE 112
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1016
+#define _APS_NEXT_CONTROL_VALUE 1015
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/plugins/MirLua/src/script.cpp b/plugins/MirLua/src/script.cpp index 50e061b59c..dc379c907c 100644 --- a/plugins/MirLua/src/script.cpp +++ b/plugins/MirLua/src/script.cpp @@ -3,33 +3,38 @@ #define MT_SCRIPT "SCRIPT"
CMLuaScript::CMLuaScript(lua_State *L, const wchar_t *path)
- : CMLuaEnvironment(L), status(None), unloadRef(LUA_NOREF)
+ : CMLuaEnvironment(L), isBinary(false),
+ status(ScriptStatus::None), unloadRef(LUA_NOREF)
{
mir_wstrcpy(filePath, path);
- fileName = wcsrchr(filePath, L'\\') + 1;
+ const wchar_t *fileName = wcsrchr(filePath, L'\\') + 1;
const wchar_t *dot = wcsrchr(fileName, '.');
size_t length = mir_wstrlen(fileName) - mir_wstrlen(dot) + 1;
- ptrW name((wchar_t*)mir_calloc(sizeof(wchar_t) * (length + 1)));
- mir_wstrncpy(name, fileName, length);
+ scriptName = (wchar_t*)mir_calloc(sizeof(wchar_t) * (length + 1));
+ mir_wstrncpy(scriptName, fileName, length);
- m_szModuleName = mir_utf8encodeW(name);
+ m_szModuleName = mir_utf8encodeW(scriptName);
+
+ isBinary = mir_wstrcmpi(dot + 1, LUAPRECSCRIPTEXT) == 0;
}
CMLuaScript::CMLuaScript(const CMLuaScript &script)
- : CMLuaEnvironment(script.L), status(None), unloadRef(LUA_NOREF)
+ : CMLuaEnvironment(script.L), isBinary(script.isBinary),
+ status(ScriptStatus::None), unloadRef(LUA_NOREF)
{
mir_wstrcpy(filePath, script.filePath);
- fileName = mir_wstrdup(script.fileName);
+ scriptName = mir_wstrdup(script.scriptName);
m_szModuleName = mir_strdup(script.m_szModuleName);
}
CMLuaScript::~CMLuaScript()
{
Unload();
- mir_free((char*)m_szModuleName);
+ mir_free((void*)m_szModuleName);
+ mir_free((void*)scriptName);
}
const wchar_t* CMLuaScript::GetFilePath() const
@@ -37,34 +42,39 @@ const wchar_t* CMLuaScript::GetFilePath() const return filePath;
}
-const wchar_t* CMLuaScript::GetFileName() const
+const wchar_t* CMLuaScript::GetName() const
+{
+ return scriptName;
+}
+
+bool CMLuaScript::IsBinary() const
{
- return fileName;
+ return isBinary;
}
-bool CMLuaScript::IsEnabled()
+bool CMLuaScript::IsEnabled() const
{
- return db_get_b(NULL, MODULENAME, _T2A(fileName), 1);
+ return db_get_b(NULL, MODULENAME, _T2A(scriptName), 1);
}
void CMLuaScript::Enable()
{
- db_unset(NULL, MODULENAME, _T2A(fileName));
+ db_unset(NULL, MODULENAME, _T2A(scriptName));
}
void CMLuaScript::Disable()
{
- db_set_b(NULL, MODULENAME, _T2A(fileName), 0);
+ db_set_b(NULL, MODULENAME, _T2A(scriptName), 0);
}
-CMLuaScript::Status CMLuaScript::GetStatus() const
+ScriptStatus CMLuaScript::GetStatus() const
{
return status;
}
int CMLuaScript::Load()
{
- status = Failed;
+ status = ScriptStatus::Failed;
if (luaL_loadfile(L, _T2A(filePath))) {
ReportError(L);
@@ -76,8 +86,7 @@ int CMLuaScript::Load() return false;
}
- status = Loaded;
- Log(L"%s:OK", filePath);
+ status = ScriptStatus::Loaded;
if (lua_isnoneornil(L, -1))
return true;
@@ -116,13 +125,13 @@ int CMLuaScript::Load() int CMLuaScript::Unload()
{
- if (status == Loaded) {
+ if (status == ScriptStatus::Loaded) {
lua_rawgeti(L, LUA_REGISTRYINDEX, unloadRef);
if (lua_isfunction(L, -1))
luaM_pcall(L);
lua_pushnil(L);
lua_rawsetp(L, LUA_REGISTRYINDEX, this);
- status = None;
+ status = ScriptStatus::None;
}
luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
@@ -138,3 +147,49 @@ bool CMLuaScript::Reload() Unload();
return Load();
}
+
+static int luc_Writer(lua_State* /*L*/, const void *p, size_t sz, void *u)
+{
+ return (fwrite(p, sz, 1, (FILE*)u) != 1) && (sz != 0);
+}
+
+bool CMLuaScript::Compile()
+{
+ Unload();
+
+ Log(L"Compiling script %s", filePath);
+
+ wchar_t scriptDir[MAX_PATH];
+ FoldersGetCustomPathT(g_hScriptsFolder, scriptDir, _countof(scriptDir), VARSW(MIRLUA_PATHT));
+ wchar_t fullPath[MAX_PATH];
+ mir_snwprintf(fullPath, L"%s\\%s.%s", scriptDir, scriptName, LUAPRECSCRIPTEXT);
+ wchar_t path[MAX_PATH];
+ PathToRelativeW(fullPath, path);
+
+ FILE *file = _wfopen(path, L"wb");
+ if (file == nullptr) {
+ Log(L"Failed to save compiled script to %s", file);
+ return false;
+ }
+
+ if (luaL_loadfile(L, _T2A(filePath))) {
+ ReportError(L);
+ fclose(file);
+ return false;
+ }
+
+ int res = lua_dump(L, luc_Writer, file, 1);
+ if (res != 0) {
+ fclose(file);
+ return false;
+ }
+
+ fclose(file);
+
+ ptrW newPath(mir_wstrdup(filePath));
+ newPath[mir_wstrlen(newPath) - 1] = L'_';
+ MoveFile(filePath, newPath);
+ mir_wstrcpy(filePath, path);
+
+ return Load();
+}
diff --git a/plugins/MirLua/src/script.h b/plugins/MirLua/src/script.h index 2caf88c925..383bac1190 100644 --- a/plugins/MirLua/src/script.h +++ b/plugins/MirLua/src/script.h @@ -1,21 +1,20 @@ #pragma once
-class CMLuaScript : public CMLuaEnvironment
+enum class ScriptStatus
{
-public:
- enum Status
- {
- None,
- Loaded,
- Failed
- };
+ None,
+ Loaded,
+ Failed,
+};
+class CMLuaScript : public CMLuaEnvironment
+{
private:
- Status status;
- int unloadRef;
-
- const wchar_t *fileName;
+ wchar_t *scriptName;
wchar_t filePath[MAX_PATH];
+ bool isBinary;
+ ScriptStatus status;
+ int unloadRef;
public:
CMLuaScript(lua_State *L, const wchar_t *path);
@@ -23,16 +22,20 @@ public: ~CMLuaScript();
const wchar_t* GetFilePath() const;
- const wchar_t* GetFileName() const;
+ const wchar_t* GetName() const;
- bool IsEnabled();
+ bool IsBinary() const;
+
+ bool IsEnabled() const;
void Enable();
void Disable();
- Status GetStatus() const;
+ ScriptStatus GetStatus() const;
int Load() override;
int Unload() override;
bool Reload();
+
+ bool Compile();
};
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)
diff --git a/plugins/MirLua/src/script_loader.h b/plugins/MirLua/src/script_loader.h index 21236df491..1b7b87eab5 100644 --- a/plugins/MirLua/src/script_loader.h +++ b/plugins/MirLua/src/script_loader.h @@ -9,7 +9,7 @@ private: void SetPaths(); - void LoadScript(const wchar_t *scriptDir, const wchar_t *file); + void LoadScript(const wchar_t *scriptDir, const wchar_t *fileName); void LoadScripts(); public: diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index 498bf9ac5d..434dcb8e50 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -37,6 +37,7 @@ class CMLuaScript;
+#include "lua.h"
#include "plugin.h"
#include "modules.h"
#include "environment.h"
@@ -60,6 +61,10 @@ extern HANDLE g_hScriptsFolder; #define MIRLUA_PATHT MIRANDA_PATH "\\Scripts"
#endif
+#define LUACLIBSCRIPTEXT L"dll"
+#define LUATEXTSCRIPTEXT L"lua"
+#define LUAPRECSCRIPTEXT L"luac"
+
extern HNETLIBUSER g_hNetlib;
void LoadNetlib();
void UnloadNetlib();
diff --git a/plugins/MirLua/src/version.h b/plugins/MirLua/src/version.h index e14edce59e..dea60e0b6b 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 8
-#define __BUILD_NUM 9
+#define __RELEASE_NUM 9
+#define __BUILD_NUM 0
#include <stdver.h>
|