diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-06-09 16:16:16 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-06-09 16:16:16 +0000 |
commit | 2c2b13b63e510af16d3806843a022853f0740ed7 (patch) | |
tree | 1d0a97401251ce0f5c47ee4083b7c259e9ffc49a /plugins/MirLua/src | |
parent | 31aeb2d24674a29ea5810a7e5e2e5a7d36bf3300 (diff) |
MirLua:
- added debug console
- added m_clist module
- added examples
git-svn-id: http://svn.miranda-ng.org/main/trunk@14079 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/src')
-rw-r--r-- | plugins/MirLua/src/main.cpp | 33 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua.cpp | 8 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua.h | 5 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_clist.cpp | 37 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_core.cpp | 10 | ||||
-rw-r--r-- | plugins/MirLua/src/stdafx.h | 4 |
6 files changed, 86 insertions, 11 deletions
diff --git a/plugins/MirLua/src/main.cpp b/plugins/MirLua/src/main.cpp index a374da2daa..59ba4fda87 100644 --- a/plugins/MirLua/src/main.cpp +++ b/plugins/MirLua/src/main.cpp @@ -3,10 +3,14 @@ int hLangpack;
HINSTANCE g_hInstance;
-CMLua *g_mLua;
+CMLua *mLua;
HANDLE hCommonFolderPath;
HANDLE hCustomFolderPath;
+#ifdef _DEBUG
+HANDLE hConsole = NULL;
+#endif
+
PLUGININFOEX pluginInfo =
{
sizeof(PLUGININFOEX),
@@ -52,18 +56,31 @@ void LoadScripts(const TCHAR *scriptDir) {
mir_sntprintf(fullPath, _T("%s\\%s"), scriptDir, fd.cFileName);
PathToRelativeT(fullPath, path);
- g_mLua->Load(T2Utf(path));
+ mLua->Load(T2Utf(path));
}
} while (FindNextFile(hFind, &fd));
FindClose(hFind);
}
}
+#include <io.h>
+#include <fcntl.h>
+
extern "C" int __declspec(dllexport) Load(void)
{
mir_getLP(&pluginInfo);
- g_mLua = new CMLua();
+#ifdef _DEBUG
+ if (AllocConsole())
+ {
+ freopen("CONOUT$", "wt", stdout);
+ hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
+ SetConsoleTitle(_T("MirLua Console"));
+ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);
+ }
+#endif
+
+ mLua = new CMLua();
hCommonFolderPath = FoldersRegisterCustomPathT("MirLua", Translate("Common scripts folder"), COMMON_SCRIPTS_PATHT);
hCustomFolderPath = FoldersRegisterCustomPathT("MirLua", Translate("Custom scripts folder"), CUSTOM_SCRIPTS_PATHT);
@@ -73,7 +90,7 @@ extern "C" int __declspec(dllexport) Load(void) LoadScripts(commonScriptDir);
TCHAR customScriptDir[MAX_PATH];
- FoldersGetCustomPathT(hCommonFolderPath, customScriptDir, SIZEOF(customScriptDir), VARST(CUSTOM_SCRIPTS_PATHT));
+ FoldersGetCustomPathT(hCustomFolderPath, customScriptDir, SIZEOF(customScriptDir), VARST(CUSTOM_SCRIPTS_PATHT));
LoadScripts(customScriptDir);
return 0;
@@ -81,7 +98,13 @@ extern "C" int __declspec(dllexport) Load(void) extern "C" int __declspec(dllexport) Unload(void)
{
- delete g_mLua;
+#ifdef _DEBUG
+ if (hConsole)
+ CloseHandle(hConsole);
+ FreeConsole();
+#endif
+
+ delete mLua;
return 0;
}
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index 04200e3777..382591e919 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -5,8 +5,9 @@ CMLua::CMLua() L = luaL_newstate();
luaL_openlibs(L);
- luaL_newlib(L, CMLua::coreFunctions);
- lua_setglobal(L, "M");
+ luaopen_m(L);
+
+ Preload(LUA_CLISTLIBNAME, luaopen_m_clist);
}
CMLua::~CMLua()
@@ -16,7 +17,8 @@ CMLua::~CMLua() void CMLua::Load(const char *path)
{
- luaL_dofile(L, path);
+ if (luaL_dofile(L, path))
+ printf("%s\n", lua_tostring(L, -1));
}
void CMLua::Preload(const char *name, lua_CFunction loader)
diff --git a/plugins/MirLua/src/mlua.h b/plugins/MirLua/src/mlua.h index 7a4ffd036b..f4378c1c57 100644 --- a/plugins/MirLua/src/mlua.h +++ b/plugins/MirLua/src/mlua.h @@ -5,6 +5,9 @@ class CMLua {
private:
lua_State *L;
+ HANDLE hConsole;
+
+ int luaopen_m(lua_State *L);
void Preload(const char *name, lua_CFunction func);
@@ -12,8 +15,6 @@ public: CMLua();
~CMLua();
- static luaL_Reg coreFunctions[10];
-
void Load(const char *name);
};
diff --git a/plugins/MirLua/src/mlua_clist.cpp b/plugins/MirLua/src/mlua_clist.cpp new file mode 100644 index 0000000000..82a36f8241 --- /dev/null +++ b/plugins/MirLua/src/mlua_clist.cpp @@ -0,0 +1,37 @@ +#include "stdafx.h"
+
+static int lua_AddContactMenuItem(lua_State *L)
+{
+ CLISTMENUITEM mi = { sizeof(CLISTMENUITEM) };
+ mi.pszName = LPGEN((char*)luaL_checkstring(L, 1));
+ mi.flags = lua_tointeger(L, 2);
+ mi.position = lua_tointeger(L, 3);
+ mi.icolibItem = (HANDLE)lua_touserdata(L, 4);
+ mi.pszService = (char*)lua_tostring(L, 5);
+
+ HGENMENU res = Menu_AddContactMenuItem(&mi);
+ lua_pushlightuserdata(L, res);
+
+ return 1;
+}
+
+static luaL_Reg clistLib[] =
+{
+ { "AddContactMenuItem", lua_AddContactMenuItem },
+
+ { NULL, NULL }
+};
+
+int luaopen_m_clist(lua_State *L)
+{
+ //luaL_newlib(L, CMLua::clistLib);
+
+ lua_getglobal(L, "M");
+ luaL_checktype(L, -1, LUA_TTABLE);
+
+ lua_newtable(L);
+ luaL_setfuncs(L, clistLib, 0);
+ lua_setfield(L, -2, "CList");
+
+ return 1;
+}
diff --git a/plugins/MirLua/src/mlua_core.cpp b/plugins/MirLua/src/mlua_core.cpp index 7f1bd3cf48..cb80255eb7 100644 --- a/plugins/MirLua/src/mlua_core.cpp +++ b/plugins/MirLua/src/mlua_core.cpp @@ -135,7 +135,7 @@ static int lua_CallService(lua_State *L) return 1;
}
-luaL_Reg CMLua::coreFunctions[10] =
+static luaL_Reg coreLib[] =
{
{ "CreateHookableEvent", lua_CreateHookableEvent },
{ "DestroyHookableEvent", lua_DestroyHookableEvent },
@@ -153,3 +153,11 @@ luaL_Reg CMLua::coreFunctions[10] = { NULL, NULL }
};
+
+int CMLua::luaopen_m(lua_State *L)
+{
+ luaL_newlib(L, coreLib);
+ lua_setglobal(L, "M");
+
+ return 1;
+}
diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index 676028d425..c596d6c029 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -8,6 +8,7 @@ #include <m_utils.h>
#include <m_langpack.h>
#include <m_folders.h>
+#include <m_clist.h>
extern "C"
{
@@ -35,4 +36,7 @@ extern HINSTANCE g_hInstance; #define CUSTOM_SCRIPTS_PATHT MIRANDA_USERDATA "\\Scripts"
#endif
+#define LUA_CLISTLIBNAME "m_clist"
+int luaopen_m_clist(lua_State *L);
+
#endif //_COMMON_H_
|