convert function call to builtInCall in setvariable, and add OOP example

This commit is contained in:
2023-06-21 20:36:06 +01:00
parent ae08f059fb
commit 9fe8bcb515
8 changed files with 59 additions and 56 deletions

View File

@@ -115,6 +115,7 @@ func ArArray(arr []any) ArObject {
step = int(a[2].(number).Num().Int64())
}
}
var ogStart = start
if start < 0 {
start = len(arr) + start
}
@@ -124,6 +125,13 @@ func ArArray(arr []any) ArObject {
if end != nil && end.(int) > len(arr) {
end = len(arr)
}
if start >= len(arr) || start < 0 {
return "", ArErr{
TYPE: "IndexError",
message: "index out of range, trying to access index " + fmt.Sprint(ogStart) + " in array of length " + fmt.Sprint(len(arr)),
EXISTS: true,
}
}
if end == nil {
return arr[start], ArErr{}
} else if step == 1 {