Use correct directory when importing other file

This commit is contained in:
Stone_Red
2022-11-17 11:54:01 +01:00
parent 1ced6f393c
commit e539813314
2 changed files with 6 additions and 0 deletions
@@ -258,6 +258,8 @@ namespace YesNt.Interpreter.Runtime
private bool LoadFile(string path)
{
path = Path.GetFullPath(path);
if (!File.Exists(path))
{
Console.WriteLine($"File \"{path}\" not found!");
@@ -272,6 +274,8 @@ namespace YesNt.Interpreter.Runtime
return false;
}
runtimeInfo.WorkingDirectory = Path.GetDirectoryName(path);
for (int i = 0; i < lines.Length; i++)
{
runtimeInfo.Lines.Add(new Line(lines[i], Path.GetFileName(path), i));
@@ -86,6 +86,8 @@ namespace YesNt.Interpreter.Statements
[Statement("imp", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.Magenta)]
public void Import(string path)
{
path = Path.Combine(RuntimeInfo.WorkingDirectory, path);
if (string.IsNullOrEmpty(Path.GetExtension(path)))
{
path = Path.ChangeExtension(path, "ynt");