From 393f9e998b1b40aa59d3fb8794c3a73da38c3fb7 Mon Sep 17 00:00:00 2001 From: Wim Date: Sun, 24 May 2020 00:06:21 +0200 Subject: Update dependencies / vendor (#1146) --- vendor/github.com/d5/tengo/v2/script.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'vendor/github.com/d5/tengo/v2/script.go') diff --git a/vendor/github.com/d5/tengo/v2/script.go b/vendor/github.com/d5/tengo/v2/script.go index 906771d9..4f9608c1 100644 --- a/vendor/github.com/d5/tengo/v2/script.go +++ b/vendor/github.com/d5/tengo/v2/script.go @@ -3,6 +3,7 @@ package tengo import ( "context" "fmt" + "path/filepath" "sync" "github.com/d5/tengo/v2/parser" @@ -16,6 +17,7 @@ type Script struct { maxAllocs int64 maxConstObjects int enableFileImport bool + importDir string } // NewScript creates a Script instance with an input script. @@ -56,6 +58,16 @@ func (s *Script) SetImports(modules *ModuleMap) { s.modules = modules } +// SetImportDir sets the initial import directory for script files. +func (s *Script) SetImportDir(dir string) error { + dir, err := filepath.Abs(dir) + if err != nil { + return err + } + s.importDir = dir + return nil +} + // SetMaxAllocs sets the maximum number of objects allocations during the run // time. Compiled script will return ErrObjectAllocLimit error if it // exceeds this limit. @@ -93,6 +105,7 @@ func (s *Script) Compile() (*Compiled, error) { c := NewCompiler(srcFile, symbolTable, nil, s.modules, nil) c.EnableFileImport(s.enableFileImport) + c.SetImportDir(s.importDir) if err := c.Compile(file); err != nil { return nil, err } -- cgit v1.2.3