From 3af4bb5ed2c17d17ecc8073cd233277ed8541cf1 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Thu, 18 Jun 2015 15:27:08 +0000 Subject: MirLua: scripts reloading pt.1 git-svn-id: http://svn.miranda-ng.org/main/trunk@14245 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/mlua.cpp | 89 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 68 insertions(+), 21 deletions(-) (limited to 'plugins/MirLua/src/mlua.cpp') diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index 9c5f9a8906..5945947441 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -1,6 +1,16 @@ #include "stdafx.h" CMLua::CMLua() : L(NULL) +{ + Load(); +} + +CMLua::~CMLua() +{ + Unload(); +} + +void CMLua::Load() { L = luaL_newstate(); luaL_openlibs(L); @@ -12,27 +22,72 @@ CMLua::CMLua() : L(NULL) lua_setfield(L, -2, "cpath"); lua_pop(L, 1); + LoadMirandaModules(); +} + +void CMLua::Unload() +{ + if (L) + lua_close(L); +} + +void CMLua::Reload() +{ + /*lua_getglobal(L, "m"); + lua_getfield(L, -1, "OnPreShutdown"); + if (lua_isfunction(L, -1)) + { + lua_pushlightuserdata(L, NULL); + lua_pushlightuserdata(L, NULL); + if (lua_pcall(L, 2, 1, 0)) + printf("%s\n", lua_tostring(L, -1)); + } + lua_pop(L, 1);*/ + Unload(); + + Load(); + /*lua_getglobal(L, "m"); + lua_getfield(L, -1, "OnModulesLoaded"); + if (lua_isfunction(L, -1)) + { + lua_pushlightuserdata(L, NULL); + lua_pushlightuserdata(L, NULL); + if (lua_pcall(L, 2, 1, 0)) + printf("%s\n", lua_tostring(L, -1)); + } + lua_pop(L, 1);*/ +} + +void CMLua::LoadModule(const char *name, lua_CFunction loader) +{ + luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); + lua_pushcfunction(L, loader); + lua_setfield(L, -2, name); + lua_pop(L, 1); +} + +void CMLua::LoadCoreModule() +{ luaL_newlib(L, coreLib); lua_pushlightuserdata(L, NULL); lua_setfield(L, -2, "NULL"); lua_setglobal(L, "m"); - - Preload(MLUA_DATABASE, luaopen_m_database); - Preload(MLUA_ICOLIB, luaopen_m_icolib); - Preload(MLUA_GENMENU, luaopen_m_genmenu); - Preload(MLUA_MSGBUTTONSBAR, luaopen_m_msg_buttonsbar); - Preload(MLUA_POPUP, luaopen_m_popup); - Preload(MLUA_TOPTOOLBAR, luaopen_m_toptoolbar); - Preload(MLUA_VARIABLES, luaopen_m_variables); } -CMLua::~CMLua() +void CMLua::LoadMirandaModules() { - if(L) - lua_close(L); + LoadCoreModule(); + + LoadModule(MLUA_DATABASE, luaopen_m_database); + LoadModule(MLUA_ICOLIB, luaopen_m_icolib); + LoadModule(MLUA_GENMENU, luaopen_m_genmenu); + LoadModule(MLUA_MSGBUTTONSBAR, luaopen_m_msg_buttonsbar); + LoadModule(MLUA_POPUP, luaopen_m_popup); + LoadModule(MLUA_TOPTOOLBAR, luaopen_m_toptoolbar); + LoadModule(MLUA_VARIABLES, luaopen_m_variables); } -void CMLua::AddPath(const char *path) +void CMLua::AddScriptsPath(const char *path) { lua_getglobal(L, "package"); lua_getfield(L, -1, "path"); @@ -43,20 +98,12 @@ void CMLua::AddPath(const char *path) lua_pop(L, 1); } -void CMLua::Load(const char *path) +void CMLua::LoadScript(const char *path) { if (luaL_dofile(L, path)) printf("%s\n", lua_tostring(L, -1)); } -void CMLua::Preload(const char *name, lua_CFunction loader) -{ - luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); - lua_pushcfunction(L, loader); - lua_setfield(L, -2, name); - lua_pop(L, 1); -} - WPARAM CMLua::GetWParam(lua_State *L, int idx) { WPARAM wParam = NULL; -- cgit v1.2.3