add isClosed to socket

This commit is contained in:
2023-06-22 11:32:33 +01:00
parent 1a2ad64ea4
commit 1d3eaf9990
3 changed files with 12 additions and 10 deletions

View File

@@ -73,18 +73,17 @@ func importMod(realpath string, origin string, main bool, global ArObject) (ArOb
} }
} else { } else {
pathsToTest = []string{ pathsToTest = []string{
filepath.Join(origin, realpath, "init.ar"),
filepath.Join(origin, path), filepath.Join(origin, path),
filepath.Join(origin, realpath, "init.ar"),
filepath.Join(origin, modules_folder, path), filepath.Join(origin, modules_folder, path),
filepath.Join(origin, modules_folder, realpath, "init.ar"), filepath.Join(origin, modules_folder, realpath, "init.ar"),
filepath.Join(ex, path), filepath.Join(ex, path),
filepath.Join(ex, modules_folder, realpath, "init.ar"),
filepath.Join(ex, modules_folder, path), filepath.Join(ex, modules_folder, path),
filepath.Join(executable, modules_folder, realpath, "init.ar"), filepath.Join(ex, modules_folder, realpath, "init.ar"),
filepath.Join(executable, modules_folder, path), filepath.Join(executable, modules_folder, path),
filepath.Join(executable, modules_folder, realpath, "init.ar"),
} }
} }
var p string var p string
var found bool var found bool
for _, p = range pathsToTest { for _, p = range pathsToTest {

View File

@@ -1,7 +1,7 @@
package main package main
import ( import (
"os" "path/filepath"
"strings" "strings"
) )
@@ -84,11 +84,8 @@ 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} return nil, ArErr{"Type Error", "import requires a string, got type '" + typeof(val) + "'", importOBJ.line, importOBJ.path, importOBJ.code, true}
} }
path := val.(string) path := val.(string)
ex, e := os.Getwd() parent := filepath.Dir(importOBJ.path)
if e != nil { stackMap, err := importMod(path, parent, false, stack[0])
return nil, ArErr{"File Error", "could not get current working directory", importOBJ.line, importOBJ.path, importOBJ.code, true}
}
stackMap, err := importMod(path, ex, false, stack[0])
if err.EXISTS { if err.EXISTS {
if err.line == 0 { if err.line == 0 {
err.line = importOBJ.line err.line = importOBJ.line

View File

@@ -127,5 +127,11 @@ func ArSocket(args ...any) (any, ArErr) {
return nil, ArErr{} return nil, ArErr{}
}, },
}, },
"isClosed": builtinFunc{
"isClosed",
func(args ...any) (any, ArErr) {
return ln == nil, ArErr{}
},
},
}), ArErr{} }), ArErr{}
} }