From f4258bb6d37d16a673c268376e0dff1958c34f82 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Fri, 23 Oct 2015 22:27:49 +0000 Subject: MirLua: - m_core is available as usual module - options page moved to Services/MirLua/Scripts - code cleaning - version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@15602 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/m_core.cpp | 6 ++++-- plugins/MirLua/src/mlua.cpp | 10 ++++------ plugins/MirLua/src/mlua_module_loader.cpp | 12 ++++++++++-- plugins/MirLua/src/mlua_options.cpp | 5 +++-- plugins/MirLua/src/mlua_script_loader.cpp | 19 +++++++++++++++---- plugins/MirLua/src/stdafx.h | 4 ++-- plugins/MirLua/src/version.h | 2 +- 7 files changed, 39 insertions(+), 19 deletions(-) (limited to 'plugins/MirLua') diff --git a/plugins/MirLua/src/m_core.cpp b/plugins/MirLua/src/m_core.cpp index b2f6beda2a..b3c5afc73f 100644 --- a/plugins/MirLua/src/m_core.cpp +++ b/plugins/MirLua/src/m_core.cpp @@ -260,14 +260,16 @@ luaL_Reg coreApi[] = { NULL, NULL } }; -LUAMOD_API int luaopen_m(lua_State *L) +LUAMOD_API int luaopen_m_core(lua_State *L) { luaL_newlib(L, coreApi); lua_pushlightuserdata(L, NULL); lua_setfield(L, -2, "NULL"); lua_pushlightuserdata(L, INVALID_HANDLE_VALUE); lua_setfield(L, -2, "INVALID_HANDLE_VALUE"); - lua_setglobal(L, MLUA_CORE); + // set copy to global variable m + lua_pushvalue(L, -1); + lua_setglobal(L, "m"); return 1; } \ No newline at end of file diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index 15bd34fe2d..6a54f92592 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -34,16 +34,14 @@ void CMLua::Load() lua_setfield(L, -2, "cpath"); lua_pop(L, 1); - lua_getglobal(L, "_G"); lua_pushcclosure(L, luaM_print, 0); - lua_setfield(L, -2, "print"); + lua_setglobal(L, "print"); lua_pushcclosure(L, luaM_toansi, 0); - lua_setfield(L, -2, "a"); + lua_setglobal(L,"a"); lua_pushcclosure(L, luaM_toucs2, 0); - lua_setfield(L, -2, "u"); + lua_setglobal(L, "u"); lua_pushcclosure(L, luaM_totable, 0); - lua_setfield(L, -2, "totable"); - lua_pop(L, 1); + lua_setglobal(L, "totable"); lua_atpanic(L, luaM_atpanic); diff --git a/plugins/MirLua/src/mlua_module_loader.cpp b/plugins/MirLua/src/mlua_module_loader.cpp index 4e82793a61..a236a76691 100644 --- a/plugins/MirLua/src/mlua_module_loader.cpp +++ b/plugins/MirLua/src/mlua_module_loader.cpp @@ -14,9 +14,8 @@ void CLuaModuleLoader::PreloadModule(const char *name, lua_CFunction loader) void CLuaModuleLoader::LoadModules() { - // load core module - luaopen_m(L); // regirter delay loading of miranda modules + PreloadModule(MLUA_CORE, luaopen_m_core); PreloadModule(MLUA_CLIST, luaopen_m_clist); PreloadModule(MLUA_DATABASE, luaopen_m_database); PreloadModule(MLUA_ICOLIB, luaopen_m_icolib); @@ -29,6 +28,15 @@ void CLuaModuleLoader::LoadModules() PreloadModule(MLUA_TOPTOOLBAR, luaopen_m_toptoolbar); PreloadModule(MLUA_VARIABLES, luaopen_m_variables); PreloadModule(MLUA_WINDOWS, luaopen_m_windows); + + // load m_core module + lua_pushglobaltable(L); + lua_getfield(L, -1, "require"); + lua_pushstring(L, "m_core"); + if (lua_pcall(L, 1, 1, 0)) + CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1)); + lua_pop(L, 1); + lua_pop(L, 1); } void CLuaModuleLoader::Load(lua_State *L) diff --git a/plugins/MirLua/src/mlua_options.cpp b/plugins/MirLua/src/mlua_options.cpp index e3ecd89092..e6bcbbd0c3 100644 --- a/plugins/MirLua/src/mlua_options.cpp +++ b/plugins/MirLua/src/mlua_options.cpp @@ -40,8 +40,9 @@ int CLuaOptions::OnOptionsInit(WPARAM wParam, LPARAM) { OPTIONSDIALOGPAGE odp = { 0 }; odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR | ODPF_DONTTRANSLATE; - odp.ptszGroup = LPGENT("Scripts"); - odp.ptszTitle = _T("Lua"); + odp.ptszGroup = LPGENT("Services"); + odp.ptszTitle = _T(MODULE); + odp.ptszTab = LPGENT("Scripts"); odp.pDialog = CLuaOptions::CreateOptionsPage(); Options_AddPage(wParam, &odp); diff --git a/plugins/MirLua/src/mlua_script_loader.cpp b/plugins/MirLua/src/mlua_script_loader.cpp index 34ee40256c..9f83d6b9cb 100644 --- a/plugins/MirLua/src/mlua_script_loader.cpp +++ b/plugins/MirLua/src/mlua_script_loader.cpp @@ -27,7 +27,16 @@ void CLuaScriptLoader::LoadScript(const TCHAR *scriptDir, const TCHAR *file, int CMLuaScript *script = new CMLuaScript(L, path, iGroup); g_mLua->Scripts.insert(script); - if (db_get_b(NULL, MODULE, _T2A(file), 1) && script->Load()) + TCHAR buf[4096]; + if (db_get_b(NULL, MODULE, _T2A(file), 1) == FALSE) + { + + mir_sntprintf(buf, _T("%s:PASS"), path); + CallService(MS_NETLIB_LOGW, (WPARAM)hNetlib, (LPARAM)buf); + return; + } + + if (script->Load()) { TCHAR buf[4096]; mir_sntprintf(buf, _T("%s:OK"), path); @@ -51,9 +60,11 @@ void CLuaScriptLoader::LoadScripts(const TCHAR *scriptDir, int iGroup) if (hFind != INVALID_HANDLE_VALUE) { do - if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) - LoadScript(scriptDir, fd.cFileName, iGroup); - while (FindNextFile(hFind, &fd)); + { + if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + continue; + LoadScript(scriptDir, fd.cFileName, iGroup); + } while (FindNextFile(hFind, &fd)); FindClose(hFind); } } diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index 2fd13a061d..72ed4cc247 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -65,8 +65,8 @@ extern HANDLE hNetlib; #define COMMON_SCRIPTS_PATHT MIRANDA_PATH "\\Scripts" #endif -#define MLUA_CORE "m" -LUAMOD_API int (luaopen_m)(lua_State *L); +#define MLUA_CORE "m_core" +LUAMOD_API int (luaopen_m_core)(lua_State *L); #define MLUA_CLIST "m_clist" LUAMOD_API int (luaopen_m_clist)(lua_State *L); diff --git a/plugins/MirLua/src/version.h b/plugins/MirLua/src/version.h index 086f2b7388..0f8628a7e7 100644 --- a/plugins/MirLua/src/version.h +++ b/plugins/MirLua/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 11 #define __RELEASE_NUM 5 -#define __BUILD_NUM 0 +#define __BUILD_NUM 1 #include -- cgit v1.2.3