summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/MirLua/src')
-rw-r--r--plugins/MirLua/src/main.cpp16
-rw-r--r--plugins/MirLua/src/mlua.cpp11
-rw-r--r--plugins/MirLua/src/mlua_options.cpp35
-rw-r--r--plugins/MirLua/src/mlua_options.h3
-rw-r--r--plugins/MirLua/src/mlua_script_loader.cpp20
-rw-r--r--plugins/MirLua/src/mlua_script_loader.h2
6 files changed, 55 insertions, 32 deletions
diff --git a/plugins/MirLua/src/main.cpp b/plugins/MirLua/src/main.cpp
index 64fc38f641..62ebb97be3 100644
--- a/plugins/MirLua/src/main.cpp
+++ b/plugins/MirLua/src/main.cpp
@@ -38,22 +38,10 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
return &pluginInfo;
}
-int OnOptionsInit(WPARAM wParam, LPARAM)
-{
- OPTIONSDIALOGPAGE odp = { 0 };
- odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR | ODPF_DONTTRANSLATE;
- odp.ptszGroup = LPGENT("Customize");
- odp.ptszTitle = LPGENT("Scripts");
- odp.ptszTab = _T("Lua");
- odp.pDialog = CLuaOptions::CreateOptionsPage();
- Options_AddPage(wParam, &odp);
-
- return 0;
-}
-
int OnModulesLoaded(WPARAM, LPARAM)
{
- HookEvent(ME_OPT_INITIALISE, OnOptionsInit);
+ HookEvent(ME_OPT_INITIALISE, CLuaOptions::OnOptionsInit);
+
return 0;
}
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp
index 7f5d8027c0..f42f0fecdb 100644
--- a/plugins/MirLua/src/mlua.cpp
+++ b/plugins/MirLua/src/mlua.cpp
@@ -3,6 +3,7 @@
CMLua::CMLua() : L(NULL)
{
console = new CMLuaConsole(L);
+ hLogger = mir_createLog(MODULE, _T("MirLua log"), VARST(_T("%miranda_logpath%\\MirLua.txt")), 0);
Load();
}
@@ -10,13 +11,15 @@ CMLua::CMLua() : L(NULL)
CMLua::~CMLua()
{
Unload();
-
+ mir_closeLog(hLogger);
delete console;
}
void CMLua::Load()
{
+ mir_writeLogT(hLogger, _T("Loading lua engine\n"));
L = luaL_newstate();
+ mir_writeLogT(hLogger, _T("Loading std modules\n"));
luaL_openlibs(L);
lua_getglobal(L, "package");
@@ -29,15 +32,15 @@ void CMLua::Load()
MUUID muidLast = MIID_LAST;
hScriptsLangpack = GetPluginLangId(muidLast, 0);
- hLogger = mir_createLog(MODULE, _T("MirLua log"), VARST(_T("%miranda_logpath%\\MirLua.txt")), 0);
-
+ mir_writeLogT(hLogger, _T("Loading miranda modules\n"));
CLuaModuleLoader::Load(L);
CLuaScriptLoader::Load(L, hLogger);
}
void CMLua::Unload()
{
- mir_closeLog(hLogger);
+ mir_writeLogT(hLogger, _T("Unloading lua engine\n"));
+
if (L)
lua_close(L);
KillModuleMenus(hScriptsLangpack);
diff --git a/plugins/MirLua/src/mlua_options.cpp b/plugins/MirLua/src/mlua_options.cpp
index 89fe72af98..bd8234ed9a 100644
--- a/plugins/MirLua/src/mlua_options.cpp
+++ b/plugins/MirLua/src/mlua_options.cpp
@@ -17,6 +17,18 @@ void CLuaOptions::CreateLink(CCtrlData& ctrl, const char *szSetting, TCHAR *szVa
ctrl.CreateDbLink(MODULE, szSetting, szValue);
}
+int CLuaOptions::OnOptionsInit(WPARAM wParam, LPARAM)
+{
+ OPTIONSDIALOGPAGE odp = { 0 };
+ odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR | ODPF_DONTTRANSLATE;
+ odp.ptszGroup = LPGENT("Scripts");
+ odp.ptszTitle = _T("Lua");
+ odp.pDialog = CLuaOptions::CreateOptionsPage();
+ Options_AddPage(wParam, &odp);
+
+ return 0;
+}
+
void CLuaOptions::LoadScripts(const TCHAR *scriptDir, int iGroup)
{
TCHAR searchMask[MAX_PATH];
@@ -39,14 +51,8 @@ void CLuaOptions::LoadScripts(const TCHAR *scriptDir, int iGroup)
}
}
-void CLuaOptions::OnInitDialog()
+void CLuaOptions::LoadScripts()
{
- CDlgBase::OnInitDialog();
-
- m_scripts.SetExtendedListViewStyle(LVS_EX_CHECKBOXES | LVS_EX_INFOTIP);
- m_scripts.EnableGroupView(TRUE);
- m_scripts.AddColumn(0, _T("Script"), 300);
-
TCHAR scriptDir[MAX_PATH], relativeScriptDir[MAX_PATH], header[MAX_PATH + 100];
FoldersGetCustomPathT(g_hCommonFolderPath, scriptDir, _countof(scriptDir), VARST(COMMON_SCRIPTS_PATHT));
PathToRelativeT(scriptDir, relativeScriptDir, NULL);
@@ -59,6 +65,17 @@ void CLuaOptions::OnInitDialog()
mir_sntprintf(header, _T("%s (%s)"), TranslateT("Custom scripts"), relativeScriptDir);
m_scripts.AddGroup(1, header);
LoadScripts(scriptDir, 1);
+}
+
+void CLuaOptions::OnInitDialog()
+{
+ CDlgBase::OnInitDialog();
+
+ m_scripts.SetExtendedListViewStyle(LVS_EX_CHECKBOXES | LVS_EX_INFOTIP);
+ m_scripts.EnableGroupView(TRUE);
+ m_scripts.AddColumn(0, _T("Script"), 300);
+
+ LoadScripts();
isScriptListInit = true;
}
@@ -102,5 +119,9 @@ INT_PTR CLuaOptions::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
void CLuaOptions::OnReload(CCtrlBase*)
{
+ isScriptListInit = false;
+ m_scripts.DeleteAllItems();
+ LoadScripts();
+ isScriptListInit = true;
g_mLua->Reload();
} \ No newline at end of file
diff --git a/plugins/MirLua/src/mlua_options.h b/plugins/MirLua/src/mlua_options.h
index 490a465395..4972656260 100644
--- a/plugins/MirLua/src/mlua_options.h
+++ b/plugins/MirLua/src/mlua_options.h
@@ -9,6 +9,7 @@ private:
CCtrlButton m_reload;
void LoadScripts(const TCHAR *scriptDir, int iGroup = -1);
+ void LoadScripts();
protected:
void OnInitDialog();
@@ -24,6 +25,8 @@ public:
void CreateLink(CCtrlData& ctrl, const char *szSetting, BYTE type, DWORD iValue);
void CreateLink(CCtrlData& ctrl, const char *szSetting, TCHAR *szValue);
+ static int OnOptionsInit(WPARAM wParam, LPARAM);
+
template<class T>
__inline void CreateLink(CCtrlData &ctrl, CMOption<T> &option)
{
diff --git a/plugins/MirLua/src/mlua_script_loader.cpp b/plugins/MirLua/src/mlua_script_loader.cpp
index abeb18d8d4..663ad4cd59 100644
--- a/plugins/MirLua/src/mlua_script_loader.cpp
+++ b/plugins/MirLua/src/mlua_script_loader.cpp
@@ -10,23 +10,28 @@ void CLuaScriptLoader::RegisterScriptsFolder(const char *path)
lua_getfield(L, -1, "path");
const char *oldPath = luaL_checkstring(L, -1);
lua_pop(L, 1);
- lua_pushfstring(L, "%s;%s\\?.lua", oldPath, path);
+ if (!mir_strlen(oldPath))
+ lua_pushfstring(L, "%s\\?.lua", path);
+ else
+ lua_pushfstring(L, "%s;%s\\?.lua", oldPath, path);
lua_setfield(L, -2, "path");
lua_pop(L, 1);
}
-void CLuaScriptLoader::LoadScript(const char *path)
+void CLuaScriptLoader::LoadScript(const TCHAR *path, const TCHAR *name)
{
- if (luaL_dofile(L, path))
+ if (luaL_dofile(L, T2Utf(path)))
{
- const char *error = lua_tostring(L, -1);
- mir_writeLogT(hLogger, _T("%s"), ptrT(mir_utf8decodeT(error)));
+ ptrT error(mir_utf8decodeT(lua_tostring(L, -1)));
+ mir_writeLogT(hLogger, _T(" %s:FAIL\n %s\n"), name, error);
printf("%s\n", lua_tostring(L, -1));
}
+ else mir_writeLogT(hLogger, _T(" %s:OK\n"), name);
}
void CLuaScriptLoader::LoadScripts(const TCHAR *scriptDir)
{
+ mir_writeLogT(hLogger, _T("Loading scripts from path %s\n"), scriptDir);
RegisterScriptsFolder(ptrA(mir_utf8encodeT(scriptDir)));
TCHAR searchMask[MAX_PATH];
@@ -45,11 +50,12 @@ 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(T2Utf(path));
+ LoadScript(fullPath, fd.cFileName);
}
} while (FindNextFile(hFind, &fd));
FindClose(hFind);
}
+ mir_writeLogT(hLogger, _T("\n"), scriptDir);
}
void CLuaScriptLoader::Load(lua_State *L, HANDLE hLogger)
@@ -62,4 +68,6 @@ void CLuaScriptLoader::Load(lua_State *L, HANDLE hLogger)
FoldersGetCustomPathT(g_hCustomFolderPath, scriptDir, _countof(scriptDir), VARST(CUSTOM_SCRIPTS_PATHT));
loader.LoadScripts(scriptDir);
+
+ mir_writeLogT(hLogger, _T("\n"), scriptDir);
} \ No newline at end of file
diff --git a/plugins/MirLua/src/mlua_script_loader.h b/plugins/MirLua/src/mlua_script_loader.h
index 16980bfdc9..b4067ec530 100644
--- a/plugins/MirLua/src/mlua_script_loader.h
+++ b/plugins/MirLua/src/mlua_script_loader.h
@@ -11,7 +11,7 @@ private:
void RegisterScriptsFolder(const char *path);
- void LoadScript(const char *path);
+ void LoadScript(const TCHAR *path, const TCHAR *name);
void LoadScripts(const TCHAR *scriptDir);
public: