From 7359b1846a695cf11f68cad10bd4a31b63466704 Mon Sep 17 00:00:00 2001 From: Evil Factory <36804725+evilfactory@users.noreply.github.com> Date: Wed, 1 Sep 2021 14:08:46 -0300 Subject: [PATCH] dofile, loadfile, require, dostring, load replaced --- .../ServerSource/Lua/LuaSetup.cs | 56 +++++++++++++++---- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs index 4c24557b8..e84cdd319 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs @@ -44,23 +44,25 @@ namespace Barotrauma } } - public void DoString(string code) + public DynValue DoString(string code, Table globalContext = null, string codeStringFriendly = null) { try { - lua.DoString(code); + return lua.DoString(code, globalContext, codeStringFriendly); } catch (Exception e) { HandleLuaException(e); } + + return null; } - public DynValue DoFile(string file) + public DynValue DoFile(string file, Table globalContext=null, string codeStringFriendly = null) { try { - return lua.DoFile(file); + return lua.DoFile(file, globalContext, codeStringFriendly); } catch (Exception e) @@ -72,11 +74,41 @@ namespace Barotrauma } - public DynValue LoadFile(string file) + public DynValue LoadString(string file, Table globalContext = null, string codeStringFriendly = null) { try { - return lua.LoadFile(file); + return lua.LoadString(file, globalContext, codeStringFriendly); + + } + catch (Exception e) + { + HandleLuaException(e); + } + + return null; + } + + public DynValue LoadFile(string file, Table globalContext = null, string codeStringFriendly = null) + { + try + { + return lua.LoadFile(file, globalContext, codeStringFriendly); + + } + catch (Exception e) + { + HandleLuaException(e); + } + + return null; + } + + public DynValue Require(string modname, Table globalContext) + { + try + { + return lua.Call(lua.RequireModule(modname, globalContext)); } catch (Exception e) @@ -169,8 +201,7 @@ namespace Barotrauma UserData.RegisterType(); UserData.RegisterType(); - - lua = new Script(CoreModules.Preset_SoftSandbox | CoreModules.LoadMethods); + lua = new Script(CoreModules.Preset_SoftSandbox); lua.Options.DebugPrint = PrintMessage; @@ -179,9 +210,12 @@ namespace Barotrauma hook = new LuaHook(this); game = new LuaGame(this); - lua.Globals["dofile"] = (Func)DoFile; - lua.Globals["loadfile"] = (Func)LoadFile; - lua.Globals["loadfilesafe"] = null; + lua.Globals["dofile"] = (Func)DoFile; + lua.Globals["loadfile"] = (Func)LoadFile; + lua.Globals["require"] = (Func)Require; + + lua.Globals["dostring"] = (Func)DoString; + lua.Globals["load"] = (Func)LoadString; lua.Globals["Player"] = new LuaPlayer(); lua.Globals["Game"] = game;