add Script.Run() method

This commit is contained in:
Daniel Kang 2019-01-12 18:25:45 -08:00
parent 2de0fa4efb
commit 8e56bd8218

View file

@ -74,6 +74,19 @@ func (s *Script) Compile() (*Compiled, error) {
}, nil
}
// Run compiles and runs the scripts.
// Use returned compiled object to access global variables.
func (s *Script) Run() (compiled *Compiled, err error) {
compiled, err = s.Compile()
if err != nil {
return
}
err = compiled.Run()
return
}
func (s *Script) prepCompile() (symbolTable *compiler.SymbolTable, globals []*objects.Object) {
var names []string
for name := range s.variables {