mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 00:46:07 +00:00
add create functions
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func anyToArgon(x any, quote bool) string {
|
||||
@@ -22,8 +23,31 @@ func anyToArgon(x any, quote bool) string {
|
||||
} else if math.IsInf(num, -1) {
|
||||
return "-infinity"
|
||||
} else {
|
||||
return strconv.FormatFloat(num, 'f', -1, 64)
|
||||
return numberToString(x, 0)
|
||||
}
|
||||
case bool:
|
||||
return strconv.FormatBool(x)
|
||||
case nil:
|
||||
return "null"
|
||||
case ArMap:
|
||||
keys := make([]any, len(x))
|
||||
|
||||
i := 0
|
||||
for k := range x {
|
||||
keys[i] = k
|
||||
i++
|
||||
}
|
||||
output := []string{}
|
||||
for _, key := range keys {
|
||||
output = append(output, anyToArgon(key, true)+": "+anyToArgon(x[key], true))
|
||||
}
|
||||
return "{" + strings.Join(output, ", ") + "}"
|
||||
case builtinFunc:
|
||||
return "<builtin function " + x.name + ">"
|
||||
case Callable:
|
||||
return "<function " + x.name + ">"
|
||||
case ArClass:
|
||||
return anyToArgon(x.value, false)
|
||||
default:
|
||||
return fmt.Sprint(x)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user