From 2a498d86625f65f6ab308fa20c421099c785bf94 Mon Sep 17 00:00:00 2001 From: aunsane Date: Thu, 22 Mar 2018 01:53:49 +0300 Subject: MirLua: various fixes - CMLua now inherit PLUGIN - additional lua fuctions initialization moved to separated loader - ability to realod script without object recreation - scropt object should control own enable state - fix m_json whit is not workes almost at all - version bump --- plugins/MirLua/src/mlua_script.cpp | 63 +++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 22 deletions(-) (limited to 'plugins/MirLua/src/mlua_script.cpp') diff --git a/plugins/MirLua/src/mlua_script.cpp b/plugins/MirLua/src/mlua_script.cpp index 310fecddf9..83b5008e15 100644 --- a/plugins/MirLua/src/mlua_script.cpp +++ b/plugins/MirLua/src/mlua_script.cpp @@ -28,29 +28,10 @@ CMLuaScript::CMLuaScript(const CMLuaScript &script) CMLuaScript::~CMLuaScript() { - if (status == Loaded) - { - lua_rawgeti(L, LUA_REGISTRYINDEX, unloadRef); - if (lua_isfunction(L, -1)) - luaM_pcall(L); - lua_pushnil(L); - lua_rawsetp(L, LUA_REGISTRYINDEX, this); - status = None; - } - - luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED"); - lua_pushnil(L); - lua_setfield(L, -2, moduleName); - lua_pop(L, 1); - + Unload(); mir_free(moduleName); } -const char* CMLuaScript::GetModuleName() const -{ - return moduleName; -} - const wchar_t* CMLuaScript::GetFilePath() const { return filePath; @@ -61,6 +42,21 @@ const wchar_t* CMLuaScript::GetFileName() const return fileName; } +bool CMLuaScript::IsEnabled() +{ + return db_get_b(NULL, MODULE, _T2A(fileName), 1); +} + +void CMLuaScript::Enable() +{ + db_unset(NULL, MODULE, _T2A(fileName)); +} + +void CMLuaScript::Disable() +{ + db_set_b(NULL, MODULE, _T2A(fileName), 0); +} + CMLuaScript::Status CMLuaScript::GetStatus() const { return status; @@ -85,7 +81,7 @@ bool CMLuaScript::Load() if (lua_isnoneornil(L, -1)) return true; - luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED"); + luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); lua_getfield(L, -1, moduleName); if (!lua_toboolean(L, -1)) { lua_pop(L, 1); @@ -115,4 +111,27 @@ bool CMLuaScript::Load() lua_pop(L, 1); return true; -} \ No newline at end of file +} + +void CMLuaScript::Unload() +{ + if (status == Loaded) { + lua_rawgeti(L, LUA_REGISTRYINDEX, unloadRef); + if (lua_isfunction(L, -1)) + luaM_pcall(L); + lua_pushnil(L); + lua_rawsetp(L, LUA_REGISTRYINDEX, this); + status = None; + } + + luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); + lua_pushnil(L); + lua_setfield(L, -2, moduleName); + lua_pop(L, 1); +} + +bool CMLuaScript::Reload() +{ + Unload(); + return Load(); +} -- cgit v1.2.3