Documentation
¶
Overview ¶
Package starbox provides a set of utilities for building Starlark virtual machine.
Index ¶
- func SetLog(l *zap.SugaredLogger)
- type ModuleSetName
- type Starbox
- func (s *Starbox) AddBuiltin(name string, starFunc StarlarkFunc)
- func (s *Starbox) AddKeyValue(key string, value interface{})
- func (s *Starbox) AddKeyValues(keyValues starlet.StringAnyMap)
- func (s *Starbox) AddModuleData(moduleName string, moduleData starlark.StringDict)
- func (s *Starbox) AddModuleLoader(moduleName string, moduleLoader starlet.ModuleLoader)
- func (s *Starbox) AddModuleScript(moduleName, moduleScript string)
- func (s *Starbox) AddNamedModules(moduleNames ...string)
- func (s *Starbox) GetMachine() *starlet.Machine
- func (s *Starbox) REPL() error
- func (s *Starbox) Reset()
- func (s *Starbox) Run(script string) (starlet.StringAnyMap, error)
- func (s *Starbox) RunInspect(script string) (starlet.StringAnyMap, error)
- func (s *Starbox) RunTimeout(script string, timeout time.Duration) (starlet.StringAnyMap, error)
- func (s *Starbox) SetModuleSet(modSet ModuleSetName)
- func (s *Starbox) SetPrintFunc(printFunc starlet.PrintFunc)
- func (s *Starbox) SetStructTag(tag string)
- func (s *Starbox) String() string
- type StarlarkFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ModuleSetName ¶
type ModuleSetName string
ModuleSetName defines the name of a module set.
const ( // EmptyModuleSet represents the predefined module set for empty scripts, it contains no modules. EmptyModuleSet ModuleSetName = "none" // SafeModuleSet represents the predefined module set for safe scripts, it contains only safe modules that do not have side effects with outside world. SafeModuleSet ModuleSetName = "safe" // NetworkModuleSet represents the predefined module set for network scripts, it's based on SafeModuleSet with additional network modules. NetworkModuleSet ModuleSetName = "network" // FullModuleSet represents the predefined module set for full scripts, it includes all available modules. FullModuleSet ModuleSetName = "full" )
type Starbox ¶
type Starbox struct {
// contains filtered or unexported fields
}
Starbox is a wrapper of starlet.Machine with additional features.
func (*Starbox) AddBuiltin ¶
func (s *Starbox) AddBuiltin(name string, starFunc StarlarkFunc)
AddBuiltin adds a builtin function with name to the global environment before running. If the name already exists, it will be overwritten. It panics if called after running.
func (*Starbox) AddKeyValue ¶
AddKeyValue adds a key-value pair to the global environment before running. If the key already exists, it will be overwritten. It panics if called after running.
func (*Starbox) AddKeyValues ¶
func (s *Starbox) AddKeyValues(keyValues starlet.StringAnyMap)
AddKeyValues adds key-value pairs to the global environment before running. Usually for output of Run()*. For each key-value pair, if the key already exists, it will be overwritten. It panics if called after running.
func (*Starbox) AddModuleData ¶
func (s *Starbox) AddModuleData(moduleName string, moduleData starlark.StringDict)
AddModuleData creates a module for the given module data along with a module loader, and adds it to the preload and lazyload registry. The given module data can be accessed in script via load("module_name", "key1") or module_name.key1. It panics if called after running.
func (*Starbox) AddModuleLoader ¶
func (s *Starbox) AddModuleLoader(moduleName string, moduleLoader starlet.ModuleLoader)
AddModuleLoader adds a custom module loader to the preload and lazyload registry. It will not load the module until the first run, and load result can be accessed in script via load("module_name", "key1") or key1 directly. It panics if called after running.
func (*Starbox) AddModuleScript ¶
AddModuleScript creates a module with given module script in virtual filesystem, and adds it to the preload and lazyload registry. The given module script can be accessed in script via load("module_name", "key1") or load("module_name.star", "key1") if module name has no ".star" suffix. It panics if called after running.
func (*Starbox) AddNamedModules ¶
AddNamedModules adds builtin modules by name to the preload and lazyload registry. It will not load the modules until the first run. It panics if called after running.
func (*Starbox) GetMachine ¶
GetMachine returns the underlying starlet.Machine instance.
func (*Starbox) Reset ¶
func (s *Starbox) Reset()
Reset creates an new Starlet machine and keeps the settings.
func (*Starbox) Run ¶
func (s *Starbox) Run(script string) (starlet.StringAnyMap, error)
Run executes a script and returns the converted output.
func (*Starbox) RunInspect ¶
func (s *Starbox) RunInspect(script string) (starlet.StringAnyMap, error)
RunInspect executes a script and then REPL with result and returns the converted output.
func (*Starbox) RunTimeout ¶
RunTimeout executes a script and returns the converted output.
func (*Starbox) SetModuleSet ¶
func (s *Starbox) SetModuleSet(modSet ModuleSetName)
SetModuleSet sets the module set to be loaded before running. It panics if called after running.
func (*Starbox) SetPrintFunc ¶
SetPrintFunc sets the print function for Starlark. It panics if called after running.
func (*Starbox) SetStructTag ¶
SetStructTag sets the custom tag of Go struct fields for Starlark. It panics if called after running.