Implement return, implement instant break, add exit function, implement dumping and loading of AST via encoding/json

This commit is contained in:
2021-03-07 17:25:16 -08:00
parent f7a34b3da4
commit 1c99345af1
6 changed files with 138 additions and 62 deletions
+22
View File
@@ -17,6 +17,7 @@ package scpt
import (
"errors"
"fmt"
"os"
"strconv"
)
@@ -59,6 +60,27 @@ func setBreakLoop(_ map[string]interface{}) (interface{}, error) {
return nil, nil
}
// Default function to set the breakLoop variable to true, breaking any loops that may be running
func setReturn(args map[string]interface{}) (interface{}, error) {
// If a loop is running
if funcRunning {
// Set breakLoop to true, breaking the loop on next cycle
retValue = args[""]
} else {
return nil, errors.New("return not inside function")
}
return nil, nil
}
func scptExit(args map[string]interface{}) (interface{}, error) {
exitCode, ok := args[""].(float64)
if !ok {
return nil, errors.New("exit requires an unnamed number argument")
}
os.Exit(int(exitCode))
return nil, nil
}
// Default function that returns an array with an appended element
func appendArray(args map[string]interface{}) (interface{}, error) {
// Attempt to get unnamed argument and assert as []interface{}