fix file loading
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Text;
|
||||
using System.IO;
|
||||
using MoonSharp.Interpreter;
|
||||
using MoonSharp.Interpreter.Loaders;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -11,18 +12,11 @@ namespace Barotrauma
|
||||
|
||||
public class LuaScriptLoader : ScriptLoaderBase
|
||||
{
|
||||
public LuaSetup lua;
|
||||
|
||||
public LuaScriptLoader(LuaSetup l)
|
||||
{
|
||||
lua = l;
|
||||
}
|
||||
|
||||
|
||||
public override object LoadFile(string file, Table globalContext)
|
||||
{
|
||||
if (!LuaFile.IsPathAllowedLuaException(file, false)) return null;
|
||||
|
||||
if (!LuaFile.IsPathAllowedLuaException(file, false)) return null;
|
||||
|
||||
return File.ReadAllText(file);
|
||||
}
|
||||
|
||||
@@ -32,7 +26,6 @@ namespace Barotrauma
|
||||
|
||||
return File.Exists(file);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,6 +126,13 @@ namespace Barotrauma
|
||||
|
||||
public DynValue DoFile(string file, Table globalContext = null, string codeStringFriendly = null)
|
||||
{
|
||||
if (!LuaFile.IsPathAllowedLuaException(file, false)) return null;
|
||||
if (!LuaFile.Exists(file))
|
||||
{
|
||||
HandleLuaException(new Exception($"dofile: File {file} not found."));
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return lua.DoFile(file, globalContext, codeStringFriendly);
|
||||
@@ -157,6 +164,13 @@ namespace Barotrauma
|
||||
|
||||
public DynValue LoadFile(string file, Table globalContext = null, string codeStringFriendly = null)
|
||||
{
|
||||
if (!LuaFile.IsPathAllowedLuaException(file, false)) return null;
|
||||
if (!LuaFile.Exists(file))
|
||||
{
|
||||
HandleLuaException(new Exception($"loadfile: File {file} not found."));
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return lua.LoadFile(file, globalContext, codeStringFriendly);
|
||||
@@ -223,7 +237,7 @@ namespace Barotrauma
|
||||
|
||||
PrintMessage("Lua! Version " + AssemblyInfo.GitRevision);
|
||||
|
||||
luaScriptLoader = new LuaScriptLoader(this);
|
||||
luaScriptLoader = new LuaScriptLoader();
|
||||
luaScriptLoader.ModulePaths = new string[] { };
|
||||
|
||||
LuaCustomConverters.RegisterAll();
|
||||
|
||||
Reference in New Issue
Block a user