Ejemplo n.º 1
0
// Runs the specified Go source code in the context of 'w'
func runScript(w *eval.World, path, sourceCode string) error {
	var err error
	var code eval.Code

	fileSet := token.NewFileSet()
	fileSet.AddFile(path, fileSet.Base(), len(sourceCode))

	code, err = w.Compile(fileSet, sourceCode)
	if err != nil {
		str := strings.Replace(err.Error(), "input", path, 1)
		return errors.New(str)
	}

	_, err = code.Run()
	if err != nil {
		return err
	}

	return nil
}