Last active
July 15, 2019 13:57
-
-
Save d0c-s4vage/b3a86ea73ce53e8f08ea9c58d4700b71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// holds script-specific information (i.e. how to load the script data, | |
// name of the script, script runtime version required, etc.) | |
type Script struct { | |
} | |
// parameters to the script, TBD if key/value or positional | |
type ScriptParam struct { | |
} | |
// current script execution scope. Defines global variables, pre-exising variables | |
// from the current scope, etc. | |
type Scope struct { | |
} | |
// Interface so multiple implementations can exist and be swapped out | |
// without changing the code | |
type Interpreter interface { | |
Execute(script *Script, scope *Scope, opts ScriptExecOpts) error | |
} | |
// First interpreter implementations (v1) | |
type V1Interpreter struct { | |
} | |
// Holds execution options, limits, constraints, etc. | |
type ScriptExecOpts struct { | |
Debug bool | |
} | |
func RunScript( | |
i Interpreter, s *Script, params []*ScriptParam, scope *Scope, | |
) error { | |
log.Printf("Running script: %+v, with params %+v", s, params) | |
// scopes can create a subscope that includes/references the parent scope. | |
// values/settings in a child scope may override (shadow) the parent scope's | |
// values | |
newScope := scope.SubScope() | |
// Loads the script parameters into the current scope (they become | |
// variables in the script) | |
newScope.SetParams(params) | |
// execute the script, in the newScope with the script execution options | |
// specified. return an error if an error occurs | |
err := i.Execute(script, newScope, ScriptExecOpts{}) | |
if err != nil { | |
log.Printf("Error running script %+v: %s", s, err.Error()) | |
return err | |
} | |
log.Printf("Done running script") | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment