diff options
Diffstat (limited to 'plugins/MirLua')
-rw-r--r-- | plugins/MirLua/src/m_icolib.cpp | 15 | ||||
-rw-r--r-- | plugins/MirLua/src/m_protocols.cpp | 3 | ||||
-rw-r--r-- | plugins/MirLua/src/m_sounds.cpp | 6 | ||||
-rw-r--r-- | plugins/MirLua/src/main.cpp | 12 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_environment.cpp | 23 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_environment.h | 10 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_metatable.h | 5 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_options.h | 5 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_script.cpp | 16 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_script.h | 9 | ||||
-rw-r--r-- | plugins/MirLua/src/mplugin.cpp | 4 | ||||
-rw-r--r-- | plugins/MirLua/src/mplugin.h | 2 | ||||
-rw-r--r-- | plugins/MirLua/src/stdafx.h | 1 |
13 files changed, 39 insertions, 72 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 b38ed43347..08390a557a 100644 --- a/plugins/MirLua/src/main.cpp +++ b/plugins/MirLua/src/main.cpp @@ -25,10 +25,6 @@ PLUGININFOEX pluginInfoEx = };
-/*CMPlugin::CMPlugin() :
- PLUGIN<CMPlugin>(MODULENAME, pluginInfoEx)
-{}*/
-
extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
{
return &pluginInfoEx;
@@ -68,14 +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_plugin.Load();
- HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
return 0;
}
@@ -83,8 +75,6 @@ extern "C" int __declspec(dllexport) Load(void) extern "C" int __declspec(dllexport) Unload(void)
{
- g_plugin.Unload();
-
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.h b/plugins/MirLua/src/mlua_options.h index 373827fc42..9658ffe336 100644 --- a/plugins/MirLua/src/mlua_options.h +++ b/plugins/MirLua/src/mlua_options.h @@ -1,5 +1,4 @@ -#ifndef _LUA_OPTIONS_H_
-#define _LUA_OPTIONS_H_
+#pragma once
class CMLuaOptions : public CPluginDlgBase
{
@@ -26,5 +25,3 @@ protected: public:
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/mplugin.cpp b/plugins/MirLua/src/mplugin.cpp index b688876fce..4a605c71db 100644 --- a/plugins/MirLua/src/mplugin.cpp +++ b/plugins/MirLua/src/mplugin.cpp @@ -1,7 +1,5 @@ #include "stdafx.h" -extern PLUGININFOEX pluginInfoEx; - int hMLuaLangpack; CMPlugin::CMPlugin() @@ -12,6 +10,8 @@ CMPlugin::CMPlugin() 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); diff --git a/plugins/MirLua/src/mplugin.h b/plugins/MirLua/src/mplugin.h index 8f3a847c5f..0a5bf21445 100644 --- a/plugins/MirLua/src/mplugin.h +++ b/plugins/MirLua/src/mplugin.h @@ -7,6 +7,7 @@ struct CMPlugin : public PLUGIN<CMPlugin> private: lua_State *L; + void Unload(); INT_PTR __cdecl Eval(WPARAM, LPARAM); INT_PTR __cdecl Call(WPARAM, LPARAM); @@ -19,6 +20,5 @@ public: ~CMPlugin(); void Load(); - void Unload(); void Reload(); }; diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index 06d1de2056..609397949f 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -47,6 +47,7 @@ class CMLuaScript; #define MODULENAME "MirLua"
extern int hMLuaLangpack;
+extern PLUGININFOEX pluginInfoEx;
extern HANDLE g_hCLibsFolder;
extern HANDLE g_hScriptsFolder;
|