summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin <apollo2k4@narod.ru>2018-05-20 21:05:22 +0300
committerKonstantin <apollo2k4@narod.ru>2018-05-20 21:05:22 +0300
commit3f90207479ee0a6530631812717801a54093658c (patch)
tree6fd49e050ec5179df59fc5badc18e5668e0d6008
parent7d6b89fd45814936d0edeff664bf5efb2d19b875 (diff)
parent5de8252e58fbdbebb8914e99a90bec06a0ff039f (diff)
Merge branch 'master' of https://github.com/miranda-ng/miranda-ng
-rw-r--r--plugins/MirLua/src/m_icolib.cpp15
-rw-r--r--plugins/MirLua/src/m_protocols.cpp3
-rw-r--r--plugins/MirLua/src/m_sounds.cpp6
-rw-r--r--plugins/MirLua/src/main.cpp19
-rw-r--r--plugins/MirLua/src/mlua_environment.cpp23
-rw-r--r--plugins/MirLua/src/mlua_environment.h10
-rw-r--r--plugins/MirLua/src/mlua_metatable.h5
-rw-r--r--plugins/MirLua/src/mlua_options.cpp11
-rw-r--r--plugins/MirLua/src/mlua_options.h8
-rw-r--r--plugins/MirLua/src/mlua_script.cpp16
-rw-r--r--plugins/MirLua/src/mlua_script.h9
-rw-r--r--plugins/MirLua/src/mlua_script_loader.cpp2
-rw-r--r--plugins/MirLua/src/mplugin.cpp (renamed from plugins/MirLua/src/mlua.cpp)278
-rw-r--r--plugins/MirLua/src/mplugin.h (renamed from plugins/MirLua/src/mlua.h)51
-rw-r--r--plugins/MirLua/src/stdafx.h10
15 files changed, 210 insertions, 256 deletions
diff --git a/plugins/MirLua/src/m_icolib.cpp b/plugins/MirLua/src/m_icolib.cpp
index a83c9877d7..f9faa2997b 100644
--- a/plugins/MirLua/src/m_icolib.cpp
+++ b/plugins/MirLua/src/m_icolib.cpp
@@ -25,8 +25,7 @@ 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);
}
@@ -52,8 +51,7 @@ 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));
@@ -61,8 +59,7 @@ 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);
}
@@ -89,8 +86,7 @@ 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;
@@ -121,8 +117,7 @@ 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 a2e3d7fbc1..0be2c253b9 100644
--- a/plugins/MirLua/src/m_protocols.cpp
+++ b/plugins/MirLua/src/m_protocols.cpp
@@ -236,6 +236,9 @@ 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<PROTOCOLDESCRIPTOR>(L, MT_PROTOCOLDESCRIPTOR)
diff --git a/plugins/MirLua/src/m_sounds.cpp b/plugins/MirLua/src/m_sounds.cpp
index 177148320a..b50bd0c20f 100644
--- a/plugins/MirLua/src/m_sounds.cpp
+++ b/plugins/MirLua/src/m_sounds.cpp
@@ -7,12 +7,10 @@ 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;
- CMPluginBase *pPlugin = GetPluginByLangId(CMLuaEnvironment::GetEnvironmentId(L));
+ int res = 1;
+ CMPluginBase *pPlugin = CMLuaEnvironment::GetEnvironment(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 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_environment.cpp b/plugins/MirLua/src/mlua_environment.cpp
index 4a82e63231..dee11d6f8f 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)
- : 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,17 +40,12 @@ 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;
}
-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 aa6ebb103a..3d6b6382fb 100644
--- a/plugins/MirLua/src/mlua_environment.h
+++ b/plugins/MirLua/src/mlua_environment.h
@@ -1,10 +1,8 @@
-#ifndef _LUA_ENVIRONMENT_H_
-#define _LUA_ENVIRONMENT_H_
+#pragma once
-class CMLuaEnvironment
+class CMLuaEnvironment : public CMPluginBase
{
private:
- int m_id;
std::map<HANDLE, int> m_hookRefs;
std::map<HANDLE, int> m_serviceRefs;
@@ -19,8 +17,6 @@ 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);
@@ -29,5 +25,3 @@ public:
bool Load();
};
-
-#endif //_LUA_ENVIRONMENT_H_
diff --git a/plugins/MirLua/src/mlua_metatable.h b/plugins/MirLua/src/mlua_metatable.h
index 33d3b40e7e..aa736428ca 100644
--- a/plugins/MirLua/src/mlua_metatable.h
+++ b/plugins/MirLua/src/mlua_metatable.h
@@ -1,5 +1,4 @@
-#ifndef _LUA_METATABLE_H_
-#define _LUA_METATABLE_H_
+#pragma once
#include <map>
#include <cstddef>
@@ -343,5 +342,3 @@ const luaL_Reg MT<T>::Events[] = {
template<typename T>
OBJLIST<CMTField> MT<T>::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 226a925fd9..3c2dade81b 100644
--- a/plugins/MirLua/src/mlua_options.cpp
+++ b/plugins/MirLua/src/mlua_options.cpp
@@ -1,11 +1,12 @@
#include "stdafx.h"
-CMLuaOptions::CMLuaOptions(CMLua *mLua)
+CMLuaOptions::CMLuaOptions()
: CPluginDlgBase(g_plugin, IDD_OPTIONS, MODULENAME),
- m_mLua(mLua), isScriptListInit(false),
+ 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);
@@ -16,7 +17,7 @@ CMLuaOptions::CMLuaOptions(CMLua *mLua)
void CMLuaOptions::LoadScripts()
{
- for (auto &script : m_mLua->Scripts) {
+ for (auto &script : g_plugin.Scripts) {
wchar_t *fileName = NEWWSTR_ALLOCA(script->GetFileName());
int iIcon = script->GetStatus() - 1;
int iItem = m_scripts.AddItem(fileName, iIcon, (LPARAM)script);
@@ -124,7 +125,7 @@ void CMLuaOptions::OnReload(CCtrlBase*)
{
isScriptListInit = false;
m_scripts.DeleteAllItems();
- m_mLua->Reload();
+ g_plugin.Reload();
LoadScripts();
isScriptListInit = true;
}
diff --git a/plugins/MirLua/src/mlua_options.h b/plugins/MirLua/src/mlua_options.h
index 2e3b4ff7f7..9658ffe336 100644
--- a/plugins/MirLua/src/mlua_options.h
+++ b/plugins/MirLua/src/mlua_options.h
@@ -1,10 +1,8 @@
-#ifndef _LUA_OPTIONS_H_
-#define _LUA_OPTIONS_H_
+#pragma once
class CMLuaOptions : public CPluginDlgBase
{
private:
- CMLua *m_mLua;
bool isScriptListInit;
CCtrlCheck m_popupOnError;
@@ -25,7 +23,5 @@ protected:
INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam);
public:
- CMLuaOptions(CMLua *mLua);
+ CMLuaOptions();
};
-
-#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 9e4cc4ffbe..976ed79688 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, '\\') + 1;
- wchar_t *dot = wcsrchr(fileName, '.');
+ fileName = wcsrchr(filePath, L'\\') + 1;
+ const 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);
- moduleName = mir_utf8encodeW(name);
+ m_szModuleName = 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);
- moduleName = mir_strdup(script.moduleName);
+ m_szModuleName = mir_strdup(script.m_szModuleName);
}
CMLuaScript::~CMLuaScript()
{
Unload();
- mir_free(moduleName);
+ mir_free((char*)m_szModuleName);
}
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, moduleName);
+ lua_getfield(L, -1, m_szModuleName);
if (!lua_toboolean(L, -1)) {
lua_pop(L, 1);
lua_pushvalue(L, -2);
- lua_setfield(L, -2, moduleName);
+ lua_setfield(L, -2, m_szModuleName);
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, moduleName);
+ lua_setfield(L, -2, m_szModuleName);
lua_pop(L, 1);
}
diff --git a/plugins/MirLua/src/mlua_script.h b/plugins/MirLua/src/mlua_script.h
index 70c044741e..8106c7a00a 100644
--- a/plugins/MirLua/src/mlua_script.h
+++ b/plugins/MirLua/src/mlua_script.h
@@ -1,5 +1,4 @@
-#ifndef _LUA_SCRIPT_H_
-#define _LUA_SCRIPT_H_
+#pragma once
class CMLuaScript : public CMLuaEnvironment
{
@@ -15,8 +14,8 @@ private:
Status status;
int unloadRef;
- char *moduleName;
- wchar_t *fileName;
+ //char *moduleName;
+ const wchar_t *fileName;
wchar_t filePath[MAX_PATH];
void Unload();
@@ -38,5 +37,3 @@ 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 95701b4559..0092cca372 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_mLua->Scripts.insert(script);
+ g_plugin.Scripts.insert(script);
if (!script->IsEnabled()) {
Log(L"%s:PASS", path);
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mplugin.cpp
index 169dcb6a91..4a605c71db 100644
--- a/plugins/MirLua/src/mlua.cpp
+++ b/plugins/MirLua/src/mplugin.cpp
@@ -1,139 +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;
-}
+#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/mlua.h b/plugins/MirLua/src/mplugin.h
index d3f9cc3acd..0a5bf21445 100644
--- a/plugins/MirLua/src/mlua.h
+++ b/plugins/MirLua/src/mplugin.h
@@ -1,27 +1,24 @@
-#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_
+#pragma once
+
+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();
+};
diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h
index f97ecd09de..609397949f 100644
--- a/plugins/MirLua/src/stdafx.h
+++ b/plugins/MirLua/src/stdafx.h
@@ -35,7 +35,7 @@
class CMLuaScript;
-#include "mlua.h"
+#include "mplugin.h"
#include "mlua_environment.h"
#include "mlua_script.h"
#include "mlua_function_loader.h"
@@ -46,14 +46,8 @@ class CMLuaScript;
#define MODULENAME "MirLua"
-struct CMPlugin : public PLUGIN<CMPlugin>
-{
- CMPlugin();
-};
-
-extern CMLua *g_mLua;
-
extern int hMLuaLangpack;
+extern PLUGININFOEX pluginInfoEx;
extern HANDLE g_hCLibsFolder;
extern HANDLE g_hScriptsFolder;