diff --git a/defaults.go b/defaults.go index e9555e1..a8dfb18 100644 --- a/defaults.go +++ b/defaults.go @@ -21,6 +21,24 @@ import ( "strconv" ) +// Vars stores any variables set during script runtime +var Vars = map[string]interface{}{} + +// FuncMap is a map of strings mapped to suitable script functions +type FuncMap map[string]func(map[string]interface{}) (interface{}, error) + +// Funcs stores the functions allowed for use in a script +var Funcs = FuncMap{ + "str": toString, + "num": parseNumber, + "bool": parseBool, + "break": setBreakLoop, + "append": appendArray, + "exit": scptExit, + "return": setReturn, + "print": scptPrint, +} + // Default function to convert unnamed argument to a string using fmt.Sprint func toString(args map[string]interface{}) (interface{}, error) { val, ok := args[""] @@ -101,3 +119,15 @@ func appendArray(args map[string]interface{}) (interface{}, error) { // Return appended unnamed argument return val, nil } + +// Print message via fmt.Println +func scptPrint(args map[string]interface{}) (interface{}, error) { + // Get message + val, ok := args[""] + if !ok { + return nil, errors.New("print requires an unnamed argument") + } + // Print message + fmt.Println(val) + return nil, nil +} \ No newline at end of file diff --git a/scpt.go b/scpt.go index d028ed1..7e23e54 100644 --- a/scpt.go +++ b/scpt.go @@ -26,23 +26,6 @@ import ( "strings" ) -// Vars stores any variables set during script runtime -var Vars = map[string]interface{}{} - -// FuncMap is a map of strings mapped to suitable script functions -type FuncMap map[string]func(map[string]interface{}) (interface{}, error) - -// Funcs stores the functions allowed for use in a script -var Funcs = FuncMap{ - "str": toString, - "num": parseNumber, - "bool": parseBool, - "break": setBreakLoop, - "append": appendArray, - "exit": scptExit, - "return": setReturn, -} - // AddFuncs adds all functions from the provided FuncMap into // the Funcs variable func AddFuncs(fnMap FuncMap) {