54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
using System.IO;
|
|
|
|
namespace Upsilon.Evaluator
|
|
{
|
|
public class ScriptLoader
|
|
{
|
|
public virtual string FilePath { get; set; } = "./";
|
|
public virtual string ModulesPath { get; set; } = "./modules/";
|
|
|
|
public virtual string LoadFile(string fileName)
|
|
{
|
|
var resolvedName = ResolveFileName(FilePath, fileName);
|
|
if (File.Exists(resolvedName))
|
|
{
|
|
return File.ReadAllText(resolvedName);
|
|
}
|
|
else if (File.Exists(resolvedName + ".yup"))
|
|
{
|
|
return File.ReadAllText(resolvedName + ".yup");
|
|
}
|
|
else if (File.Exists(resolvedName + ".lua"))
|
|
{
|
|
return File.ReadAllText(resolvedName + ".lua");
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public virtual string LoadModule(string fileName)
|
|
{
|
|
var resolvedName = ResolveFileName(ModulesPath, fileName);
|
|
string text = null;
|
|
if (File.Exists(resolvedName))
|
|
{
|
|
text = File.ReadAllText(resolvedName);
|
|
}
|
|
else if (File.Exists(resolvedName + ".yup"))
|
|
{
|
|
text = File.ReadAllText(resolvedName + ".yup");
|
|
}
|
|
else if (File.Exists(resolvedName + ".lua"))
|
|
{
|
|
text = File.ReadAllText(resolvedName + ".lua");
|
|
}
|
|
|
|
return text;
|
|
}
|
|
|
|
|
|
public virtual string ResolveFileName(string path, string fileName)
|
|
{
|
|
return Path.Combine(path, fileName);
|
|
}
|
|
}
|
|
} |