From f8b41d51f1b760a433c2dbf997ed852b7dd94945 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sun, 3 Jan 2016 21:30:23 +0000 Subject: MirLua: fixed script loading git-svn-id: http://svn.miranda-ng.org/main/trunk@16014 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/main.cpp | 2 -- plugins/MirLua/src/mlua.cpp | 15 +++++++-------- plugins/MirLua/src/mlua_script.cpp | 2 +- plugins/MirLua/src/mlua_script_loader.cpp | 14 +++----------- plugins/MirLua/src/mlua_utils.cpp | 25 +++++++++++++++++++------ plugins/MirLua/src/stdafx.h | 19 ++++++------------- 6 files changed, 36 insertions(+), 41 deletions(-) (limited to 'plugins/MirLua') diff --git a/plugins/MirLua/src/main.cpp b/plugins/MirLua/src/main.cpp index 4652610222..e1b9950fc6 100644 --- a/plugins/MirLua/src/main.cpp +++ b/plugins/MirLua/src/main.cpp @@ -7,7 +7,6 @@ HINSTANCE g_hInstance; CMLua *g_mLua; -HANDLE g_hCLibsFolder; HANDLE g_hScriptsFolder; HANDLE hNetlib = NULL; @@ -42,7 +41,6 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) int OnModulesLoaded(WPARAM, LPARAM) { - g_hCLibsFolder = FoldersRegisterCustomPathT(MODULE, Translate("C libs folder"), MIRLUA_CPATHT); g_hScriptsFolder = FoldersRegisterCustomPathT(MODULE, Translate("Scripts folder"), MIRLUA_PATHT); HookEvent(ME_OPT_INITIALISE, CLuaOptions::OnOptionsInit); diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index 7256c2b6df..dc0699182e 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -20,15 +20,14 @@ CMLua::~CMLua() void CMLua::SetPaths() { TCHAR path[MAX_PATH]; + FoldersGetCustomPathT(g_hScriptsFolder, path, _countof(path), VARST(MIRLUA_PATHT)); lua_getglobal(L, "package"); - FoldersGetCustomPathT(g_hScriptsFolder, path, _countof(path), VARST(MIRLUA_CPATHT)); - lua_pushstring(L, ptrA(mir_utf8encodeT(path))); + lua_pushfstring(L, "%s\\?.dll", ptrA(mir_utf8encodeT(path))); lua_setfield(L, -2, "cpath"); - FoldersGetCustomPathT(g_hScriptsFolder, path, _countof(path), VARST(MIRLUA_PATHT)); - lua_pushstring(L, ptrA(mir_utf8encodeT(path))); + lua_pushfstring(L, "%s\\?.lua", ptrA(mir_utf8encodeT(path))); lua_setfield(L, -2, "path"); lua_pop(L, 1); @@ -36,9 +35,9 @@ void CMLua::SetPaths() void CMLua::Load() { - CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)"Loading lua engine"); + Log("Loading lua engine"); L = luaL_newstate(); - CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)"Loading std modules"); + Log("Loading std modules"); luaL_openlibs(L); SetPaths(); @@ -57,14 +56,14 @@ void CMLua::Load() MUUID muidLast = MIID_LAST; hScriptsLangpack = GetPluginLangId(muidLast, 0); - CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)"Loading miranda modules"); + Log("Loading miranda modules"); CLuaModuleLoader::Load(L); CLuaScriptLoader::Load(L); } void CMLua::Unload() { - CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)"Unloading lua engine"); + Log("Unloading lua engine"); while (int last = Scripts.getCount()) { diff --git a/plugins/MirLua/src/mlua_script.cpp b/plugins/MirLua/src/mlua_script.cpp index bfe827418b..8f76f864a4 100644 --- a/plugins/MirLua/src/mlua_script.cpp +++ b/plugins/MirLua/src/mlua_script.cpp @@ -38,7 +38,7 @@ bool CMLuaScript::Load() { if (luaL_loadfile(L, T2Utf(filePath))) { - CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1)); + Log(lua_tostring(L, -1)); return false; } diff --git a/plugins/MirLua/src/mlua_script_loader.cpp b/plugins/MirLua/src/mlua_script_loader.cpp index b374007dce..13dc5bea99 100644 --- a/plugins/MirLua/src/mlua_script_loader.cpp +++ b/plugins/MirLua/src/mlua_script_loader.cpp @@ -13,20 +13,14 @@ void CLuaScriptLoader::LoadScript(const TCHAR *scriptDir, const TCHAR *file) CMLuaScript *script = new CMLuaScript(L, path); g_mLua->Scripts.insert(script); - TCHAR buf[4096]; if (db_get_b(NULL, MODULE, _T2A(file), 1) == FALSE) { - - mir_sntprintf(buf, _T("%s:PASS"), path); - CallService(MS_NETLIB_LOGW, (WPARAM)hNetlib, (LPARAM)buf); + Log(_T("%s:PASS"), path); return; } if (script->Load()) - { - mir_sntprintf(buf, _T("%s:OK"), path); - CallService(MS_NETLIB_LOGW, (WPARAM)hNetlib, (LPARAM)buf); - } + Log(_T("%s:OK"), path); } void CLuaScriptLoader::LoadScripts() @@ -34,9 +28,7 @@ void CLuaScriptLoader::LoadScripts() TCHAR scriptDir[MAX_PATH]; FoldersGetCustomPathT(g_hScriptsFolder, scriptDir, _countof(scriptDir), VARST(MIRLUA_PATHT)); - TCHAR buf[4096]; - mir_sntprintf(buf, _T("Loading scripts from %s"), scriptDir); - CallService(MS_NETLIB_LOGW, (WPARAM)hNetlib, (LPARAM)buf); + Log(_T("Loading scripts from %s"), scriptDir); TCHAR searchMask[MAX_PATH]; mir_sntprintf(searchMask, _T("%s\\%s"), scriptDir, _T("*.lua")); diff --git a/plugins/MirLua/src/mlua_utils.cpp b/plugins/MirLua/src/mlua_utils.cpp index 9b5d9ca9ee..d0c89090b3 100644 --- a/plugins/MirLua/src/mlua_utils.cpp +++ b/plugins/MirLua/src/mlua_utils.cpp @@ -1,5 +1,21 @@ #include "stdafx.h" +void Log(const char *format, ...) +{ + va_list args; + va_start(args, format); + CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)(CMStringA().FormatV(format, args))); + va_end(args); +} + +void Log(const wchar_t *format, ...) +{ + va_list args; + va_start(args, format); + CallService(MS_NETLIB_LOGW, (WPARAM)hNetlib, (LPARAM)(CMStringW().FormatV(format, args))); + va_end(args); +} + void ShowNotification(const char *caption, const char *message, int flags, MCONTACT hContact) { if (Miranda_Terminated()) @@ -21,7 +37,7 @@ void ShowNotification(const char *caption, const char *message, int flags, MCONT void ReportError(const char *message) { - CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)message); + Log(message); if (db_get_b(NULL, MODULE, "PopupOnError", 0)) ShowNotification(MODULE, message, MB_OK | MB_ICONERROR); } @@ -59,9 +75,6 @@ int luaM_print(lua_State *L) case LUA_TSTRING: data.AppendFormat("%s ", lua_tostring(L, i)); break; - case LUA_TTABLE: - data.AppendFormat("table(0x%p) ", lua_topointer(L, i)); - break; default: data.AppendFormat("%s(0x%p) ", luaL_typename(L, i), lua_topointer(L, i)); break; @@ -70,7 +83,7 @@ int luaM_print(lua_State *L) if (data.GetLength() >= 3) data.Delete(data.GetLength() - 3, 3); - CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)data.GetBuffer()); + Log(data.GetBuffer()); return 0; } @@ -165,7 +178,7 @@ void ObsoleteMethod(lua_State *L, const char *message) char text[512]; mir_snprintf(text, "%s is obsolete. %s", info.name, message); - CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)text); + Log(text); if (db_get_b(NULL, MODULE, "PopupOnObsolete", 0)) ShowNotification(MODULE, text, MB_OK | MB_ICONWARNING, NULL); } \ No newline at end of file diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index 9eb436bfa7..db8a0b2e48 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -50,23 +50,12 @@ class CMLuaScript; #define MODULE "MirLua" -extern CMLua *g_mLua; - extern int hScriptsLangpack; - extern HINSTANCE g_hInstance; -extern HANDLE g_hCLibsFolder; -extern HANDLE g_hScriptsFolder; - -extern HANDLE hNetlib; - -#ifdef _UNICODE -#define MIRLUA_CPATHT L"" -#else -#define MIRLUA_CPATHT "" -#endif +extern CMLua *g_mLua; +extern HANDLE g_hScriptsFolder; #ifdef _UNICODE #define MIRLUA_PATHT MIRANDA_PATHW L"\\Scripts" #else @@ -117,6 +106,10 @@ LUAMOD_API int (luaopen_m_windows)(lua_State *L); /* utils */ +extern HANDLE hNetlib; +void Log(const char *format, ...); +void Log(const wchar_t *format, ...); + void ShowNotification(const char *caption, const char *message, int flags = 0, MCONTACT hContact = NULL); int luaM_atpanic(lua_State *L); -- cgit v1.2.3