diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-07-02 08:52:29 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-07-02 08:52:29 +0000 |
commit | 2481102c6541df37a773569dd4d67b579f04d819 (patch) | |
tree | c8dac50aac18414c42e8c024340eab7a6ee5ab32 /plugins | |
parent | cea0c911bc4bb8d527739cbaf1a098ac2344a7d8 (diff) |
MirLua:
- removed console
- changed logging (via netlib)
- version bump
git-svn-id: http://svn.miranda-ng.org/main/trunk@14467 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/MirLua/src/m_core.cpp | 2 | ||||
-rw-r--r-- | plugins/MirLua/src/main.cpp | 15 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua.cpp | 26 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua.h | 5 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_console.cpp | 36 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_console.h | 15 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_script_loader.cpp | 29 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_script_loader.h | 6 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_utils.cpp | 20 | ||||
-rw-r--r-- | plugins/MirLua/src/stdafx.h | 9 | ||||
-rw-r--r-- | plugins/MirLua/src/version.h | 2 |
11 files changed, 75 insertions, 90 deletions
diff --git a/plugins/MirLua/src/m_core.cpp b/plugins/MirLua/src/m_core.cpp index 41adff71fc..a61ed05431 100644 --- a/plugins/MirLua/src/m_core.cpp +++ b/plugins/MirLua/src/m_core.cpp @@ -177,7 +177,7 @@ static INT_PTR ServiceFunctionObjParam(void *obj, WPARAM wParam, LPARAM lParam, lua_pushnumber(L, wParam);
lua_pushnumber(L, lParam);
if (lua_pcall(L, 2, 1, 0))
- printf("%s\n", lua_tostring(L, -1));
+ CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1));
INT_PTR res = (INT_PTR)lua_tointeger(L, 1);
lua_pushinteger(L, res);
diff --git a/plugins/MirLua/src/main.cpp b/plugins/MirLua/src/main.cpp index 62ebb97be3..e9bf5fff64 100644 --- a/plugins/MirLua/src/main.cpp +++ b/plugins/MirLua/src/main.cpp @@ -8,6 +8,8 @@ HINSTANCE g_hInstance; HANDLE g_hCommonFolderPath;
HANDLE g_hCustomFolderPath;
+HANDLE hNetlib = NULL;
+
CMLua *g_mLua;
PLUGININFOEX pluginInfo =
@@ -54,6 +56,13 @@ extern "C" int __declspec(dllexport) Load(void) g_hCommonFolderPath = FoldersRegisterCustomPathT("MirLua", Translate("Common scripts folder"), COMMON_SCRIPTS_PATHT);
g_hCustomFolderPath = FoldersRegisterCustomPathT("MirLua", Translate("Custom scripts folder"), CUSTOM_SCRIPTS_PATHT);
+ NETLIBUSER nlu = { 0 };
+ nlu.cbSize = sizeof(nlu);
+ nlu.flags = NUF_OUTGOING | NUF_INCOMING | NUF_HTTPCONNS | NUF_UNICODE;
+ nlu.ptszDescriptiveName = _T(MODULE);
+ nlu.szSettingsModule = MODULE;
+ hNetlib = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
+
g_mLua = new CMLua();
return 0;
@@ -63,5 +72,11 @@ extern "C" int __declspec(dllexport) Unload(void) {
delete g_mLua;
+ if (hNetlib)
+ {
+ Netlib_CloseHandle(hNetlib);
+ hNetlib = NULL;
+ }
+
return 0;
}
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index 3d0d7f6106..253bd2b64e 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -2,24 +2,19 @@ CMLua::CMLua() : L(NULL)
{
- console = new CMLuaConsole(L);
- hLogger = mir_createLog(MODULE, _T("MirLua log"), VARST(_T("%miranda_logpath%\\MirLua.txt")), 0);
-
Load();
}
CMLua::~CMLua()
{
Unload();
- mir_closeLog(hLogger);
- delete console;
}
void CMLua::Load()
{
- mir_writeLogT(hLogger, _T("Loading lua engine\n"));
+ CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)"Loading lua engine");
L = luaL_newstate();
- mir_writeLogT(hLogger, _T("Loading std modules\n"));
+ CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)"Loading std modules");
luaL_openlibs(L);
lua_getglobal(L, "package");
@@ -29,17 +24,24 @@ void CMLua::Load() lua_setfield(L, -2, "cpath");
lua_pop(L, 1);
+ lua_getglobal(L, "_G");
+ lua_pushcclosure(L, luaM_print, 0); + lua_setfield(L, -2, "print");
+ lua_pop(L, 1);
+
+ lua_atpanic(L, luaM_atpanic);
+
MUUID muidLast = MIID_LAST;
hScriptsLangpack = GetPluginLangId(muidLast, 0);
- mir_writeLogT(hLogger, _T("Loading miranda modules\n"));
+ CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)"Loading miranda modules");
CLuaModuleLoader::Load(L);
- CLuaScriptLoader::Load(L, hLogger);
+ CLuaScriptLoader::Load(L);
}
void CMLua::Unload()
{
- mir_writeLogT(hLogger, _T("Unloading lua engine\n"));
+ CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)"Unloading lua engine");
::KillModuleMenus(hScriptsLangpack);
::KillModuleServices();
@@ -66,11 +68,9 @@ int CMLua::HookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM par lua_pushnumber(L, wParam);
lua_pushnumber(L, lParam);
if (lua_pcall(L, 2, 1, 0))
- printf("%s\n", lua_tostring(L, -1));
+ CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1));
int res = (int)lua_tointeger(L, 1);
- //luaL_unref(L, LUA_REGISTRYINDEX, ref);
-
return res;
}
\ No newline at end of file diff --git a/plugins/MirLua/src/mlua.h b/plugins/MirLua/src/mlua.h index 81bdbdb177..c792c32780 100644 --- a/plugins/MirLua/src/mlua.h +++ b/plugins/MirLua/src/mlua.h @@ -5,11 +5,6 @@ class CMLua {
private:
lua_State *L;
- HANDLE hLogger;
- CMLuaConsole *console;
-
- static void KillModuleServices();
- static void KillModuleEventHooks();
void Load();
void Unload();
diff --git a/plugins/MirLua/src/mlua_console.cpp b/plugins/MirLua/src/mlua_console.cpp deleted file mode 100644 index 428e43f585..0000000000 --- a/plugins/MirLua/src/mlua_console.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "stdafx.h"
-
-BOOL WINAPI ConsoleHandler(DWORD)
-{
- return TRUE;
-}
-
-CMLuaConsole::CMLuaConsole(lua_State *L)
- : L(L), hConsole(NULL)
-{
- if (db_get_b(NULL, MODULE, "ShowConsole", 0))
- {
- if (!AttachConsole(ATTACH_PARENT_PROCESS))
- {
- if (AllocConsole())
- {
- SetConsoleTitle(_T("MirLua Console"));
- freopen("CONOUT$", "w", stdout);
- hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
- if (HWND hConsoleWindow = GetConsoleWindow())
- {
- HMENU hConsoleMenu = GetSystemMenu(hConsoleWindow, FALSE);
- DeleteMenu(hConsoleMenu, SC_CLOSE, MF_BYCOMMAND);
- }
- SetConsoleCtrlHandler(ConsoleHandler, true);
- }
- }
- }
-}
-
-CMLuaConsole::~CMLuaConsole()
-{
- if (hConsole)
- CloseHandle(hConsole);
- FreeConsole();
-}
\ No newline at end of file diff --git a/plugins/MirLua/src/mlua_console.h b/plugins/MirLua/src/mlua_console.h deleted file mode 100644 index 6e82a22dd0..0000000000 --- a/plugins/MirLua/src/mlua_console.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _LUA_CONSOLE_H_
-#define _LUA_CONSOLE_H_
-
-class CMLuaConsole
-{
-private:
- lua_State *L;
- HANDLE hConsole;
-
-public:
- CMLuaConsole(lua_State *L);
- ~CMLuaConsole();
-};
-
-#endif //_LUA_CONSOLE_H_
\ No newline at end of file diff --git a/plugins/MirLua/src/mlua_script_loader.cpp b/plugins/MirLua/src/mlua_script_loader.cpp index 663ad4cd59..c54c489d8b 100644 --- a/plugins/MirLua/src/mlua_script_loader.cpp +++ b/plugins/MirLua/src/mlua_script_loader.cpp @@ -1,6 +1,6 @@ #include "stdafx.h"
-CLuaScriptLoader::CLuaScriptLoader(lua_State *L, HANDLE hLogger) : L(L), hLogger(hLogger)
+CLuaScriptLoader::CLuaScriptLoader(lua_State *L) : L(L)
{
}
@@ -18,20 +18,26 @@ void CLuaScriptLoader::RegisterScriptsFolder(const char *path) lua_pop(L, 1);
}
-void CLuaScriptLoader::LoadScript(const TCHAR *path, const TCHAR *name)
+void CLuaScriptLoader::LoadScript(const TCHAR *path)
{
+
if (luaL_dofile(L, T2Utf(path)))
{
- 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));
+ CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1));
+ return;
}
- else mir_writeLogT(hLogger, _T(" %s:OK\n"), name);
+
+ TCHAR buf[4096];
+ mir_sntprintf(buf, _T("%s:OK"), path);
+ CallService(MS_NETLIB_LOGW, (WPARAM)hNetlib, (LPARAM)buf);
}
void CLuaScriptLoader::LoadScripts(const TCHAR *scriptDir)
{
- mir_writeLogT(hLogger, _T("Loading scripts from path %s\n"), scriptDir);
+ TCHAR buf[4096];
+ mir_sntprintf(buf, _T("Loading scripts from %s"), scriptDir);
+ CallService(MS_NETLIB_LOGW, (WPARAM)hNetlib, (LPARAM)buf);
+
RegisterScriptsFolder(ptrA(mir_utf8encodeT(scriptDir)));
TCHAR searchMask[MAX_PATH];
@@ -50,24 +56,21 @@ 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, fd.cFileName);
+ LoadScript(fullPath);
}
} while (FindNextFile(hFind, &fd));
FindClose(hFind);
}
- mir_writeLogT(hLogger, _T("\n"), scriptDir);
}
-void CLuaScriptLoader::Load(lua_State *L, HANDLE hLogger)
+void CLuaScriptLoader::Load(lua_State *L)
{
TCHAR scriptDir[MAX_PATH];
- CLuaScriptLoader loader(L, hLogger);
+ 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);
-
- 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 b4067ec530..fe15bbc08b 100644 --- a/plugins/MirLua/src/mlua_script_loader.h +++ b/plugins/MirLua/src/mlua_script_loader.h @@ -7,15 +7,15 @@ private: lua_State *L;
HANDLE hLogger;
- CLuaScriptLoader(lua_State *L, HANDLE hLogger);
+ CLuaScriptLoader(lua_State *L);
void RegisterScriptsFolder(const char *path);
- void LoadScript(const TCHAR *path, const TCHAR *name);
+ void LoadScript(const TCHAR *path);
void LoadScripts(const TCHAR *scriptDir);
public:
- static void Load(lua_State *L, HANDLE hLogger = NULL);
+ static void Load(lua_State *L);
};
#endif //_LUA_SCRIPT_LOADER_H_
\ No newline at end of file diff --git a/plugins/MirLua/src/mlua_utils.cpp b/plugins/MirLua/src/mlua_utils.cpp index d4eded5ea9..837ab08c53 100644 --- a/plugins/MirLua/src/mlua_utils.cpp +++ b/plugins/MirLua/src/mlua_utils.cpp @@ -1,5 +1,25 @@ #include "stdafx.h"
+int luaM_print(lua_State *L)
+{
+ CMStringA data;
+ int nargs = lua_gettop(L);
+ for (int i = 1; i <= nargs; ++i)
+ data.AppendFormat("%s ", lua_tostring(L, i));
+ data.Delete(data.GetLength() - 3, 3);
+
+ CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)data.GetBuffer());
+
+ return 0;
+}
+
+int luaM_atpanic(lua_State *L)
+{
+ CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1));
+
+ return 0;
+}
+
bool luaM_checkboolean(lua_State *L, int idx)
{
luaL_checktype(L, 2, LUA_TBOOLEAN);
diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index 5c2cedb63e..1b463b564a 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -11,6 +11,7 @@ #include <m_database.h>
#include <m_options.h>
#include <m_gui.h>
+#include <m_netlib.h>
#include <m_genmenu.h>
#include <m_clist.h>
@@ -32,10 +33,7 @@ extern "C" #include "version.h"
#include "resource.h"
-class CMLuaConsole;
-
#include "mlua.h"
-#include "mlua_console.h"
#include "mlua_module_loader.h"
#include "mlua_script_loader.h"
#include "mlua_options.h"
@@ -51,6 +49,8 @@ extern HINSTANCE g_hInstance; extern HANDLE g_hCommonFolderPath;
extern HANDLE g_hCustomFolderPath;
+extern HANDLE hNetlib;
+
#ifdef _UNICODE
#define COMMON_SCRIPTS_PATHT MIRANDA_PATHW L"\\Scripts"
#define CUSTOM_SCRIPTS_PATHT MIRANDA_USERDATAW L"\\Scripts"
@@ -84,6 +84,9 @@ LUAMOD_API int (luaopen_m_toptoolbar)(lua_State *L); #define MLUA_VARIABLES "m_variables"
LUAMOD_API int (luaopen_m_variables)(lua_State *L);
+int luaM_print(lua_State *L);
+int luaM_atpanic(lua_State *L);
+
bool luaM_checkboolean(lua_State *L, int idx);
WPARAM luaM_towparam(lua_State *L, int idx);
LPARAM luaM_tolparam(lua_State *L, int idx);
diff --git a/plugins/MirLua/src/version.h b/plugins/MirLua/src/version.h index f2af4804d5..e16ba2651e 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 2
-#define __BUILD_NUM 0
+#define __BUILD_NUM 1
#include <stdver.h>
|