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_loader.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'plugins/MirLua/src/mlua_script_loader.cpp') diff --git a/plugins/MirLua/src/mlua_script_loader.cpp b/plugins/MirLua/src/mlua_script_loader.cpp index 60ceb5cbb5..95701b4559 100644 --- a/plugins/MirLua/src/mlua_script_loader.cpp +++ b/plugins/MirLua/src/mlua_script_loader.cpp @@ -1,9 +1,27 @@ #include "stdafx.h" -CMLuaScriptLoader::CMLuaScriptLoader(lua_State *L) : L(L) +CMLuaScriptLoader::CMLuaScriptLoader(lua_State *L) + : L(L) { } +void CMLuaScriptLoader::SetPaths() +{ + wchar_t path[MAX_PATH]; + + lua_getglobal(L, LUA_LOADLIBNAME); + + FoldersGetCustomPathT(g_hCLibsFolder, path, _countof(path), VARSW(MIRLUA_PATHT)); + lua_pushfstring(L, "%s\\?.dll", T2Utf(path)); + lua_setfield(L, -2, "cpath"); + + FoldersGetCustomPathT(g_hScriptsFolder, path, _countof(path), VARSW(MIRLUA_PATHT)); + lua_pushfstring(L, "%s\\?.lua", T2Utf(path)); + lua_setfield(L, -2, "path"); + + lua_pop(L, 1); +} + void CMLuaScriptLoader::LoadScript(const wchar_t *scriptDir, const wchar_t *file) { wchar_t fullPath[MAX_PATH], path[MAX_PATH]; @@ -13,7 +31,7 @@ void CMLuaScriptLoader::LoadScript(const wchar_t *scriptDir, const wchar_t *file CMLuaScript *script = new CMLuaScript(L, path); g_mLua->Scripts.insert(script); - if (db_get_b(NULL, MODULE, _T2A(file), 1) == FALSE) { + if (!script->IsEnabled()) { Log(L"%s:PASS", path); return; } @@ -24,6 +42,8 @@ void CMLuaScriptLoader::LoadScript(const wchar_t *scriptDir, const wchar_t *file void CMLuaScriptLoader::LoadScripts() { + SetPaths(); + wchar_t scriptDir[MAX_PATH]; FoldersGetCustomPathT(g_hScriptsFolder, scriptDir, _countof(scriptDir), VARSW(MIRLUA_PATHT)); -- cgit v1.2.3