From b9f48f4a1d76c9cec03636363075b3e9e64cfc9f Mon Sep 17 00:00:00 2001
From: aunsane <aunsane@gmail.com>
Date: Sun, 20 May 2018 21:44:13 +0300
Subject: fix merge

---
 plugins/MirLua/src/environment.cpp |  18 ++---
 plugins/MirLua/src/main.cpp        |  19 +----
 plugins/MirLua/src/mlua.cpp        | 139 ------------------------------------
 plugins/MirLua/src/mlua.h          |  27 -------
 plugins/MirLua/src/mplugin.cpp     | 141 +++++++++++++++++++++++++++++++++++++
 plugins/MirLua/src/mplugin.h       |  27 +++++++
 6 files changed, 180 insertions(+), 191 deletions(-)
 delete mode 100644 plugins/MirLua/src/mlua.cpp
 delete mode 100644 plugins/MirLua/src/mlua.h
 create mode 100644 plugins/MirLua/src/mplugin.cpp
 create mode 100644 plugins/MirLua/src/mplugin.h

(limited to 'plugins/MirLua')

diff --git a/plugins/MirLua/src/environment.cpp b/plugins/MirLua/src/environment.cpp
index e0090c6d70..e0a5689296 100644
--- a/plugins/MirLua/src/environment.cpp
+++ b/plugins/MirLua/src/environment.cpp
@@ -3,18 +3,18 @@
 #define MT_ENVIRONMENT "ENVIRONMENT"
 
 CMLuaEnvironment::CMLuaEnvironment(lua_State *L)
-	: L(L)
+	: CMPluginBase(nullptr, *(PLUGININFOEX*)nullptr), L(L)
 {
 	MUUID muidLast = MIID_LAST;
-	m_id = GetPluginLangId(muidLast, 0);
+	m_hLang = GetPluginLangId(muidLast, 0);
 }
 
 CMLuaEnvironment::~CMLuaEnvironment()
 {
-	KillModuleIcons(m_id);
-	KillModuleSounds(m_id);
-	KillModuleMenus(m_id);
-	KillModuleHotkeys(m_id);
+	KillModuleIcons(m_hLang);
+	KillModuleSounds(m_hLang);
+	KillModuleMenus(m_hLang);
+	KillModuleHotkeys(m_hLang);
 
 	KillObjectEventHooks(this);
 	KillObjectServices(this);
@@ -40,9 +40,9 @@ CMLuaEnvironment* CMLuaEnvironment::GetEnvironment(lua_State *L)
 
 int CMLuaEnvironment::GetEnvironmentId(lua_State *L)
 {
-	CMLuaEnvironment *script = GetEnvironment(L);
-	return script != nullptr
-		? script->GetId()
+	CMLuaEnvironment *env = GetEnvironment(L);
+	return env != nullptr
+		? env->m_hLang
 		: hMLuaLangpack;
 }
 
diff --git a/plugins/MirLua/src/main.cpp b/plugins/MirLua/src/main.cpp
index f65f6293ad..08390a557a 100644
--- a/plugins/MirLua/src/main.cpp
+++ b/plugins/MirLua/src/main.cpp
@@ -3,8 +3,6 @@
 int &hLangpack(g_plugin.m_hLang);
 CMPlugin g_plugin;
 
-CMLua *g_mLua;
-
 HANDLE g_hCLibsFolder;
 HANDLE g_hScriptsFolder;
 
@@ -27,10 +25,6 @@ PLUGININFOEX pluginInfoEx =
 
 };
 
-CMPlugin::CMPlugin() :
-	PLUGIN<CMPlugin>(MODULENAME, pluginInfoEx)
-{}
-
 extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
 {
 	return &pluginInfoEx;
@@ -46,7 +40,7 @@ int OnOptionsInit(WPARAM wParam, LPARAM)
 	odp.szGroup.w = LPGENW("Services");
 	odp.szTitle.w = L"Lua";
 	odp.szTab.w = LPGENW("Scripts");
-	odp.pDialog = new CMLuaOptions(g_mLua);
+	odp.pDialog = new CMLuaOptions();
 	Options_AddPage(wParam, &odp);
 	return 0;
 }
@@ -70,15 +64,10 @@ extern "C" int __declspec(dllexport) Load(void)
 	nlu.szSettingsModule = MODULENAME;
 	hNetlib = Netlib_RegisterUser(&nlu);
 
-	Proto_RegisterModule(PROTOTYPE_FILTER, MODULENAME);
-
-	hRecvMessage = CreateHookableEvent(MODULENAME PSR_MESSAGE);
-	CreateProtoServiceFunction(MODULENAME, PSR_MESSAGE, FilterRecvMessage);
+	HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
 
-	g_mLua = new CMLua();
-	g_mLua->Load();
+	g_plugin.Load();
 
-	HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
 	return 0;
 }
 
@@ -86,8 +75,6 @@ extern "C" int __declspec(dllexport) Load(void)
 
 extern "C" int __declspec(dllexport) Unload(void)
 {
-	delete g_mLua;
-
 	if (hNetlib) {
 		Netlib_CloseHandle(hNetlib);
 		hNetlib = nullptr;
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp
deleted file mode 100644
index 169dcb6a91..0000000000
--- a/plugins/MirLua/src/mlua.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-#include "stdafx.h"
-
-extern PLUGININFOEX pluginInfoEx;
-
-int hMLuaLangpack;
-
-CMLua::CMLua()
-	: PLUGIN(MODULENAME, pluginInfoEx),
-	L(nullptr),
-	Scripts(1)
-{
-	MUUID muidLast = MIID_LAST;
-	hMLuaLangpack = GetPluginLangId(muidLast, 0);
-
-	CreatePluginService(MS_LUA_CALL, &CMLua::Call);
-	CreatePluginService(MS_LUA_EXEC, &CMLua::Exec);
-	CreatePluginService(MS_LUA_EVAL, &CMLua::Eval);
-}
-
-CMLua::~CMLua()
-{
-	Unload();
-}
-
-void CMLua::Load()
-{
-	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);
-}
-
-void CMLua::Unload()
-{
-	Log("Unloading lua engine");
-
-	Scripts.destroy();
-
-	KillModuleIcons(hMLuaLangpack);
-	KillModuleSounds(hMLuaLangpack);
-	KillModuleMenus(hMLuaLangpack);
-	KillModuleHotkeys(hMLuaLangpack);
-
-	KillObjectEventHooks(L);
-	KillObjectServices(L);
-
-	lua_close(L);
-}
-
-void CMLua::Reload()
-{
-	Unload();
-	Load();
-}
-
-/***********************************************/
-
-static int mlua_call(lua_State *L)
-{
-	const char *module = luaL_checkstring(L, -3);
-	const char *function = luaL_checkstring(L, -2);
-
-	if (module && module[0]) {
-		lua_getglobal(L, "require");
-		lua_pushstring(L, module);
-		lua_pcall(L, 1, 1, 0);
-
-		lua_getfield(L, -1, function);
-		lua_replace(L, -2);
-	}
-	else
-		lua_getglobal(L, function);
-
-	lua_pcall(L, 0, 1, 0);
-
-	return 1;
-}
-
-INT_PTR CMLua::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_newtable(L);
-	lua_pushcclosure(L, mlua_call, 1);
-
-	CMLuaEnvironment env(L);
-	env.Load();
-
-	wchar_t *result = mir_utf8decodeW(lua_tostring(L, -1));
-	lua_pop(L, 1);
-
-	return (INT_PTR)result;
-}
-
-INT_PTR CMLua::Eval(WPARAM, LPARAM lParam)
-{
-	const wchar_t *script = (const wchar_t*)lParam;
-
-	if (luaL_loadstring(L, ptrA(mir_utf8encodeW(script)))) {
-		ReportError(L);
-		return NULL;
-	}
-
-	CMLuaEnvironment env(L);
-	env.Load();
-
-	wchar_t *result = mir_utf8decodeW(lua_tostring(L, -1));
-	lua_pop(L, 1);
-
-	return (INT_PTR)result;
-}
-
-INT_PTR CMLua::Exec(WPARAM, LPARAM lParam)
-{
-	const wchar_t *path = (const wchar_t*)lParam;
-
-	if (luaL_loadfile(L, ptrA(mir_utf8encodeW(path)))) {
-		ReportError(L);
-		return NULL;
-	}
-
-	CMLuaEnvironment env(L);
-	env.Load();
-
-	wchar_t *result = mir_utf8decodeW(lua_tostring(L, -1));
-	lua_pop(L, 1);
-
-	return (INT_PTR)result;
-}
diff --git a/plugins/MirLua/src/mlua.h b/plugins/MirLua/src/mlua.h
deleted file mode 100644
index d3f9cc3acd..0000000000
--- a/plugins/MirLua/src/mlua.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef _LUA_CORE_H_
-#define _LUA_CORE_H_
-
-class CMLua : public PLUGIN<CMLua>
-{
-	friend class CMLuaOptions;
-
-private:
-	lua_State *L;
-
-	void Unload();
-
-	INT_PTR __cdecl Eval(WPARAM, LPARAM);
-	INT_PTR __cdecl Call(WPARAM, LPARAM);
-	INT_PTR __cdecl Exec(WPARAM, LPARAM);
-
-public:
-	OBJLIST<CMLuaScript> Scripts;
-
-	CMLua();
-	~CMLua();
-
-	void Load();
-	void Reload();
-};
-
-#endif //_LUA_CORE_H_
diff --git a/plugins/MirLua/src/mplugin.cpp b/plugins/MirLua/src/mplugin.cpp
new file mode 100644
index 0000000000..5262499e98
--- /dev/null
+++ b/plugins/MirLua/src/mplugin.cpp
@@ -0,0 +1,141 @@
+#include "stdafx.h"
+
+extern PLUGININFOEX pluginInfoEx;
+
+int hMLuaLangpack;
+
+CMPlugin::CMPlugin()
+	: PLUGIN(MODULENAME, pluginInfoEx),
+	L(nullptr),
+	Scripts(1)
+{
+	MUUID muidLast = MIID_LAST;
+	hMLuaLangpack = GetPluginLangId(muidLast, 0);
+
+	RegisterProtocol(PROTOTYPE_FILTER);
+
+	CreatePluginService(MS_LUA_CALL, &CMPlugin::Call);
+	CreatePluginService(MS_LUA_EXEC, &CMPlugin::Exec);
+	CreatePluginService(MS_LUA_EVAL, &CMPlugin::Eval);
+}
+
+CMPlugin::~CMPlugin()
+{
+	Unload();
+}
+
+void CMPlugin::Load()
+{
+	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);
+}
+
+void CMPlugin::Unload()
+{
+	Log("Unloading lua engine");
+
+	Scripts.destroy();
+
+	KillModuleIcons(hMLuaLangpack);
+	KillModuleSounds(hMLuaLangpack);
+	KillModuleMenus(hMLuaLangpack);
+	KillModuleHotkeys(hMLuaLangpack);
+
+	KillObjectEventHooks(L);
+	KillObjectServices(L);
+
+	lua_close(L);
+}
+
+void CMPlugin::Reload()
+{
+	Unload();
+	Load();
+}
+
+/***********************************************/
+
+static int mlua_call(lua_State *L)
+{
+	const char *module = luaL_checkstring(L, -3);
+	const char *function = luaL_checkstring(L, -2);
+
+	if (module && module[0]) {
+		lua_getglobal(L, "require");
+		lua_pushstring(L, module);
+		lua_pcall(L, 1, 1, 0);
+
+		lua_getfield(L, -1, function);
+		lua_replace(L, -2);
+	}
+	else
+		lua_getglobal(L, function);
+
+	lua_pcall(L, 0, 1, 0);
+
+	return 1;
+}
+
+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_newtable(L);
+	lua_pushcclosure(L, mlua_call, 1);
+
+	CMLuaEnvironment env(L);
+	env.Load();
+
+	wchar_t *result = mir_utf8decodeW(lua_tostring(L, -1));
+	lua_pop(L, 1);
+
+	return (INT_PTR)result;
+}
+
+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);
+		return NULL;
+	}
+
+	CMLuaEnvironment env(L);
+	env.Load();
+
+	wchar_t *result = mir_utf8decodeW(lua_tostring(L, -1));
+	lua_pop(L, 1);
+
+	return (INT_PTR)result;
+}
+
+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);
+		return NULL;
+	}
+
+	CMLuaEnvironment env(L);
+	env.Load();
+
+	wchar_t *result = mir_utf8decodeW(lua_tostring(L, -1));
+	lua_pop(L, 1);
+
+	return (INT_PTR)result;
+}
diff --git a/plugins/MirLua/src/mplugin.h b/plugins/MirLua/src/mplugin.h
new file mode 100644
index 0000000000..9db92580f8
--- /dev/null
+++ b/plugins/MirLua/src/mplugin.h
@@ -0,0 +1,27 @@
+#ifndef _LUA_CORE_H_
+#define _LUA_CORE_H_
+
+struct CMPlugin : public PLUGIN<CMPlugin>
+{
+	friend class CMLuaOptions;
+
+private:
+	lua_State *L;
+
+	void Unload();
+
+	INT_PTR __cdecl Eval(WPARAM, LPARAM);
+	INT_PTR __cdecl Call(WPARAM, LPARAM);
+	INT_PTR __cdecl Exec(WPARAM, LPARAM);
+
+public:
+	OBJLIST<CMLuaScript> Scripts;
+
+	CMPlugin();
+	~CMPlugin();
+
+	void Load();
+	void Reload();
+};
+
+#endif //_LUA_CORE_H_
-- 
cgit v1.2.3