mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 00:46:07 +00:00
add path
This commit is contained in:
@@ -335,5 +335,6 @@ func makeGlobal() ArObject {
|
||||
}
|
||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot get max of type '" + typeof(a[0]) + "'", EXISTS: true}
|
||||
}}
|
||||
vars["path"] = ArPath
|
||||
return Map(vars)
|
||||
}
|
||||
|
||||
@@ -116,6 +116,13 @@ func ArRead(args ...any) (any, ArErr) {
|
||||
}
|
||||
return newNumber().SetInt64(info.Size()), ArErr{}
|
||||
}},
|
||||
"ModTime": builtinFunc{"ModTime", func(...any) (any, ArErr) {
|
||||
info, err := file.Stat()
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
return ArTimeClass(info.ModTime()), ArErr{}
|
||||
}},
|
||||
}), ArErr{}
|
||||
}
|
||||
|
||||
|
||||
76
src/path.go
Normal file
76
src/path.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
var ArPath = Map(
|
||||
anymap{
|
||||
"ReadDir": builtinFunc{
|
||||
"ReadDir",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "ReadDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
args[0] = ArValidToAny(args[0])
|
||||
if typeof(args[0]) != "string" {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "ReadDir argument must be a string, got " + typeof(args[0]),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
files, err := os.ReadDir(args[0].(string))
|
||||
if err != nil {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: err.Error(),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
var ret []any
|
||||
for _, file := range files {
|
||||
ret = append(ret, file.Name())
|
||||
}
|
||||
return ret, ArErr{}
|
||||
}},
|
||||
"join": builtinFunc{
|
||||
"join",
|
||||
func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "join takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
args[0] = ArValidToAny(args[0])
|
||||
switch arr := args[0].(type) {
|
||||
case []any:
|
||||
var Path []string
|
||||
for _, x := range arr {
|
||||
x = ArValidToAny(x)
|
||||
if typeof(x) != "string" {
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "join argument must be an array of strings, got " + typeof(x),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
Path = append(Path, x.(string))
|
||||
}
|
||||
return path.Join(Path...), ArErr{}
|
||||
}
|
||||
return nil, ArErr{
|
||||
TYPE: "runtime",
|
||||
message: "join argument must be an array, got " + typeof(args[0]),
|
||||
EXISTS: true,
|
||||
}
|
||||
}},
|
||||
})
|
||||
@@ -80,7 +80,7 @@ var ArTerm = Map(anymap{
|
||||
}},
|
||||
}),
|
||||
"error": builtinFunc{"error", func(args ...any) (any, ArErr) {
|
||||
output := []any{"error: "}
|
||||
output := []any{}
|
||||
for i := 0; i < len(args); i++ {
|
||||
output = append(output, anyToArgon(args[i], false, true, 3, 0, false, 0))
|
||||
}
|
||||
@@ -89,7 +89,7 @@ var ArTerm = Map(anymap{
|
||||
},
|
||||
},
|
||||
"warn": builtinFunc{"error", func(args ...any) (any, ArErr) {
|
||||
output := []any{"warning: "}
|
||||
output := []any{}
|
||||
for i := 0; i < len(args); i++ {
|
||||
output = append(output, anyToArgon(args[i], false, true, 3, 0, false, 0))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user