mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 08:56:07 +00:00
fix being able to run a script in a parent folder from a child folder
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
@@ -97,7 +98,7 @@ func __runTranslatedImport(translatedImport translatedImport, global ArObject, m
|
||||
return local, ArErr{}
|
||||
}
|
||||
|
||||
func translateImport(realpath string, origin string) (translatedImport, ArErr) {
|
||||
func translateImport(realpath string, origin string, topLevelOnly bool) (translatedImport, ArErr) {
|
||||
extention := filepath.Ext(realpath)
|
||||
path := realpath
|
||||
if extention == "" {
|
||||
@@ -125,9 +126,13 @@ func translateImport(realpath string, origin string) (translatedImport, ArErr) {
|
||||
filepath.Join(currentPath, realpath, "init.ar"),
|
||||
filepath.Join(currentPath, modules_folder, path),
|
||||
filepath.Join(currentPath, modules_folder, realpath, "init.ar"))
|
||||
if topLevelOnly {
|
||||
break
|
||||
}
|
||||
oldPath = currentPath
|
||||
currentPath = filepath.Dir(currentPath)
|
||||
}
|
||||
fmt.Println(pathsToTest)
|
||||
}
|
||||
var p string
|
||||
var found bool
|
||||
|
||||
@@ -56,7 +56,7 @@ func main() {
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
translated, err := translateImport(Args[0], ex)
|
||||
translated, err := translateImport(Args[0], ex, true)
|
||||
if err.EXISTS {
|
||||
panicErr(err)
|
||||
os.Exit(1)
|
||||
|
||||
@@ -80,7 +80,7 @@ func parseGenericImport(code UNPARSEcode, index int, codeline []UNPARSEcode) (Ar
|
||||
}
|
||||
|
||||
if str, ok := toImport.(string); ok {
|
||||
resp, err := translateImport(str, filepath.Dir(filepath.ToSlash(code.path)))
|
||||
resp, err := translateImport(str, filepath.Dir(filepath.ToSlash(code.path)), false)
|
||||
if !err.EXISTS {
|
||||
importOBJ.translated = resp
|
||||
importOBJ.pretranslated = true
|
||||
@@ -102,7 +102,7 @@ func runImport(importOBJ ArImport, stack stack, stacklevel int) (any, ArErr) {
|
||||
return nil, ArErr{"Type Error", "import requires a string, got type '" + typeof(val) + "'", importOBJ.Line, importOBJ.Path, importOBJ.Code, true}
|
||||
}
|
||||
parent := filepath.Dir(filepath.ToSlash(importOBJ.Path))
|
||||
translated, err = translateImport(val.(string), parent)
|
||||
translated, err = translateImport(val.(string), parent, false)
|
||||
if err.EXISTS {
|
||||
if err.line == 0 {
|
||||
err.line = importOBJ.Line
|
||||
|
||||
Reference in New Issue
Block a user