From 46363eef857b69761f1d6d28da5a53a954f76900 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Sun, 20 May 2018 21:09:53 +0300 Subject: Revert "Merge branch 'master' of https://github.com/miranda-ng/miranda-ng" This reverts commit 3f90207479ee0a6530631812717801a54093658c, reversing changes made to 7d6b89fd45814936d0edeff664bf5efb2d19b875. --- plugins/MirLua/src/m_icolib.cpp | 15 ++-- plugins/MirLua/src/m_protocols.cpp | 3 - plugins/MirLua/src/m_sounds.cpp | 6 +- plugins/MirLua/src/main.cpp | 19 +++- plugins/MirLua/src/mlua.cpp | 139 ++++++++++++++++++++++++++++++ plugins/MirLua/src/mlua.h | 27 ++++++ plugins/MirLua/src/mlua_environment.cpp | 23 +++-- plugins/MirLua/src/mlua_environment.h | 10 ++- plugins/MirLua/src/mlua_metatable.h | 5 +- plugins/MirLua/src/mlua_options.cpp | 11 ++- plugins/MirLua/src/mlua_options.h | 8 +- plugins/MirLua/src/mlua_script.cpp | 16 ++-- plugins/MirLua/src/mlua_script.h | 9 +- plugins/MirLua/src/mlua_script_loader.cpp | 2 +- plugins/MirLua/src/mplugin.cpp | 139 ------------------------------ plugins/MirLua/src/mplugin.h | 24 ------ plugins/MirLua/src/stdafx.h | 10 ++- 17 files changed, 256 insertions(+), 210 deletions(-) create mode 100644 plugins/MirLua/src/mlua.cpp create mode 100644 plugins/MirLua/src/mlua.h delete mode 100644 plugins/MirLua/src/mplugin.cpp delete mode 100644 plugins/MirLua/src/mplugin.h (limited to 'plugins') diff --git a/plugins/MirLua/src/m_icolib.cpp b/plugins/MirLua/src/m_icolib.cpp index f9faa2997b..a83c9877d7 100644 --- a/plugins/MirLua/src/m_icolib.cpp +++ b/plugins/MirLua/src/m_icolib.cpp @@ -25,7 +25,8 @@ static void MakeSKINICONDESC(lua_State *L, SKINICONDESC &sid) sid.defaultFile.w = mir_utf8decodeW(lua_tostring(L, -1)); lua_pop(L, 1); - if (sid.defaultFile.w == nullptr) { + if (sid.defaultFile.w == nullptr) + { sid.defaultFile.w = (wchar_t*)mir_calloc(MAX_PATH + 1); GetModuleFileName(g_plugin.getInst(), sid.defaultFile.w, MAX_PATH); } @@ -51,7 +52,8 @@ static int lua_AddIcon(lua_State *L) { SKINICONDESC sid = { }; - if (lua_type(L, 1) == LUA_TSTRING) { + if (lua_type(L, 1) == LUA_TSTRING) + { sid.flags = SIDF_ALL_UNICODE; sid.pszName = mir_utf8decodeA(luaL_checkstring(L, 1)); sid.description.w = mir_utf8decodeW(luaL_checkstring(L, 2)); @@ -59,7 +61,8 @@ static int lua_AddIcon(lua_State *L) sid.defaultFile.w = mir_utf8decodeW(lua_tostring(L, 4)); sid.hDefaultIcon = GetIcon(IDI_SCRIPT); - if (sid.defaultFile.w == nullptr) { + if (sid.defaultFile.w == nullptr) + { sid.defaultFile.w = (wchar_t*)mir_calloc(MAX_PATH + 1); GetModuleFileName(g_plugin.getInst(), sid.defaultFile.w, MAX_PATH); } @@ -86,7 +89,8 @@ static int lua_GetIcon(lua_State *L) bool big = luaM_toboolean(L, 2); HICON hIcon = nullptr; - switch (lua_type(L, 1)) { + switch (lua_type(L, 1)) + { case LUA_TLIGHTUSERDATA: hIcon = IcoLib_GetIconByHandle(lua_touserdata(L, 1), big); break; @@ -117,7 +121,8 @@ static int lua_GetIconHandle(lua_State *L) static int lua_RemoveIcon(lua_State *L) { - switch (lua_type(L, 1)) { + switch (lua_type(L, 1)) + { case LUA_TLIGHTUSERDATA: IcoLib_RemoveIconByHandle(lua_touserdata(L, 1)); break; diff --git a/plugins/MirLua/src/m_protocols.cpp b/plugins/MirLua/src/m_protocols.cpp index 0be2c253b9..a2e3d7fbc1 100644 --- a/plugins/MirLua/src/m_protocols.cpp +++ b/plugins/MirLua/src/m_protocols.cpp @@ -236,9 +236,6 @@ static luaL_Reg protocolsApi[] = LUAMOD_API int luaopen_m_protocols(lua_State *L) { - hRecvMessage = CreateHookableEvent(MODULENAME PSR_MESSAGE); - CreateProtoServiceFunction(MODULENAME, PSR_MESSAGE, FilterRecvMessage); - luaL_newlib(L, protocolsApi); MT(L, MT_PROTOCOLDESCRIPTOR) diff --git a/plugins/MirLua/src/m_sounds.cpp b/plugins/MirLua/src/m_sounds.cpp index b50bd0c20f..177148320a 100644 --- a/plugins/MirLua/src/m_sounds.cpp +++ b/plugins/MirLua/src/m_sounds.cpp @@ -7,10 +7,12 @@ static int lua_AddSound(lua_State *L) ptrW section(mir_utf8decodeW(luaL_optstring(L, 3, MODULENAME))); ptrW filePath(mir_utf8decodeW(lua_tostring(L, 4))); - int res = 1; - CMPluginBase *pPlugin = CMLuaEnvironment::GetEnvironment(L); + int res; + CMPluginBase *pPlugin = GetPluginByLangId(CMLuaEnvironment::GetEnvironmentId(L)); if (pPlugin != nullptr) res = pPlugin->addSound(name, section, description, filePath); + else + res = 1; lua_pushboolean(L, res == 0); return 1; diff --git a/plugins/MirLua/src/main.cpp b/plugins/MirLua/src/main.cpp index 08390a557a..f65f6293ad 100644 --- a/plugins/MirLua/src/main.cpp +++ b/plugins/MirLua/src/main.cpp @@ -3,6 +3,8 @@ int &hLangpack(g_plugin.m_hLang); CMPlugin g_plugin; +CMLua *g_mLua; + HANDLE g_hCLibsFolder; HANDLE g_hScriptsFolder; @@ -25,6 +27,10 @@ PLUGININFOEX pluginInfoEx = }; +CMPlugin::CMPlugin() : + PLUGIN(MODULENAME, pluginInfoEx) +{} + extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) { return &pluginInfoEx; @@ -40,7 +46,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(); + odp.pDialog = new CMLuaOptions(g_mLua); Options_AddPage(wParam, &odp); return 0; } @@ -64,10 +70,15 @@ extern "C" int __declspec(dllexport) Load(void) nlu.szSettingsModule = MODULENAME; hNetlib = Netlib_RegisterUser(&nlu); - HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); + Proto_RegisterModule(PROTOTYPE_FILTER, MODULENAME); - g_plugin.Load(); + hRecvMessage = CreateHookableEvent(MODULENAME PSR_MESSAGE); + CreateProtoServiceFunction(MODULENAME, PSR_MESSAGE, FilterRecvMessage); + g_mLua = new CMLua(); + g_mLua->Load(); + + HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); return 0; } @@ -75,6 +86,8 @@ 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 new file mode 100644 index 0000000000..169dcb6a91 --- /dev/null +++ b/plugins/MirLua/src/mlua.cpp @@ -0,0 +1,139 @@ +#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 new file mode 100644 index 0000000000..d3f9cc3acd --- /dev/null +++ b/plugins/MirLua/src/mlua.h @@ -0,0 +1,27 @@ +#ifndef _LUA_CORE_H_ +#define _LUA_CORE_H_ + +class CMLua : public PLUGIN +{ + 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 Scripts; + + CMLua(); + ~CMLua(); + + void Load(); + void Reload(); +}; + +#endif //_LUA_CORE_H_ diff --git a/plugins/MirLua/src/mlua_environment.cpp b/plugins/MirLua/src/mlua_environment.cpp index dee11d6f8f..4a82e63231 100644 --- a/plugins/MirLua/src/mlua_environment.cpp +++ b/plugins/MirLua/src/mlua_environment.cpp @@ -3,18 +3,18 @@ #define MT_ENVIRONMENT "ENVIRONMENT" CMLuaEnvironment::CMLuaEnvironment(lua_State *L) - : CMPluginBase(nullptr, *(PLUGININFOEX*)nullptr), L(L) + : L(L) { MUUID muidLast = MIID_LAST; - m_hLang = GetPluginLangId(muidLast, 0); + m_id = GetPluginLangId(muidLast, 0); } CMLuaEnvironment::~CMLuaEnvironment() { - KillModuleIcons(m_hLang); - KillModuleSounds(m_hLang); - KillModuleMenus(m_hLang); - KillModuleHotkeys(m_hLang); + KillModuleIcons(m_id); + KillModuleSounds(m_id); + KillModuleMenus(m_id); + KillModuleHotkeys(m_id); KillObjectEventHooks(this); KillObjectServices(this); @@ -40,12 +40,17 @@ CMLuaEnvironment* CMLuaEnvironment::GetEnvironment(lua_State *L) int CMLuaEnvironment::GetEnvironmentId(lua_State *L) { - CMLuaEnvironment *env = GetEnvironment(L); - return env != nullptr - ? env->m_hLang + CMLuaEnvironment *script = GetEnvironment(L); + return script != nullptr + ? script->GetId() : hMLuaLangpack; } +int CMLuaEnvironment::GetId() const +{ + return m_id; +} + void CMLuaEnvironment::AddHookRef(HANDLE h, int ref) { m_hookRefs[h] = ref; diff --git a/plugins/MirLua/src/mlua_environment.h b/plugins/MirLua/src/mlua_environment.h index 3d6b6382fb..aa6ebb103a 100644 --- a/plugins/MirLua/src/mlua_environment.h +++ b/plugins/MirLua/src/mlua_environment.h @@ -1,8 +1,10 @@ -#pragma once +#ifndef _LUA_ENVIRONMENT_H_ +#define _LUA_ENVIRONMENT_H_ -class CMLuaEnvironment : public CMPluginBase +class CMLuaEnvironment { private: + int m_id; std::map m_hookRefs; std::map m_serviceRefs; @@ -17,6 +19,8 @@ public: static CMLuaEnvironment* GetEnvironment(lua_State *L); static int GetEnvironmentId(lua_State *L); + int GetId() const; + void AddHookRef(HANDLE h, int ref); void ReleaseHookRef(HANDLE h); @@ -25,3 +29,5 @@ public: bool Load(); }; + +#endif //_LUA_ENVIRONMENT_H_ diff --git a/plugins/MirLua/src/mlua_metatable.h b/plugins/MirLua/src/mlua_metatable.h index aa736428ca..33d3b40e7e 100644 --- a/plugins/MirLua/src/mlua_metatable.h +++ b/plugins/MirLua/src/mlua_metatable.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef _LUA_METATABLE_H_ +#define _LUA_METATABLE_H_ #include #include @@ -342,3 +343,5 @@ const luaL_Reg MT::Events[] = { template OBJLIST MT::Fields(5, &CMTField::Compare); + +#endif //_LUA_METATABLE_H_ diff --git a/plugins/MirLua/src/mlua_options.cpp b/plugins/MirLua/src/mlua_options.cpp index 3c2dade81b..226a925fd9 100644 --- a/plugins/MirLua/src/mlua_options.cpp +++ b/plugins/MirLua/src/mlua_options.cpp @@ -1,12 +1,11 @@ #include "stdafx.h" -CMLuaOptions::CMLuaOptions() +CMLuaOptions::CMLuaOptions(CMLua *mLua) : CPluginDlgBase(g_plugin, IDD_OPTIONS, MODULENAME), - isScriptListInit(false), + m_mLua(mLua), isScriptListInit(false), m_popupOnError(this, IDC_POPUPONERROR), m_popupOnObsolete(this, IDC_POPUPONOBSOLETE), - m_scripts(this, IDC_SCRIPTS), - m_reload(this, IDC_RELOAD) + m_scripts(this, IDC_SCRIPTS), m_reload(this, IDC_RELOAD) { CreateLink(m_popupOnError, "PopupOnError", DBVT_BYTE, 1); CreateLink(m_popupOnObsolete, "PopupOnObsolete", DBVT_BYTE, 1); @@ -17,7 +16,7 @@ CMLuaOptions::CMLuaOptions() void CMLuaOptions::LoadScripts() { - for (auto &script : g_plugin.Scripts) { + for (auto &script : m_mLua->Scripts) { wchar_t *fileName = NEWWSTR_ALLOCA(script->GetFileName()); int iIcon = script->GetStatus() - 1; int iItem = m_scripts.AddItem(fileName, iIcon, (LPARAM)script); @@ -125,7 +124,7 @@ void CMLuaOptions::OnReload(CCtrlBase*) { isScriptListInit = false; m_scripts.DeleteAllItems(); - g_plugin.Reload(); + m_mLua->Reload(); LoadScripts(); isScriptListInit = true; } diff --git a/plugins/MirLua/src/mlua_options.h b/plugins/MirLua/src/mlua_options.h index 9658ffe336..2e3b4ff7f7 100644 --- a/plugins/MirLua/src/mlua_options.h +++ b/plugins/MirLua/src/mlua_options.h @@ -1,8 +1,10 @@ -#pragma once +#ifndef _LUA_OPTIONS_H_ +#define _LUA_OPTIONS_H_ class CMLuaOptions : public CPluginDlgBase { private: + CMLua *m_mLua; bool isScriptListInit; CCtrlCheck m_popupOnError; @@ -23,5 +25,7 @@ protected: INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam); public: - CMLuaOptions(); + CMLuaOptions(CMLua *mLua); }; + +#endif //_LUA_OPTIONS_H_ \ No newline at end of file diff --git a/plugins/MirLua/src/mlua_script.cpp b/plugins/MirLua/src/mlua_script.cpp index 976ed79688..9e4cc4ffbe 100644 --- a/plugins/MirLua/src/mlua_script.cpp +++ b/plugins/MirLua/src/mlua_script.cpp @@ -7,15 +7,15 @@ CMLuaScript::CMLuaScript(lua_State *L, const wchar_t *path) { mir_wstrcpy(filePath, path); - fileName = wcsrchr(filePath, L'\\') + 1; - const wchar_t *dot = wcsrchr(fileName, '.'); + fileName = wcsrchr(filePath, '\\') + 1; + wchar_t *dot = wcsrchr(fileName, '.'); size_t length = mir_wstrlen(fileName) - mir_wstrlen(dot) + 1; ptrW name((wchar_t*)mir_calloc(sizeof(wchar_t) * (length + 1))); mir_wstrncpy(name, fileName, length); - m_szModuleName = mir_utf8encodeW(name); + moduleName = mir_utf8encodeW(name); } CMLuaScript::CMLuaScript(const CMLuaScript &script) @@ -23,13 +23,13 @@ CMLuaScript::CMLuaScript(const CMLuaScript &script) { mir_wstrcpy(filePath, script.filePath); fileName = mir_wstrdup(script.fileName); - m_szModuleName = mir_strdup(script.m_szModuleName); + moduleName = mir_strdup(script.moduleName); } CMLuaScript::~CMLuaScript() { Unload(); - mir_free((char*)m_szModuleName); + mir_free(moduleName); } const wchar_t* CMLuaScript::GetFilePath() const @@ -82,11 +82,11 @@ bool CMLuaScript::Load() return true; luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); - lua_getfield(L, -1, m_szModuleName); + lua_getfield(L, -1, moduleName); if (!lua_toboolean(L, -1)) { lua_pop(L, 1); lua_pushvalue(L, -2); - lua_setfield(L, -2, m_szModuleName); + lua_setfield(L, -2, moduleName); lua_pop(L, 1); } else @@ -126,7 +126,7 @@ void CMLuaScript::Unload() luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); lua_pushnil(L); - lua_setfield(L, -2, m_szModuleName); + lua_setfield(L, -2, moduleName); lua_pop(L, 1); } diff --git a/plugins/MirLua/src/mlua_script.h b/plugins/MirLua/src/mlua_script.h index 8106c7a00a..70c044741e 100644 --- a/plugins/MirLua/src/mlua_script.h +++ b/plugins/MirLua/src/mlua_script.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef _LUA_SCRIPT_H_ +#define _LUA_SCRIPT_H_ class CMLuaScript : public CMLuaEnvironment { @@ -14,8 +15,8 @@ private: Status status; int unloadRef; - //char *moduleName; - const wchar_t *fileName; + char *moduleName; + wchar_t *fileName; wchar_t filePath[MAX_PATH]; void Unload(); @@ -37,3 +38,5 @@ public: bool Load(); bool Reload(); }; + +#endif //_LUA_SCRIPT_H_ diff --git a/plugins/MirLua/src/mlua_script_loader.cpp b/plugins/MirLua/src/mlua_script_loader.cpp index 0092cca372..95701b4559 100644 --- a/plugins/MirLua/src/mlua_script_loader.cpp +++ b/plugins/MirLua/src/mlua_script_loader.cpp @@ -29,7 +29,7 @@ void CMLuaScriptLoader::LoadScript(const wchar_t *scriptDir, const wchar_t *file PathToRelativeW(fullPath, path); CMLuaScript *script = new CMLuaScript(L, path); - g_plugin.Scripts.insert(script); + g_mLua->Scripts.insert(script); if (!script->IsEnabled()) { Log(L"%s:PASS", path); diff --git a/plugins/MirLua/src/mplugin.cpp b/plugins/MirLua/src/mplugin.cpp deleted file mode 100644 index 4a605c71db..0000000000 --- a/plugins/MirLua/src/mplugin.cpp +++ /dev/null @@ -1,139 +0,0 @@ -#include "stdafx.h" - -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 deleted file mode 100644 index 0a5bf21445..0000000000 --- a/plugins/MirLua/src/mplugin.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -struct CMPlugin : public PLUGIN -{ - 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 Scripts; - - CMPlugin(); - ~CMPlugin(); - - void Load(); - void Reload(); -}; diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index 609397949f..f97ecd09de 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -35,7 +35,7 @@ class CMLuaScript; -#include "mplugin.h" +#include "mlua.h" #include "mlua_environment.h" #include "mlua_script.h" #include "mlua_function_loader.h" @@ -46,8 +46,14 @@ class CMLuaScript; #define MODULENAME "MirLua" +struct CMPlugin : public PLUGIN +{ + CMPlugin(); +}; + +extern CMLua *g_mLua; + extern int hMLuaLangpack; -extern PLUGININFOEX pluginInfoEx; extern HANDLE g_hCLibsFolder; extern HANDLE g_hScriptsFolder; -- cgit v1.2.3