Implement return, implement instant break, add exit function, implement dumping and loading of AST via encoding/json
This commit is contained in:
+22
@@ -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{}
|
||||
|
||||
Reference in New Issue
Block a user