Documentation
¶
Overview ¶
Package starbox provides a set of utilities for building Starlark virtual machine.
Index ¶
- func NewMemory() *dataconv.SharedDict
- func SetLog(l *zap.SugaredLogger)
- type InspectCondFunc
- 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) AddStarlarkValues(keyValues starlark.StringDict)
- func (s *Starbox) AttachMemory(name string, memory *dataconv.SharedDict)
- func (s *Starbox) CreateMemory(name string) *dataconv.SharedDict
- 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) RunInspectIf(script string, cond InspectCondFunc) (starlet.StringAnyMap, error)
- func (s *Starbox) RunTimeout(script string, timeout time.Duration) (starlet.StringAnyMap, error)
- func (s *Starbox) SetFS(hfs fs.FS)
- 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 ¶
func NewMemory ¶ added in v0.0.3
func NewMemory() *dataconv.SharedDict
NewMemory creates a new shared dictionary for la mémoire collective.
Types ¶
type InspectCondFunc ¶ added in v0.0.2
type InspectCondFunc func(starlet.StringAnyMap, error) bool
InspectCondFunc is a function type for inspecting the converted output of Run*() and decide whether to continue.
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) AddStarlarkValues ¶ added in v0.0.2
func (s *Starbox) AddStarlarkValues(keyValues starlark.StringDict)
AddStarlarkValues adds key-value pairs to the global environment before running, the values are already converted to Starlark values. For each key-value pair, if the key already exists, it will be overwritten. It panics if called after running.
func (*Starbox) AttachMemory ¶ added in v0.0.3
func (s *Starbox) AttachMemory(name string, memory *dataconv.SharedDict)
AttachMemory adds a shared dictionary to the global environment before running.
func (*Starbox) CreateMemory ¶ added in v0.0.3
func (s *Starbox) CreateMemory(name string) *dataconv.SharedDict
CreateMemory creates a new shared dictionary for la mémoire collective with the given name, and adds it to the global environment before 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) RunInspectIf ¶ added in v0.0.2
func (s *Starbox) RunInspectIf(script string, cond InspectCondFunc) (starlet.StringAnyMap, error)
RunInspectIf executes a script and then REPL with result and returns the converted output, if the condition is met. The condition function is called with the converted output and the error from Run*(), and returns true if REPL is needed.
func (*Starbox) RunTimeout ¶
RunTimeout executes a script and returns the converted output.
func (*Starbox) SetFS ¶ added in v0.0.3
SetFS sets the virtual filesystem for module scripts. If it's not nil, it'll override all the scripts added by AddModuleScript(). It panics if called after running.
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.