diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-06-22 14:21:07 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-06-22 14:21:07 +0000 |
commit | 631e22caadf37a547bafccc0f90251621b0bd987 (patch) | |
tree | b83353c9449eb2ef415120304d829f0dca17af07 | |
parent | 0514092bbe0dfcfa7a091a7a66b4df83be3a7eb9 (diff) |
MirLua: console refactoring
git-svn-id: http://svn.miranda-ng.org/main/trunk@14328 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | plugins/MirLua/src/main.cpp | 18 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua.cpp | 3 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua.h | 1 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_console.cpp | 25 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_console.h | 15 | ||||
-rw-r--r-- | plugins/MirLua/src/stdafx.h | 4 |
6 files changed, 48 insertions, 18 deletions
diff --git a/plugins/MirLua/src/main.cpp b/plugins/MirLua/src/main.cpp index a747a6ea9e..64fc38f641 100644 --- a/plugins/MirLua/src/main.cpp +++ b/plugins/MirLua/src/main.cpp @@ -9,7 +9,6 @@ HANDLE g_hCommonFolderPath; HANDLE g_hCustomFolderPath;
CMLua *g_mLua;
-HANDLE hConsole = NULL;
PLUGININFOEX pluginInfo =
{
@@ -62,33 +61,18 @@ extern "C" int __declspec(dllexport) Load(void) {
mir_getLP(&pluginInfo);
- if (db_get_b(NULL, MODULE, "ShowConsole", 0))
- {
- if (!AttachConsole(ATTACH_PARENT_PROCESS))
- if (AllocConsole())
- {
- freopen("CONOUT$", "w", stdout);
- hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
- SetConsoleTitle(_T("MirLua Console"));
- }
- }
+ HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
g_hCommonFolderPath = FoldersRegisterCustomPathT("MirLua", Translate("Common scripts folder"), COMMON_SCRIPTS_PATHT);
g_hCustomFolderPath = FoldersRegisterCustomPathT("MirLua", Translate("Custom scripts folder"), CUSTOM_SCRIPTS_PATHT);
g_mLua = new CMLua();
- HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
-
return 0;
}
extern "C" int __declspec(dllexport) Unload(void)
{
- if (hConsole)
- CloseHandle(hConsole);
- FreeConsole();
-
delete g_mLua;
return 0;
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index e76731e11b..c90d120006 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -25,12 +25,15 @@ void CMLua::Load() MUUID muidLast = MIID_LAST;
hScriptsLangpack = GetPluginLangId(muidLast, 0);
+ console = new CMLuaConsole(L);
+
CLuaModuleLoader::Load(L);
CLuaScriptLoader::Load(L);
}
void CMLua::Unload()
{
+ delete console;
if (L)
lua_close(L);
KillModuleMenus(hScriptsLangpack);
diff --git a/plugins/MirLua/src/mlua.h b/plugins/MirLua/src/mlua.h index c792c32780..103512145e 100644 --- a/plugins/MirLua/src/mlua.h +++ b/plugins/MirLua/src/mlua.h @@ -5,6 +5,7 @@ class CMLua {
private:
lua_State *L;
+ CMLuaConsole *console;
void Load();
void Unload();
diff --git a/plugins/MirLua/src/mlua_console.cpp b/plugins/MirLua/src/mlua_console.cpp new file mode 100644 index 0000000000..75a51585b6 --- /dev/null +++ b/plugins/MirLua/src/mlua_console.cpp @@ -0,0 +1,25 @@ +#include "stdafx.h"
+
+CMLuaConsole::CMLuaConsole(lua_State *L)
+ : L(L), hConsole(NULL)
+{
+ if (db_get_b(NULL, MODULE, "ShowConsole", 0))
+ {
+ if (!AttachConsole(ATTACH_PARENT_PROCESS))
+ {
+ if (AllocConsole())
+ {
+ freopen("CONOUT$", "w", stdout);
+ hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
+ SetConsoleTitle(_T("MirLua Console"));
+ }
+ }
+ }
+}
+
+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 new file mode 100644 index 0000000000..6e82a22dd0 --- /dev/null +++ b/plugins/MirLua/src/mlua_console.h @@ -0,0 +1,15 @@ +#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/stdafx.h b/plugins/MirLua/src/stdafx.h index ce3e7948c6..592640b3e6 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -32,14 +32,16 @@ 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"
#define MODULE "MirLua"
-
extern CMLua *g_mLua;
extern int hScriptsLangpack;
|