diff options
author | aunsane <aunsane@gmail.com> | 2018-05-20 21:44:13 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2018-05-20 21:44:13 +0300 |
commit | b9f48f4a1d76c9cec03636363075b3e9e64cfc9f (patch) | |
tree | 537831af62c72e79dbafa877e3f05216fc1567b1 /plugins/MirLua | |
parent | 3aaa121979662b5127f54a244a328a161be281ea (diff) |
fix merge
Diffstat (limited to 'plugins/MirLua')
-rw-r--r-- | plugins/MirLua/src/environment.cpp | 18 | ||||
-rw-r--r-- | plugins/MirLua/src/main.cpp | 19 | ||||
-rw-r--r-- | plugins/MirLua/src/mplugin.cpp (renamed from plugins/MirLua/src/mlua.cpp) | 280 | ||||
-rw-r--r-- | plugins/MirLua/src/mplugin.h (renamed from plugins/MirLua/src/mlua.h) | 54 |
4 files changed, 180 insertions, 191 deletions
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/mplugin.cpp index 169dcb6a91..5262499e98 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mplugin.cpp @@ -1,139 +1,141 @@ -#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;
-}
+#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/mlua.h b/plugins/MirLua/src/mplugin.h index d3f9cc3acd..9db92580f8 100644 --- a/plugins/MirLua/src/mlua.h +++ b/plugins/MirLua/src/mplugin.h @@ -1,27 +1,27 @@ -#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_
+#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_ |