fix up inconsistent error types

This commit is contained in:
2024-04-09 19:22:43 +01:00
parent 42e12933bf
commit a8fb5d4c1f
15 changed files with 273 additions and 279 deletions

View File

@@ -31,21 +31,21 @@ func ArArray(arr []any) ArObject {
func(a ...any) (any, ArErr) {
if len(a) != 2 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected 2 arguments, got " + fmt.Sprint(len(a)),
EXISTS: true,
}
}
if typeof(a[0]) != "number" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "dex must be a number",
EXISTS: true,
}
}
if !a[0].(number).IsInt() {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "index must be an integer",
EXISTS: true,
}
@@ -53,7 +53,7 @@ func ArArray(arr []any) ArObject {
num := int(a[0].(number).Num().Int64())
if num < 0 || num >= len(arr) {
return nil, ArErr{
TYPE: "IndexError",
TYPE: "Index Error",
message: "index out of range",
EXISTS: true,
}
@@ -69,7 +69,7 @@ func ArArray(arr []any) ArObject {
// a[1] is end
// a[2] is step
if len(a) > 3 {
return nil, ArErr{"TypeError", "expected 1 to 3 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 to 3 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
var (
start int = 0
@@ -81,7 +81,7 @@ func ArArray(arr []any) ArObject {
start = 0
} else if typeof(a[0]) != "number" || !a[0].(number).IsInt() {
return "", ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "slice index must be an integer",
EXISTS: true,
}
@@ -94,7 +94,7 @@ func ArArray(arr []any) ArObject {
end = len(arr)
} else if typeof(a[1]) != "number" || !a[1].(number).IsInt() {
return "", ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "slice index must be an integer",
EXISTS: true,
}
@@ -107,7 +107,7 @@ func ArArray(arr []any) ArObject {
step = 1
} else if typeof(a[2]) != "number" || !a[2].(number).IsInt() {
return "", ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "slice index must be an integer",
EXISTS: true,
}
@@ -127,7 +127,7 @@ func ArArray(arr []any) ArObject {
}
if start >= len(arr) || start < 0 {
return "", ArErr{
TYPE: "IndexError",
TYPE: "Index Error",
message: "index out of range, trying to access index " + fmt.Sprint(ogStart) + " in array of length " + fmt.Sprint(len(arr)),
EXISTS: true,
}
@@ -155,21 +155,21 @@ func ArArray(arr []any) ArObject {
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "missing argument",
EXISTS: true,
}
}
if typeof(args[0]) != "number" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "argument must be a number",
EXISTS: true,
}
}
if !args[0].(number).IsInt() {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "argument must be an integer",
EXISTS: true,
}
@@ -177,7 +177,7 @@ func ArArray(arr []any) ArObject {
num := int(args[0].(number).Num().Int64())
if num < 0 || num >= len(arr) {
return nil, ArErr{
TYPE: "IndexError",
TYPE: "Index Error",
message: "index out of range",
EXISTS: true,
}
@@ -192,7 +192,7 @@ func ArArray(arr []any) ArObject {
func(args ...any) (any, ArErr) {
if len(args) == 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "missing argument",
EXISTS: true,
}
@@ -208,21 +208,21 @@ func ArArray(arr []any) ArObject {
func(args ...any) (any, ArErr) {
if len(args) < 2 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "missing argument",
EXISTS: true,
}
}
if typeof(args[0]) != "number" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "argument must be a number",
EXISTS: true,
}
}
if !args[0].(number).IsInt() {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "argument must be an integer",
EXISTS: true,
}
@@ -230,7 +230,7 @@ func ArArray(arr []any) ArObject {
num := int(args[0].(number).Num().Int64())
if num < 0 || num > len(arr) {
return nil, ArErr{
TYPE: "IndexError",
TYPE: "Index Error",
message: "index out of range",
EXISTS: true,
}
@@ -246,7 +246,7 @@ func ArArray(arr []any) ArObject {
func(args ...any) (any, ArErr) {
if len(args) > 1 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "too many arguments",
EXISTS: true,
}
@@ -254,14 +254,14 @@ func ArArray(arr []any) ArObject {
if len(args) == 1 {
if typeof(args[0]) != "number" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "argument must be a number",
EXISTS: true,
}
}
if !args[0].(number).IsInt() {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "argument must be an integer",
EXISTS: true,
}
@@ -269,7 +269,7 @@ func ArArray(arr []any) ArObject {
num := int(args[0].(number).Num().Int64())
if num < 0 || num >= len(arr) {
return nil, ArErr{
TYPE: "IndexError",
TYPE: "Index Error",
message: "index out of range",
EXISTS: true,
}
@@ -292,7 +292,7 @@ func ArArray(arr []any) ArObject {
func(args ...any) (any, ArErr) {
if len(args) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "too many arguments",
EXISTS: true,
}
@@ -308,14 +308,14 @@ func ArArray(arr []any) ArObject {
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "missing argument",
EXISTS: true,
}
}
if typeof(args[0]) != "array" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "argument must be an array",
EXISTS: true,
}
@@ -331,7 +331,7 @@ func ArArray(arr []any) ArObject {
func(args ...any) (any, ArErr) {
if len(args) > 2 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "too many arguments",
EXISTS: true,
}
@@ -340,7 +340,7 @@ func ArArray(arr []any) ArObject {
if len(args) >= 1 {
if typeof(args[0]) != "boolean" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "argument must be a boolean",
EXISTS: true,
}
@@ -350,7 +350,7 @@ func ArArray(arr []any) ArObject {
if len(args) == 2 {
if typeof(args[1]) != "function" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "argument must be a function",
EXISTS: true,
}
@@ -396,14 +396,14 @@ func ArArray(arr []any) ArObject {
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "missing argument",
EXISTS: true,
}
}
if typeof(args[0]) != "function" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "argument must be a function",
EXISTS: true,
}
@@ -427,14 +427,14 @@ func ArArray(arr []any) ArObject {
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "missing argument",
EXISTS: true,
}
}
if typeof(args[0]) != "function" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "argument must be a function",
EXISTS: true,
}
@@ -460,14 +460,14 @@ func ArArray(arr []any) ArObject {
func(args ...any) (any, ArErr) {
if len(args) != 2 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "missing argument, expected 2 got " + fmt.Sprint(len(args)),
EXISTS: true,
}
}
if typeof(args[0]) != "function" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "argument must be a function",
EXISTS: true,
}
@@ -498,14 +498,14 @@ func ArArray(arr []any) ArObject {
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "missing argument",
EXISTS: true,
}
}
if typeof(args[0]) != "string" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "argument must be a string",
EXISTS: true,
}
@@ -514,7 +514,7 @@ func ArArray(arr []any) ArObject {
for _, v := range arr {
if typeof(v) != "string" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "array must be an array of strings",
EXISTS: true,
}
@@ -529,14 +529,14 @@ func ArArray(arr []any) ArObject {
func(args ...any) (any, ArErr) {
if len(args) < 1 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "missing argument(s)",
EXISTS: true,
}
}
if typeof(args[0]) != "array" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "argument must be an array",
EXISTS: true,
}
@@ -550,7 +550,7 @@ func ArArray(arr []any) ArObject {
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "missing argument",
EXISTS: true,
}
@@ -580,7 +580,7 @@ func ArArray(arr []any) ArObject {
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "missing argument",
EXISTS: true,
}
@@ -605,7 +605,7 @@ func ArArray(arr []any) ArObject {
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "missing argument",
EXISTS: true,
}

View File

@@ -35,7 +35,7 @@ func ArByte(Byte byte) ArObject {
func(a ...any) (any, ArErr) {
if len(a) == 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected at least 1 argument, got 0",
EXISTS: true,
}
@@ -45,7 +45,7 @@ func ArByte(Byte byte) ArObject {
case number:
if x.Denom().Cmp(one.Denom()) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected integer, got " + fmt.Sprint(x),
EXISTS: true,
}
@@ -70,7 +70,7 @@ func ArByte(Byte byte) ArObject {
Byte = byte(x[0])
default:
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected number or string, got " + typeof(x),
EXISTS: true,
}
@@ -106,7 +106,7 @@ func ArBuffer(buf []byte) ArObject {
func(a ...any) (any, ArErr) {
if len(a) == 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected at least 1 argument, got 0",
EXISTS: true,
}
@@ -124,7 +124,7 @@ func ArBuffer(buf []byte) ArObject {
case number:
if y.Denom().Cmp(one.Denom()) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "Cannot convert non-integer to byte",
EXISTS: true,
}
@@ -132,7 +132,7 @@ func ArBuffer(buf []byte) ArObject {
outputbuf = append(outputbuf, byte(y.Num().Int64()))
default:
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "Cannot convert " + typeof(v) + " to byte",
EXISTS: true,
}
@@ -141,7 +141,7 @@ func ArBuffer(buf []byte) ArObject {
buf = outputbuf
default:
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected string or buffer, got " + typeof(x),
EXISTS: true,
}
@@ -156,7 +156,7 @@ func ArBuffer(buf []byte) ArObject {
func(a ...any) (any, ArErr) {
if len(a) != 2 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
EXISTS: true,
}
@@ -164,7 +164,7 @@ func ArBuffer(buf []byte) ArObject {
splitVal := ArValidToAny(a[0])
if typeof(splitVal) != "buffer" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected buffer, got " + typeof(splitVal),
EXISTS: true,
}
@@ -173,7 +173,7 @@ func ArBuffer(buf []byte) ArObject {
nVal := ArValidToAny(a[1])
if typeof(nVal) != "number" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected number, got " + typeof(nVal),
EXISTS: true,
}
@@ -181,7 +181,7 @@ func ArBuffer(buf []byte) ArObject {
nNum := nVal.(number)
if nNum.Denom().Cmp(one.Denom()) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected integer, got " + fmt.Sprint(nNum),
EXISTS: true,
}
@@ -216,7 +216,7 @@ func ArBuffer(buf []byte) ArObject {
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
EXISTS: true,
}
@@ -224,7 +224,7 @@ func ArBuffer(buf []byte) ArObject {
splitVal := ArValidToAny(a[0])
if typeof(splitVal) != "buffer" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected buffer, got " + typeof(splitVal),
EXISTS: true,
}
@@ -255,7 +255,7 @@ func ArBuffer(buf []byte) ArObject {
func(a ...any) (any, ArErr) {
if len(a) != 2 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected 2 arguments, got " + fmt.Sprint(len(a)),
EXISTS: true,
}
@@ -263,7 +263,7 @@ func ArBuffer(buf []byte) ArObject {
startVal := ArValidToAny(a[0])
if typeof(startVal) != "number" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected number, got " + typeof(startVal),
EXISTS: true,
}
@@ -271,7 +271,7 @@ func ArBuffer(buf []byte) ArObject {
start := startVal.(number)
if start.Denom().Cmp(one.Denom()) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected integer, got " + fmt.Sprint(start),
EXISTS: true,
}
@@ -279,7 +279,7 @@ func ArBuffer(buf []byte) ArObject {
endVal := ArValidToAny(a[1])
if typeof(endVal) != "number" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected number, got " + typeof(endVal),
EXISTS: true,
}
@@ -287,7 +287,7 @@ func ArBuffer(buf []byte) ArObject {
end := endVal.(number)
if end.Denom().Cmp(one.Denom()) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected integer, got " + fmt.Sprint(end),
EXISTS: true,
}
@@ -300,14 +300,14 @@ func ArBuffer(buf []byte) ArObject {
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
EXISTS: true,
}
}
if typeof(a[0]) != "string" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected string, got " + typeof(a[0]),
EXISTS: true,
}
@@ -330,7 +330,7 @@ func ArBuffer(buf []byte) ArObject {
return ArArray(output), ArErr{}
default:
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected string, bytes or array, got '" + Type + "'",
EXISTS: true,
}
@@ -342,7 +342,7 @@ func ArBuffer(buf []byte) ArObject {
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
EXISTS: true,
}
@@ -352,7 +352,7 @@ func ArBuffer(buf []byte) ArObject {
case number:
if x.Denom().Cmp(one.Denom()) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "Cannot convert non-integer to byte",
EXISTS: true,
}
@@ -368,7 +368,7 @@ func ArBuffer(buf []byte) ArObject {
case number:
if y.Denom().Cmp(one.Denom()) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "Cannot convert non-integer to byte",
EXISTS: true,
}
@@ -376,7 +376,7 @@ func ArBuffer(buf []byte) ArObject {
buf = append(buf, byte(y.Num().Int64()))
default:
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "Cannot convert " + typeof(v) + " to byte",
EXISTS: true,
}
@@ -384,7 +384,7 @@ func ArBuffer(buf []byte) ArObject {
}
default:
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected string, buffer or array, got " + typeof(x),
EXISTS: true,
}
@@ -399,7 +399,7 @@ func ArBuffer(buf []byte) ArObject {
func(a ...any) (any, ArErr) {
if len(a) != 2 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected 2 arguments, got " + fmt.Sprint(len(a)),
EXISTS: true,
}
@@ -408,7 +408,7 @@ func ArBuffer(buf []byte) ArObject {
values := ArValidToAny(a[1])
if typeof(poss) != "number" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected number, got " + typeof(poss),
EXISTS: true,
}
@@ -416,7 +416,7 @@ func ArBuffer(buf []byte) ArObject {
pos := poss.(number)
if pos.Denom().Cmp(one.Denom()) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "position must be an integer",
EXISTS: true,
}
@@ -426,7 +426,7 @@ func ArBuffer(buf []byte) ArObject {
case number:
if x.Denom().Cmp(one.Denom()) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "Cannot convert non-integer to byte",
EXISTS: true,
}
@@ -442,7 +442,7 @@ func ArBuffer(buf []byte) ArObject {
case number:
if y.Denom().Cmp(one.Denom()) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "Cannot convert non-integer to byte",
EXISTS: true,
}
@@ -450,7 +450,7 @@ func ArBuffer(buf []byte) ArObject {
buf = append(buf[:posNum], append([]byte{byte(y.Num().Int64())}, buf[posNum:]...)...)
default:
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "Cannot convert " + typeof(v) + " to byte",
EXISTS: true,
}
@@ -458,7 +458,7 @@ func ArBuffer(buf []byte) ArObject {
}
default:
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected string or buffer, got " + typeof(x),
EXISTS: true,
}
@@ -473,7 +473,7 @@ func ArBuffer(buf []byte) ArObject {
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
EXISTS: true,
}
@@ -481,7 +481,7 @@ func ArBuffer(buf []byte) ArObject {
poss := ArValidToAny(a[0])
if typeof(poss) != "number" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected number, got " + typeof(poss),
EXISTS: true,
}
@@ -489,7 +489,7 @@ func ArBuffer(buf []byte) ArObject {
pos := poss.(number)
if pos.Denom().Cmp(one.Denom()) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "position must be an integer",
EXISTS: true,
}

View File

@@ -33,7 +33,7 @@ func makeGlobal() ArObject {
case []any:
if len(y) == 2 {
if isUnhashable(y[0]) {
return nil, ArErr{TYPE: "TypeError", message: "Cannot use unhashable value as key: " + typeof(y[0]), EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot use unhashable value as key: " + typeof(y[0]), EXISTS: true}
}
key := ArValidToAny(y[0])
newmap[key] = y[1]
@@ -57,32 +57,32 @@ func makeGlobal() ArObject {
}
return Map(newmap), ArErr{}
}
return nil, ArErr{TYPE: "TypeError", message: "Cannot create map from '" + typeof(a[0]) + "'", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot create map from '" + typeof(a[0]) + "'", EXISTS: true}
}}
vars["hex"] = builtinFunc{"hex", func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{TYPE: "TypeError", message: "expected 1 argument, got " + fmt.Sprint(len(a)), EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "expected 1 argument, got " + fmt.Sprint(len(a)), EXISTS: true}
}
a[0] = ArValidToAny(a[0])
switch x := a[0].(type) {
case number:
if x.Denom().Cmp(one.Denom()) != 0 {
return nil, ArErr{TYPE: "TypeError", message: "Cannot convert non-integer to hex", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot convert non-integer to hex", EXISTS: true}
}
n := x.Num().Int64()
return ArString(fmt.Sprintf("%x", n)), ArErr{}
}
return nil, ArErr{TYPE: "TypeError", message: "Cannot convert '" + typeof(a[0]) + "' to hex", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot convert '" + typeof(a[0]) + "' to hex", EXISTS: true}
}}
vars["buffer"] = builtinFunc{"buffer", func(a ...any) (any, ArErr) {
if len(a) != 0 {
return nil, ArErr{TYPE: "TypeError", message: "expected 0 arguments, got " + fmt.Sprint(len(a)), EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "expected 0 arguments, got " + fmt.Sprint(len(a)), EXISTS: true}
}
return ArBuffer([]byte{}), ArErr{}
}}
vars["byte"] = builtinFunc{"byte", func(a ...any) (any, ArErr) {
if len(a) != 0 {
return nil, ArErr{TYPE: "TypeError", message: "expected 0 arguments, got " + fmt.Sprint(len(a)), EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "expected 0 arguments, got " + fmt.Sprint(len(a)), EXISTS: true}
}
return ArByte(0), ArErr{}
}}
@@ -109,7 +109,7 @@ func makeGlobal() ArObject {
}
return ArArray(newarray), ArErr{}
}
return nil, ArErr{TYPE: "TypeError", message: "Cannot create array from '" + typeof(a[0]) + "'", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot create array from '" + typeof(a[0]) + "'", EXISTS: true}
}}
vars["boolean"] = builtinFunc{"boolean", func(a ...any) (any, ArErr) {
if len(a) == 0 {
@@ -136,11 +136,11 @@ func makeGlobal() ArObject {
switch x := a[1].(type) {
case number:
if !x.IsInt() {
return nil, ArErr{TYPE: "TypeError", message: "Cannot round to '" + typeof(a[1]) + "'", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot round to '" + typeof(a[1]) + "'", EXISTS: true}
}
precision = x
default:
return nil, ArErr{TYPE: "TypeError", message: "Cannot round to '" + typeof(a[1]) + "'", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot round to '" + typeof(a[1]) + "'", EXISTS: true}
}
}
@@ -148,7 +148,7 @@ func makeGlobal() ArObject {
case number:
return round(newNumber().Set(x), int(precision.Num().Int64())), ArErr{}
}
return nil, ArErr{TYPE: "TypeError", message: "Cannot round '" + typeof(a[0]) + "'", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot round '" + typeof(a[0]) + "'", EXISTS: true}
}}
vars["floor"] = builtinFunc{"floor", func(a ...any) (any, ArErr) {
if len(a) == 0 {
@@ -159,7 +159,7 @@ func makeGlobal() ArObject {
case number:
return floor(x), ArErr{}
}
return nil, ArErr{TYPE: "TypeError", message: "Cannot floor '" + typeof(a[0]) + "'", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot floor '" + typeof(a[0]) + "'", EXISTS: true}
}}
vars["ceil"] = builtinFunc{"ceil", func(a ...any) (any, ArErr) {
if len(a) == 0 {
@@ -171,7 +171,7 @@ func makeGlobal() ArObject {
case number:
return ceil(x), ArErr{}
}
return nil, ArErr{TYPE: "TypeError", message: "Cannot ceil '" + typeof(a[0]) + "'", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot ceil '" + typeof(a[0]) + "'", EXISTS: true}
}}
vars["sqrt"] = builtinFunc{"sqrt", ArgonSqrt}
vars["file"] = ArFile
@@ -217,7 +217,7 @@ func makeGlobal() ArObject {
return resp, ArErr{}
}
}
return nil, ArErr{TYPE: "TypeError", message: "Cannot fraction '" + typeof(a[0]) + "'", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot fraction '" + typeof(a[0]) + "'", EXISTS: true}
}}
vars["dir"] = builtinFunc{"dir", func(a ...any) (any, ArErr) {
if len(a) == 0 {
@@ -255,7 +255,7 @@ func makeGlobal() ArObject {
case number:
return string([]rune{rune(floor(x).Num().Int64())}), ArErr{}
}
return nil, ArErr{TYPE: "TypeError", message: "Cannot convert '" + typeof(a[0]) + "' to string", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot convert '" + typeof(a[0]) + "' to string", EXISTS: true}
}}
vars["ord"] = builtinFunc{"ord", func(a ...any) (any, ArErr) {
if len(a) != 1 {
@@ -269,7 +269,7 @@ func makeGlobal() ArObject {
}
return floor(newNumber().SetInt64(int64([]rune(x)[0]))), ArErr{}
}
return nil, ArErr{TYPE: "TypeError", message: "Cannot convert '" + typeof(a[0]) + "' to string", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot convert '" + typeof(a[0]) + "' to string", EXISTS: true}
}}
vars["max"] = builtinFunc{"max", func(a ...any) (any, ArErr) {
if len(a) != 1 {
@@ -296,7 +296,7 @@ func makeGlobal() ArObject {
}
return max, ArErr{}
}
return nil, ArErr{TYPE: "TypeError", message: "Cannot get max of type '" + typeof(a[0]) + "'", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot get max of type '" + typeof(a[0]) + "'", EXISTS: true}
}}
vars["min"] = builtinFunc{"min", func(a ...any) (any, ArErr) {
if len(a) != 1 {
@@ -323,7 +323,7 @@ func makeGlobal() ArObject {
}
return max, ArErr{}
}
return nil, ArErr{TYPE: "TypeError", message: "Cannot get max of type '" + typeof(a[0]) + "'", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot get max of type '" + typeof(a[0]) + "'", EXISTS: true}
}}
vars["path"] = ArPath
vars["typeof"] = builtinFunc{"typeof", func(a ...any) (any, ArErr) {
@@ -341,7 +341,7 @@ func makeGlobal() ArObject {
case string:
return ArString(sha256Hash(x)), ArErr{}
}
return nil, ArErr{TYPE: "TypeError", message: "Cannot hash type '" + typeof(a[0]) + "'", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot hash type '" + typeof(a[0]) + "'", EXISTS: true}
}}
return Map(vars)
}

View File

@@ -12,7 +12,7 @@ var ArColour = Map(
"set": builtinFunc{"set", func(a ...any) (any, ArErr) {
if len(a) != 2 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "set() takes exactly 2 argument (" + fmt.Sprint(len(a)) + " given)",
EXISTS: true,
}
@@ -23,7 +23,7 @@ var ArColour = Map(
c = color.Set(color.Attribute(x.Num().Int64()))
} else {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "set() argument 1 must be an number, not " + typeof(a[0]),
EXISTS: true,
}
@@ -32,7 +32,7 @@ var ArColour = Map(
s = ArValidToAny(a[1]).(string)
} else {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "set() argument 2 must be a string, not " + typeof(a[1]),
EXISTS: true,
}

View File

@@ -16,19 +16,19 @@ type ArErr struct {
func ArThrowError(a ...any) (any, ArErr) {
if len(a) != 2 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "throwError takes 2 arguments, " + fmt.Sprint(len(a)) + " given",
EXISTS: true,
}
} else if typeof(a[0]) != "string" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "throwError type must be a string",
EXISTS: true,
}
} else if typeof(a[1]) != "string" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "throwError message must be a string",
EXISTS: true,
}

View File

@@ -51,7 +51,7 @@ func mapGet(r ArMapGet, stack stack, stacklevel int) (any, ArErr) {
return nil, err
}
return nil, ArErr{
"TypeError",
"Type Error",
"cannot read " + anyToArgon(key, true, true, 3, 0, false, 0) + " from type '" + typeof(resp) + "'",
r.Line,
r.Path,

View File

@@ -10,14 +10,8 @@ var Args = os.Args[1:]
type stack = []ArObject
const VERSION = "3.0.4-2"
const VERSION_NUM = 1
// Example struct
type Person struct {
Name string
Age int
}
const VERSION = "3.0.4-3"
const VERSION_NUM = 2
func newscope() ArObject {
return Map(anymap{})

View File

@@ -36,7 +36,7 @@ func runCreateMap(m createMap, stack stack, stacklevel int) (any, ArErr) {
}
if isUnhashable(keyVal) {
return nil, ArErr{
"TypeError",
"Type Error",
"unhashable type: '" + typeof(keyVal) + "'",
m.line,
m.path,
@@ -161,7 +161,7 @@ func Map(m anymap) ArObject {
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true,
}
@@ -201,7 +201,7 @@ func Map(m anymap) ArObject {
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true,
}
@@ -241,7 +241,7 @@ func Map(m anymap) ArObject {
func(args ...any) (any, ArErr) {
if len(args) != 2 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected 2 arguments, got " + fmt.Sprint(len(args)),
EXISTS: true,
}
@@ -279,7 +279,7 @@ func Map(m anymap) ArObject {
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true,
}
@@ -330,7 +330,7 @@ func Map(m anymap) ArObject {
debugPrintln("Equal", args)
if len(args) != 1 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true,
}
@@ -372,7 +372,7 @@ func Map(m anymap) ArObject {
debugPrintln("copy", args)
if len(args) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected 0 arguments, got " + fmt.Sprint(len(args)),
EXISTS: true,
}
@@ -391,7 +391,7 @@ func Map(m anymap) ArObject {
func(args ...any) (any, ArErr) {
if len(args) != 2 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected 2 arguments, got " + fmt.Sprint(len(args)),
EXISTS: true,
}
@@ -406,7 +406,7 @@ func Map(m anymap) ArObject {
}
if typeof(args[1]) != "function" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected function, got " + typeof(args[1]),
EXISTS: true,
}
@@ -425,7 +425,7 @@ func Map(m anymap) ArObject {
func(args ...any) (any, ArErr) {
if len(args) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected 0 arguments, got " + fmt.Sprint(len(args)),
EXISTS: true,
}
@@ -444,7 +444,7 @@ func Map(m anymap) ArObject {
func(args ...any) (any, ArErr) {
if len(args) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected 0 arguments, got " + fmt.Sprint(len(args)),
EXISTS: true,
}
@@ -475,7 +475,7 @@ func Map(m anymap) ArObject {
func(args ...any) (any, ArErr) {
if len(args) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "expected 0 arguments, got " + fmt.Sprint(len(args)),
EXISTS: true,
}

View File

@@ -14,7 +14,7 @@ var ArPath = Map(
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: "ReadDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true,
}
@@ -22,7 +22,7 @@ var ArPath = Map(
args[0] = ArValidToAny(args[0])
if typeof(args[0]) != "string" {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: "ReadDir argument must be a string, got " + typeof(args[0]),
EXISTS: true,
}
@@ -30,7 +30,7 @@ var ArPath = Map(
files, err := os.ReadDir(args[0].(string))
if err != nil {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: err.Error(),
EXISTS: true,
}
@@ -46,7 +46,7 @@ var ArPath = Map(
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: "exists takes exactly 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true,
}
@@ -54,7 +54,7 @@ var ArPath = Map(
args[0] = ArValidToAny(args[0])
if typeof(args[0]) != "string" {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: "exists argument must be a string, got " + typeof(args[0]),
EXISTS: true,
}
@@ -65,7 +65,7 @@ var ArPath = Map(
return false, ArErr{}
}
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: err.Error(),
EXISTS: true,
}
@@ -77,7 +77,7 @@ var ArPath = Map(
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: "mkAllDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true,
}
@@ -85,7 +85,7 @@ var ArPath = Map(
args[0] = ArValidToAny(args[0])
if typeof(args[0]) != "string" {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: "mkAllDir argument must be a string, got " + typeof(args[0]),
EXISTS: true,
}
@@ -93,7 +93,7 @@ var ArPath = Map(
err := os.MkdirAll(args[0].(string), os.ModePerm)
if err != nil {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: err.Error(),
EXISTS: true,
}
@@ -105,7 +105,7 @@ var ArPath = Map(
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: "mkDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true,
}
@@ -113,7 +113,7 @@ var ArPath = Map(
args[0] = ArValidToAny(args[0])
if typeof(args[0]) != "string" {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: "mkDir argument must be a string, got " + typeof(args[0]),
EXISTS: true,
}
@@ -121,7 +121,7 @@ var ArPath = Map(
err := os.Mkdir(args[0].(string), os.ModePerm)
if err != nil {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: err.Error(),
EXISTS: true,
}
@@ -133,7 +133,7 @@ var ArPath = Map(
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: "remove takes exactly 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true,
}
@@ -141,7 +141,7 @@ var ArPath = Map(
args[0] = ArValidToAny(args[0])
if typeof(args[0]) != "string" {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: "remove argument must be a string, got " + typeof(args[0]),
EXISTS: true,
}
@@ -149,7 +149,7 @@ var ArPath = Map(
err := os.Remove(args[0].(string))
if err != nil {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: err.Error(),
EXISTS: true,
}
@@ -161,7 +161,7 @@ var ArPath = Map(
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: "isDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true,
}
@@ -169,7 +169,7 @@ var ArPath = Map(
args[0] = ArValidToAny(args[0])
if typeof(args[0]) != "string" {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: "isDir argument must be a string, got " + typeof(args[0]),
EXISTS: true,
}
@@ -180,7 +180,7 @@ var ArPath = Map(
return false, ArErr{}
}
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: err.Error(),
EXISTS: true,
}
@@ -192,7 +192,7 @@ var ArPath = Map(
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: "join takes exactly 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true,
}
@@ -205,7 +205,7 @@ var ArPath = Map(
x = ArValidToAny(x)
if typeof(x) != "string" {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: "join argument must be an array of strings, got " + typeof(x),
EXISTS: true,
}
@@ -215,7 +215,7 @@ var ArPath = Map(
return filepath.Join(Path...), ArErr{}
}
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: "join argument must be an array, got " + typeof(args[0]),
EXISTS: true,
}
@@ -225,7 +225,7 @@ var ArPath = Map(
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: "parent takes exactly 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true,
}
@@ -233,7 +233,7 @@ var ArPath = Map(
args[0] = ArValidToAny(args[0])
if typeof(args[0]) != "string" {
return nil, ArErr{
TYPE: "runtime",
TYPE: "Runtime Error",
message: "parent argument must be a string, got " + typeof(args[0]),
EXISTS: true,
}

View File

@@ -76,7 +76,7 @@ func runVal(line any, stack stack, stacklevel int) (any, ArErr) {
return y, ArErr{}
}
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "cannot negate a non-number",
EXISTS: true,
}

View File

@@ -10,19 +10,19 @@ import (
func ArSocketClient(args ...any) (any, ArErr) {
if len(args) != 2 {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket takes exactly 2 arguments",
EXISTS: true,
}
} else if typeof(args[0]) != "string" {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket type must be a string",
EXISTS: true,
}
} else if typeof(args[1]) != "string" {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket address must be a string",
EXISTS: true,
}
@@ -32,7 +32,7 @@ func ArSocketClient(args ...any) (any, ArErr) {
conn, err := net.Dial(networktype, address)
if err != nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: fmt.Sprintf("Socket connection failed: %s", err.Error()),
EXISTS: true,
}
@@ -44,14 +44,14 @@ func ArSocketClient(args ...any) (any, ArErr) {
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket.readData() takes exactly 1 argument",
EXISTS: true,
}
}
if conn == nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Connection is closed",
EXISTS: true,
}
@@ -60,7 +60,7 @@ func ArSocketClient(args ...any) (any, ArErr) {
n, err := conn.Read(buf)
if err != nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: fmt.Sprintf("Socket read failed: %s", err.Error()),
EXISTS: true,
}
@@ -72,14 +72,14 @@ func ArSocketClient(args ...any) (any, ArErr) {
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket.readUntil() takes exactly 1 argument",
EXISTS: true,
}
}
if conn == nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Connection is closed",
EXISTS: true,
}
@@ -87,7 +87,7 @@ func ArSocketClient(args ...any) (any, ArErr) {
value := ArValidToAny(args[0])
if typeof(value) != "buffer" {
return ArObject{}, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: fmt.Sprintf("Socket.readUntil() argument must be a buffer, not %s", typeof(value)),
EXISTS: true,
}
@@ -100,7 +100,7 @@ func ArSocketClient(args ...any) (any, ArErr) {
_, err := reader.Read(buf)
if err != nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: fmt.Sprintf("Socket read failed: %s", err.Error()),
EXISTS: true,
}
@@ -125,21 +125,21 @@ func ArSocketClient(args ...any) (any, ArErr) {
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: fmt.Sprintf("write() takes exactly 1 argument (%d given)", len(args)),
EXISTS: true,
}
}
if typeof(args[0]) != "buffer" {
return ArObject{}, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: fmt.Sprintf("write() argument must be a buffer, not %s", typeof(args[0])),
EXISTS: true,
}
}
if conn == nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Connection is closed",
EXISTS: true,
}
@@ -147,7 +147,7 @@ func ArSocketClient(args ...any) (any, ArErr) {
args[0] = ArValidToAny(args[0])
if typeof(args[0]) != "buffer" {
return ArObject{}, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: fmt.Sprintf("write() argument must be a buffer, not %s", typeof(args[0])),
EXISTS: true,
}
@@ -155,7 +155,7 @@ func ArSocketClient(args ...any) (any, ArErr) {
_, err := conn.Write(args[0].([]byte))
if err != nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: err.Error(),
EXISTS: true,
}
@@ -167,7 +167,7 @@ func ArSocketClient(args ...any) (any, ArErr) {
func(args ...any) (any, ArErr) {
if conn == nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Connection is already closed",
EXISTS: true,
}
@@ -175,7 +175,7 @@ func ArSocketClient(args ...any) (any, ArErr) {
err := conn.Close()
if err != nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: err.Error(),
EXISTS: true,
}
@@ -208,19 +208,19 @@ func ArSocketClient(args ...any) (any, ArErr) {
func ArSocketServer(args ...any) (any, ArErr) {
if len(args) != 2 {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket takes exactly 2 arguments",
EXISTS: true,
}
} else if typeof(args[0]) != "string" {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket type must be a string",
EXISTS: true,
}
} else if typeof(args[1]) != "number" {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket port must be a number",
EXISTS: true,
}
@@ -229,7 +229,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
port := args[1].(number)
if port.Denom().Int64() != 1 {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket port must be an integer",
EXISTS: true,
}
@@ -237,7 +237,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
ln, err := net.Listen(networktype, ":"+fmt.Sprint(port.Num().Int64()))
if err != nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: err.Error(),
EXISTS: true,
}
@@ -248,7 +248,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
func(args ...any) (any, ArErr) {
if ln == nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket is closed",
EXISTS: true,
}
@@ -256,7 +256,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
conn, err := ln.Accept()
if err != nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: err.Error(),
EXISTS: true,
}
@@ -267,14 +267,14 @@ func ArSocketServer(args ...any) (any, ArErr) {
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket.readData() takes exactly 1 argument",
EXISTS: true,
}
}
if conn == nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Connection is closed",
EXISTS: true,
}
@@ -283,7 +283,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
n, err := conn.Read(buf)
if err != nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: err.Error(),
EXISTS: true,
}
@@ -296,14 +296,14 @@ func ArSocketServer(args ...any) (any, ArErr) {
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket.readUntil() takes exactly 1 argument",
EXISTS: true,
}
}
if conn == nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Connection is closed",
EXISTS: true,
}
@@ -311,7 +311,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
value := ArValidToAny(args[0])
if typeof(value) != "buffer" {
return ArObject{}, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: fmt.Sprintf("Socket.readUntil() argument must be a buffer, not %s", typeof(value)),
EXISTS: true,
}
@@ -346,14 +346,14 @@ func ArSocketServer(args ...any) (any, ArErr) {
func(args ...any) (any, ArErr) {
if len(args) != 0 {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket.clearTimeout() takes exactly 0 arguments",
EXISTS: true,
}
}
if conn == nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Connection is closed",
EXISTS: true,
}
@@ -367,21 +367,21 @@ func ArSocketServer(args ...any) (any, ArErr) {
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket.setTimeout() takes exactly 1 argument",
EXISTS: true,
}
}
if typeof(args[0]) != "number" {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket timeout must be a number",
EXISTS: true,
}
}
if conn == nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Connection is closed",
EXISTS: true,
}
@@ -389,7 +389,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
timeout := args[0].(number)
if timeout.Denom().Int64() != 1 {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket timeout must be an integer",
EXISTS: true,
}
@@ -397,7 +397,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
err := conn.SetDeadline(time.Now().Add(time.Duration(timeout.Num().Int64()) * time.Millisecond))
if err != nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: err.Error(),
EXISTS: true,
}
@@ -410,14 +410,14 @@ func ArSocketServer(args ...any) (any, ArErr) {
func(args ...any) (any, ArErr) {
if len(args) != 1 {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket.writeData() takes exactly 1 argument",
EXISTS: true,
}
}
if conn == nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Connection is closed",
EXISTS: true,
}
@@ -429,7 +429,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
for _, v := range x {
if typeof(v) != "number" && v.(number).Denom().Int64() != 1 {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket.writeData() argument must be a array of integers",
EXISTS: true,
}
@@ -443,7 +443,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
return nil, ArErr{}
}
return nil, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket.writeData() argument must be a array of numbers",
}
},
@@ -453,7 +453,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
func(args ...any) (any, ArErr) {
if conn == nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Connection is already closed",
EXISTS: true,
}
@@ -486,7 +486,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
func(args ...any) (any, ArErr) {
if conn == nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Connection is closed",
EXISTS: true,
}
@@ -508,7 +508,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
func(args ...any) (any, ArErr) {
if ln == nil {
return ArObject{}, ArErr{
TYPE: "SocketError",
TYPE: "Socket Error",
message: "Socket is already closed",
EXISTS: true,
}

View File

@@ -73,26 +73,26 @@ func ArString(str string) ArObject {
"__setindex__",
func(a ...any) (any, ArErr) {
if len(a) != 2 {
return nil, ArErr{"TypeError", "expected 2 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 2 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "number" {
return nil, ArErr{"TypeError", "expected number, got " + typeof(a[0]), 0, "", "", true}
return nil, ArErr{"Type Error", "expected number, got " + typeof(a[0]), 0, "", "", true}
}
if typeof(a[1]) != "string" {
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[1]), 0, "", "", true}
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[1]), 0, "", "", true}
}
if len(a[1].(string)) != 1 {
return nil, ArErr{"TypeError", "expected string of length 1, got " + fmt.Sprint(len(a[1].(string))), 0, "", "", true}
return nil, ArErr{"Type Error", "expected string of length 1, got " + fmt.Sprint(len(a[1].(string))), 0, "", "", true}
}
if !a[0].(number).IsInt() {
return nil, ArErr{"TypeError", "expected integer, got float", 0, "", "", true}
return nil, ArErr{"Type Error", "expected integer, got float", 0, "", "", true}
}
index := a[0].(number).Num().Int64()
if index < 0 {
index = int64(len(str)) + index
}
if index < 0 || index >= int64(len(str)) {
return nil, ArErr{"IndexError", "index out of range", 0, "", "", true}
return nil, ArErr{"Index Error", "index out of range", 0, "", "", true}
}
str = strings.Join([]string{str[:index], a[1].(string), str[index+1:]}, "")
obj.obj["__value__"] = str
@@ -106,7 +106,7 @@ func ArString(str string) ArObject {
// a[1] is end
// a[2] is step
if len(a) > 3 {
return nil, ArErr{"TypeError", "expected 1 to 3 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 to 3 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
var (
start int = 0
@@ -118,7 +118,7 @@ func ArString(str string) ArObject {
start = 0
} else if typeof(a[0]) != "number" || !a[0].(number).IsInt() {
return "", ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "slice index must be an integer",
EXISTS: true,
}
@@ -131,7 +131,7 @@ func ArString(str string) ArObject {
end = len(str)
} else if typeof(a[1]) != "number" || !a[1].(number).IsInt() {
return "", ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "slice index must be an integer",
EXISTS: true,
}
@@ -144,7 +144,7 @@ func ArString(str string) ArObject {
step = 1
} else if typeof(a[2]) != "number" || !a[2].(number).IsInt() {
return "", ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "slice index must be an integer",
EXISTS: true,
}
@@ -184,13 +184,13 @@ func ArString(str string) ArObject {
"append",
func(a ...any) (any, ArErr) {
if len(a) == 0 {
return nil, ArErr{"TypeError", "expected 1 or more argument, got 0", 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 or more argument, got 0", 0, "", "", true}
}
output := []string{str}
for _, v := range a {
v = ArValidToAny(v)
if typeof(v) != "string" {
return nil, ArErr{"TypeError", "expected string, got " + typeof(v), 0, "", "", true}
return nil, ArErr{"Type Error", "expected string, got " + typeof(v), 0, "", "", true}
}
output = append(output, v.(string))
}
@@ -203,15 +203,15 @@ func ArString(str string) ArObject {
"extend",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "array" {
return nil, ArErr{"TypeError", "expected array, got " + typeof(a[0]), 0, "", "", true}
return nil, ArErr{"Type Error", "expected array, got " + typeof(a[0]), 0, "", "", true}
}
output := []string{str}
for _, v := range a[0].([]any) {
if typeof(v) != "string" {
return nil, ArErr{"TypeError", "expected string, got " + typeof(v), 0, "", "", true}
return nil, ArErr{"Type Error", "expected string, got " + typeof(v), 0, "", "", true}
}
output = append(output, v.(string))
}
@@ -225,13 +225,13 @@ func ArString(str string) ArObject {
"insert",
func(a ...any) (any, ArErr) {
if len(a) != 2 {
return nil, ArErr{"TypeError", "expected 2 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 2 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "number" || !a[0].(number).IsInt() {
return nil, ArErr{"TypeError", "expected integer, got " + typeof(a[0]), 0, "", "", true}
return nil, ArErr{"Type Error", "expected integer, got " + typeof(a[0]), 0, "", "", true}
}
if typeof(a[1]) != "string" {
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[1]), 0, "", "", true}
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[1]), 0, "", "", true}
}
index := int(a[0].(number).Num().Int64())
if index < 0 {
@@ -249,12 +249,12 @@ func ArString(str string) ArObject {
"concat",
func(a ...any) (any, ArErr) {
if len(a) == 0 {
return nil, ArErr{"TypeError", "expected 1 or more argument, got 0", 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 or more argument, got 0", 0, "", "", true}
}
output := []string{str}
for _, v := range a {
if typeof(v) != "string" {
return nil, ArErr{"TypeError", "expected string, got " + typeof(v), 0, "", "", true}
return nil, ArErr{"Type Error", "expected string, got " + typeof(v), 0, "", "", true}
}
output = append(output, v.(string))
}
@@ -264,10 +264,10 @@ func ArString(str string) ArObject {
"split",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 or more argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 or more argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
}
splitby := ArValidToAny(a[0]).(string)
output := []any{}
@@ -281,13 +281,13 @@ func ArString(str string) ArObject {
"splitN",
func(a ...any) (any, ArErr) {
if len(a) != 2 {
return nil, ArErr{"TypeError", "expected 2 or more argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 2 or more argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
}
if typeof(a[1]) != "number" || !a[1].(number).IsInt() {
return nil, ArErr{"TypeError", "expected integer, got " + typeof(a[1]), 0, "", "", true}
return nil, ArErr{"Type Error", "expected integer, got " + typeof(a[1]), 0, "", "", true}
}
splitby := ArValidToAny(a[0]).(string)
n := int(a[1].(number).Num().Int64())
@@ -302,7 +302,7 @@ func ArString(str string) ArObject {
"capitalise",
func(a ...any) (any, ArErr) {
if len(a) != 0 {
return nil, ArErr{"TypeError", "expected 0 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 0 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
return cases.Title(language.English).String(str), ArErr{}
}}
@@ -310,7 +310,7 @@ func ArString(str string) ArObject {
"lower",
func(a ...any) (any, ArErr) {
if len(a) != 0 {
return nil, ArErr{"TypeError", "expected 0 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 0 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
return strings.ToLower(str), ArErr{}
}}
@@ -318,7 +318,7 @@ func ArString(str string) ArObject {
"upper",
func(a ...any) (any, ArErr) {
if len(a) != 0 {
return nil, ArErr{"TypeError", "expected 0 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 0 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
return strings.ToUpper(str), ArErr{}
}}
@@ -326,13 +326,13 @@ func ArString(str string) ArObject {
"replace",
func(a ...any) (any, ArErr) {
if len(a) != 2 {
return nil, ArErr{"TypeError", "expected 2 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 2 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
}
if typeof(a[1]) != "string" {
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[1]), 0, "", "", true}
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[1]), 0, "", "", true}
}
a[0] = ArValidToAny(a[0])
a[1] = ArValidToAny(a[1])
@@ -342,10 +342,10 @@ func ArString(str string) ArObject {
"contains",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
}
return strings.Contains(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
}}
@@ -353,10 +353,10 @@ func ArString(str string) ArObject {
"startswith",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
}
return strings.HasPrefix(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
}}
@@ -364,10 +364,10 @@ func ArString(str string) ArObject {
"endswith",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
}
return strings.HasSuffix(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
}}
@@ -375,10 +375,10 @@ func ArString(str string) ArObject {
"index",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
}
return strings.Index(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
}}
@@ -386,10 +386,10 @@ func ArString(str string) ArObject {
"rindex",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
}
return strings.LastIndex(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
}}
@@ -398,10 +398,10 @@ func ArString(str string) ArObject {
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
}
return strings.Count(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
}}
@@ -411,7 +411,7 @@ func ArString(str string) ArObject {
func(args ...any) (any, ArErr) {
if len(args) > 2 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "too many arguments",
EXISTS: true,
}
@@ -420,7 +420,7 @@ func ArString(str string) ArObject {
if len(args) >= 1 {
if typeof(args[0]) != "boolean" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "argument must be a boolean",
EXISTS: true,
}
@@ -435,7 +435,7 @@ func ArString(str string) ArObject {
if len(args) == 2 {
if typeof(args[1]) != "function" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: "argument must be a function",
EXISTS: true,
}
@@ -483,12 +483,12 @@ func ArString(str string) ArObject {
"strip",
func(a ...any) (any, ArErr) {
if len(a) > 1 {
return nil, ArErr{"TypeError", "expected 0 or 1 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 0 or 1 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
cutset := " "
if len(a) == 1 {
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
}
cutset = a[0].(ArObject).obj["__value__"].(string)
}
@@ -498,12 +498,12 @@ func ArString(str string) ArObject {
"leftstrip",
func(a ...any) (any, ArErr) {
if len(a) > 1 {
return nil, ArErr{"TypeError", "expected 0 or 1 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 0 or 1 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
cutset := " "
if len(a) == 1 {
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
}
cutset = a[0].(ArObject).obj["__value__"].(string)
}
@@ -513,12 +513,12 @@ func ArString(str string) ArObject {
"rightstrip",
func(a ...any) (any, ArErr) {
if len(a) > 1 {
return nil, ArErr{"TypeError", "expected 0 or 1 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 0 or 1 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
cutset := " "
if len(a) == 1 {
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
}
cutset = a[0].(ArObject).obj["__value__"].(string)
}
@@ -528,10 +528,10 @@ func ArString(str string) ArObject {
"__LessThanOrEqual__",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "cannot get less than or equal to of type " + typeof(a[0]) + " from string", 0, "", "", true}
return nil, ArErr{"Type Error", "cannot get less than or equal to of type " + typeof(a[0]) + " from string", 0, "", "", true}
}
a[0] = ArValidToAny(a[0])
return str <= a[0].(string), ArErr{}
@@ -540,10 +540,10 @@ func ArString(str string) ArObject {
"__LessThan__",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "cannot get less than of type " + typeof(a[0]) + " from string", 0, "", "", true}
return nil, ArErr{"Type Error", "cannot get less than of type " + typeof(a[0]) + " from string", 0, "", "", true}
}
a[0] = ArValidToAny(a[0])
return str < a[0].(string), ArErr{}
@@ -552,10 +552,10 @@ func ArString(str string) ArObject {
"__GreaterThan__",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "cannot get greater than of type " + typeof(a[0]) + " from string", 0, "", "", true}
return nil, ArErr{"Type Error", "cannot get greater than of type " + typeof(a[0]) + " from string", 0, "", "", true}
}
a[0] = ArValidToAny(a[0])
return str > a[0].(string), ArErr{}
@@ -565,10 +565,10 @@ func ArString(str string) ArObject {
"__GreaterThanEqual__",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "cannot get greater than or equal to of type " + typeof(a[0]) + " from string", 0, "", "", true}
return nil, ArErr{"Type Error", "cannot get greater than or equal to of type " + typeof(a[0]) + " from string", 0, "", "", true}
}
a[0] = ArValidToAny(a[0])
return str >= a[0].(string), ArErr{}
@@ -577,7 +577,7 @@ func ArString(str string) ArObject {
"__Equal__",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
a[0] = ArValidToAny(a[0])
return str == a[0], ArErr{}
@@ -586,7 +586,7 @@ func ArString(str string) ArObject {
"__NotEqual__",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
a[0] = ArValidToAny(a[0])
return str != a[0], ArErr{}
@@ -595,7 +595,7 @@ func ArString(str string) ArObject {
"__Add__",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
a[0] = ArValidToAny(a[0])
if typeof(a[0]) != "string" {
@@ -607,7 +607,7 @@ func ArString(str string) ArObject {
"__PostAdd__",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
a[0] = ArValidToAny(a[0])
if typeof(a[0]) != "string" {
@@ -619,10 +619,10 @@ func ArString(str string) ArObject {
"__Multiply__",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "number" {
return nil, ArErr{"TypeError", "cannot multiply string by " + typeof(a[0]), 0, "", "", true}
return nil, ArErr{"Type Error", "cannot multiply string by " + typeof(a[0]), 0, "", "", true}
}
n := a[0].(number)
if !n.IsInt() {
@@ -637,10 +637,10 @@ func ArString(str string) ArObject {
"__NotContains__",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "cannot check if string contains " + typeof(a[0]), 0, "", "", true}
return nil, ArErr{"Type Error", "cannot check if string contains " + typeof(a[0]), 0, "", "", true}
}
a[0] = ArValidToAny(a[0])
return !strings.Contains(str, a[0].(string)), ArErr{}
@@ -649,10 +649,10 @@ func ArString(str string) ArObject {
"__Contains__",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "cannot check if string contains " + typeof(a[0]), 0, "", "", true}
return nil, ArErr{"Type Error", "cannot check if string contains " + typeof(a[0]), 0, "", "", true}
}
a[0] = ArValidToAny(a[0])
return strings.Contains(str, a[0].(string)), ArErr{}
@@ -661,10 +661,10 @@ func ArString(str string) ArObject {
"__Subtract__",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "cannot subtract " + typeof(a[0]) + " from string", 0, "", "", true}
return nil, ArErr{"Type Error", "cannot subtract " + typeof(a[0]) + " from string", 0, "", "", true}
}
a[0] = ArValidToAny(a[0])
return strings.Replace(str, a[0].(string), "", -1), ArErr{}
@@ -673,10 +673,10 @@ func ArString(str string) ArObject {
"__Divide__",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "string" {
return nil, ArErr{"TypeError", "cannot divide string by " + typeof(a[0]), 0, "", "", true}
return nil, ArErr{"Type Error", "cannot divide string by " + typeof(a[0]), 0, "", "", true}
}
a[0] = ArValidToAny(a[0])
splitby := a[0].(string)

View File

@@ -15,7 +15,7 @@ func ArSubprocess(args ...any) (any, ArErr) {
}
} else if typeof(args[0]) != "array" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: fmt.Sprintf("subprocess() argument must be an array, not %s", typeof(args[0])),
EXISTS: true,
}
@@ -32,7 +32,7 @@ func ArSubprocess(args ...any) (any, ArErr) {
for _, x := range args[0].([]any) {
if typeof(x) != "string" {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: fmt.Sprintf("subprocess() argument must be an array of strings, not %s", typeof(x)),
EXISTS: true,
}
@@ -70,7 +70,7 @@ func ArSubprocess(args ...any) (any, ArErr) {
func(args ...any) (any, ArErr) {
if len(args) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: fmt.Sprintf("scan() takes exactly 0 arguments (%d given)", len(args)),
EXISTS: true,
}
@@ -82,7 +82,7 @@ func ArSubprocess(args ...any) (any, ArErr) {
func(args ...any) (any, ArErr) {
if len(args) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: fmt.Sprintf("text() takes exactly 0 arguments (%d given)", len(args)),
EXISTS: true,
}
@@ -94,7 +94,7 @@ func ArSubprocess(args ...any) (any, ArErr) {
func(args ...any) (any, ArErr) {
if len(args) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: fmt.Sprintf("err() takes exactly 0 arguments (%d given)", len(args)),
EXISTS: true,
}
@@ -109,7 +109,7 @@ func ArSubprocess(args ...any) (any, ArErr) {
func(args ...any) (any, ArErr) {
if len(args) != 0 {
return nil, ArErr{
TYPE: "TypeError",
TYPE: "Type Error",
message: fmt.Sprintf("wait() takes exactly 0 arguments (%d given)", len(args)),
EXISTS: true,
}

View File

@@ -115,7 +115,7 @@ var ArTerm = Map(anymap{
}
timingSync.RLock()
if _, ok := timing[id]; !ok {
return nil, ArErr{TYPE: "TypeError", message: "Cannot find timer with id '" + fmt.Sprint(id) + "'", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot find timer with id '" + fmt.Sprint(id) + "'", EXISTS: true}
}
timesince := time.Since(timing[id].(time.Time))
timingSync.RUnlock()

View File

@@ -9,19 +9,19 @@ var threadChan = make(chan bool)
func ArThread(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{TYPE: "TypeError", message: "Invalid number of arguments, expected 1, got " + fmt.Sprint(len(args)), EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Invalid number of arguments, expected 1, got " + fmt.Sprint(len(args)), EXISTS: true}
}
var tocall any
switch x := args[0].(type) {
case anymap:
if _, ok := x["__call__"]; !ok {
return nil, ArErr{TYPE: "TypeError", message: "Cannot call thread with a '" + typeof(args[0]) + "'", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot call thread with a '" + typeof(args[0]) + "'", EXISTS: true}
}
tocall = x["__call__"]
case builtinFunc, Callable:
tocall = x
default:
return nil, ArErr{TYPE: "TypeError", message: "Cannot call thread with a '" + typeof(args[0]) + "'", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot call thread with a '" + typeof(args[0]) + "'", EXISTS: true}
}
var resp any
var err ArErr
@@ -35,7 +35,7 @@ func ArThread(args ...any) (any, ArErr) {
return nil, ArErr{TYPE: "Runtime Error", message: "Cannot start a thread twice", EXISTS: true}
}
if len(args) != 0 {
return nil, ArErr{TYPE: "TypeError", message: "Invalid number of arguments, expected 0, got " + fmt.Sprint(len(args)), EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Invalid number of arguments, expected 0, got " + fmt.Sprint(len(args)), EXISTS: true}
}
hasrun = true
threadCount++
@@ -56,7 +56,7 @@ func ArThread(args ...any) (any, ArErr) {
return nil, ArErr{TYPE: "Runtime Error", message: "Cannot join a thread twice", EXISTS: true}
}
if len(args) != 0 {
return nil, ArErr{TYPE: "TypeError", message: "Invalid number of arguments, expected 0, got " + fmt.Sprint(len(args)), EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Invalid number of arguments, expected 0, got " + fmt.Sprint(len(args)), EXISTS: true}
}
joined = true
<-wg