From 8e56bd8218692fb14f328585a90c5fc9e142a1a0 Mon Sep 17 00:00:00 2001 From: Daniel Kang Date: Sat, 12 Jan 2019 18:25:45 -0800 Subject: [PATCH] add Script.Run() method --- script/script.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/script/script.go b/script/script.go index 5756035..32933eb 100644 --- a/script/script.go +++ b/script/script.go @@ -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 {