Documentation
¶
Index ¶
- Constants
- Variables
- func Eval(ctx context.Context, expr string, params map[string]any) (any, error)
- func MustValueOf(v any) core.Value
- func ValueOf(v any) (core.Value, error)
- type Compiled
- func (c *Compiled) Clone() (*Compiled, error)
- func (c *Compiled) Get(name string) core.Value
- func (c *Compiled) GetAll() map[string]core.Value
- func (c *Compiled) Reset()
- func (c *Compiled) Run(v *vm.VM) error
- func (c *Compiled) RunContext(ctx context.Context, v *vm.VM) (err error)
- func (c *Compiled) Set(name string, val core.Value) error
- type Script
- func (s *Script) AddCustomModule(name string, source []byte)
- func (s *Script) AddGlobals(globals ...string)
- func (s *Script) Compile() (*Compiled, error)
- func (s *Script) DisableFileImport()
- func (s *Script) EnableFileImport(path string) error
- func (s *Script) SetAllowedModules(modules ...string)
- func (s *Script) SetAssignmentMode(mode compiler.AssignmentMode)
- func (s *Script) SetGlobals(globals ...string)
- func (s *Script) SetSource(source []byte)
Constants ¶
const ( // SourceFileExtDefault is the default extension for source files. SourceFileExtDefault = ".kvn" UsedDefinedModule = module.UserDefined UserDefinedType = value.FirstUserDefinedType )
Variables ¶
var ( NewBuiltinFunction = core.NewBuiltinFunction InitModule = stdlib.InitModule AllModuleNames = stdlib.AllModuleNames )
Functions ¶
func Eval ¶
Eval compiles and executes given expr with params, and returns an evaluated value. Argument `expr` must be an expression. Otherwise it will fail to compile. Expression must not use or define variable "__res__" as it's reserved for the internal usage.
func MustValueOf ¶ added in v0.4.1
Types ¶
type Compiled ¶
type Compiled struct {
// contains filtered or unexported fields
}
Compiled is a compiled instance of the user script. Use Script.Compile() to create Compiled object.
func (*Compiled) Get ¶
Get returns the value of a variable identified by the name. If the variable is not defined, it returns Undefined.
func (*Compiled) Reset ¶ added in v0.4.1
func (c *Compiled) Reset()
Reset sets all global variable values to Undefined.
func (*Compiled) Run ¶
Executes script in the provided virtual machine. It is the caller's responsibility to set all global variables to new values before calling Run.
func (*Compiled) RunContext ¶
Run executes the compiled script in the provided virtual machine with a context for cancellation. It is the caller's responsibility to set all global variables to new values before calling Run.
type Script ¶
type Script struct {
// contains filtered or unexported fields
}
Script represents a script with its source code, variables, and compilation settings. It simplifies the process of compiling and executing embedded scripts by managing the necessary components and configurations.
func NewScript ¶
NewScript creates a Script instance with the given source code and global variable names (optional). The script is initialized with default settings, including smart assignment mode, file import disabled and all builtin modules allowed.
func (*Script) AddCustomModule ¶ added in v0.4.1
AddCustomModule adds a custom module with the given name and source code.
func (*Script) AddGlobals ¶ added in v0.4.1
AddGlobals adds new global variable names to the script.
func (*Script) Compile ¶
Compile compiles the script and returns a Compiled instance containing bytecode and global variable indexes.
func (*Script) DisableFileImport ¶ added in v0.4.1
func (s *Script) DisableFileImport()
DisableFileImport disables file import for the script.
func (*Script) EnableFileImport ¶
EnableFileImport enables file import for the script, allowing it to import other scripts from the specified directory.
func (*Script) SetAllowedModules ¶ added in v0.4.1
SetAllowedModules sets the allowed builtin module names for import. If not set, all modules are allowed.
func (*Script) SetAssignmentMode ¶
func (s *Script) SetAssignmentMode(mode compiler.AssignmentMode)
SetAssignmentMode sets how plain '=' handles unresolved identifiers during compilation.
func (*Script) SetGlobals ¶ added in v0.4.1
SetGlobals sets the global variable names for the script.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
bench
command
|
|
|
gen-templates
command
|
|
|
kavun
command
|
|
|
Package errs defines the structured error type used throughout the Kavun runtime.
|
Package errs defines the structured error type used throughout the Kavun runtime. |
|
internal
|
|
