Documentation
¶
Index ¶
- Constants
- Variables
- func AllModuleNames() []string
- func Commit() string
- func CompileAndRun(ctx context.Context, data []byte, inputFile string, args []string) (err error)
- func CompileOnly(data []byte, inputFile, outputFile string) (err error)
- func Exports() map[string]map[string]*module.Export
- func GetExportMap(names ...string) map[string]map[string]*module.Export
- func GetModuleMap(names ...string) *vm.ModuleMap
- func Modules() *vm.ModuleMap
- func RunCompiled(ctx context.Context, data []byte, args []string) (err error)
- func RunREPL(ctx context.Context, in io.Reader, out io.Writer, prompt string, ...)
- func Version() string
- type Program
- func (p *Program) Bytecode() *vm.Bytecode
- func (p *Program) Clone() *Program
- func (p *Program) Equals(other *Program) bool
- func (p *Program) Get(name string) *Variable
- func (p *Program) GetAll() []*Variable
- func (p *Program) IsDefined(name string) bool
- func (p *Program) Marshal() ([]byte, error)
- func (p *Program) Run() error
- func (p *Program) RunContext(ctx context.Context) (err error)
- func (p *Program) Set(name string, value interface{}) error
- func (p *Program) SetArgs(args []string)
- func (p *Program) Unmarshal(b []byte) (err error)
- type Script
- func (s *Script) Add(name string, value interface{}) error
- func (s *Script) Compile() (*Program, error)
- func (s *Script) EnableFileImport(enable bool)
- func (s *Script) Remove(name string) bool
- func (s *Script) Run() (program *Program, err error)
- func (s *Script) RunContext(ctx context.Context) (program *Program, err error)
- func (s *Script) SetImportDir(dir string) error
- func (s *Script) SetImports(modules *vm.ModuleMap)
- func (s *Script) SetMaxAllocs(n int64)
- func (s *Script) SetMaxConstObjects(n int)
- func (s *Script) SetName(name string)
- type Variable
- func (v *Variable) Array() []interface{}
- func (v *Variable) Bool() bool
- func (v *Variable) Bytes() []byte
- func (v *Variable) Char() rune
- func (v *Variable) Error() error
- func (v *Variable) Float() float64
- func (v *Variable) Int() int
- func (v *Variable) Int64() int64
- func (v *Variable) IsUndefined() bool
- func (v *Variable) Map() map[string]interface{}
- func (v *Variable) Name() string
- func (v *Variable) Object() vm.Object
- func (v *Variable) String() string
- func (v *Variable) Value() interface{}
- func (v *Variable) ValueType() string
Constants ¶
const Magic = "VVC\x00"
Magic is a magic number every encoded Program starts with. format: [4]MAGIC [4]SIZE [N]DATA [8]CRC64(ECMA)
Variables ¶
var BuiltinModules = map[string]*module.BuiltinModule{ "base64": base64.Module, "cui": cui.Module, "fmt": fmt.Module, "hex": hex.Module, "json": json.Module, "math": math.Module, "rand": rand.Module, "shell": shell.Module, "text": text.Module, "times": times.Module, }
BuiltinModules are builtin type standard library modules.
var SourceModules = map[string]*module.SourceModule{ "enum": module.NewSource("is_enumerable := func(x) {\n return is_array(x) || is_map(x) || is_immutable_array(x) || is_immutable_map(x)\n}\n\nis_array_like := func(x) {\n return is_array(x) || is_immutable_array(x)\n}\n\nexport {\n // all(x map, fn func(key, value) bool) (result bool)\n // all returns true if the given function 'fn' evaluates to a truthy value on\n // all of the items in 'x'. It returns undefined if 'x' is not enumerable.\n all: func(x, fn) {\n if !is_enumerable(x) { return undefined }\n\n for k, v in x {\n if !fn(k, v) { return false }\n }\n\n return true\n },\n\n // any(x map, fn func(key, value) bool) (result bool)\n // any returns true if the given function 'fn' evaluates to a truthy value on\n // any of the items in 'x'. It returns undefined if 'x' is not enumerable.\n any: func(x, fn) {\n if !is_enumerable(x) { return undefined }\n\n for k, v in x {\n if fn(k, v) { return true }\n }\n\n return false\n },\n\n // chunk(x array, size int) (result array)\n // chunk returns an array of elements split into groups the length of size.\n // If 'x' can't be split evenly, the final chunk will be the remaining elements.\n // It returns undefined if 'x' is not array.\n chunk: func(x, size) {\n if !is_array_like(x) || !size { return undefined }\n\n numElements := len(x)\n if !numElements { return [] }\n\n res := []\n idx := 0\n for idx < numElements {\n res = append(res, x[idx:idx+size])\n idx += size\n }\n\n return res\n },\n\n // at(x map, key string) (result any)\n // at returns an element at the given index (if 'x' is array) or\n // key (if 'x' is map). It returns undefined if 'x' is not enumerable.\n at: func(x, key) {\n if !is_enumerable(x) { return undefined }\n\n if is_array_like(x) {\n if !is_int(key) { return undefined }\n } else {\n if !is_string(key) { return undefined }\n }\n\n return x[key]\n },\n\n // each(x map, fn func(key, value)) (result undefined)\n // each iterates over elements of 'x' and invokes 'fn' for each element. 'fn' is\n // invoked with two arguments: 'key' and 'value'. 'key' is an int index\n // if 'x' is array. 'key' is a string key if 'x' is map. It does not iterate\n // and returns undefined if 'x' is not enumerable.\n each: func(x, fn) {\n if !is_enumerable(x) { return undefined }\n\n for k, v in x {\n fn(k, v)\n }\n },\n\n // filter(x map, fn func(key, value) bool) (result array)\n // filter iterates over elements of 'x', returning an array of all elements 'fn'\n // returns truthy for. 'fn' is invoked with two arguments: 'key' and 'value'.\n // 'key' is an int index if 'x' is array. 'key' is a string key if 'x' is map.\n // It returns undefined if 'x' is not enumerable.\n filter: func(x, fn) {\n if !is_array_like(x) { return undefined }\n\n dst := []\n for k, v in x {\n if fn(k, v) { dst = append(dst, v) }\n }\n\n return dst\n },\n\n // find(x map, fn func(key, value) bool) (result any)\n // find iterates over elements of 'x', returning value of the first element 'fn'\n // returns truthy for. 'fn' is invoked with two arguments: 'key' and 'value'.\n // 'key' is an int index if 'x' is array. 'key' is a string key if 'x' is map.\n // It returns undefined if 'x' is not enumerable.\n find: func(x, fn) {\n if !is_enumerable(x) { return undefined }\n\n for k, v in x {\n if fn(k, v) { return v }\n }\n },\n\n // find_key(x map, fn func(key, value) bool) (result any)\n // find_key iterates over elements of 'x', returning key or index of the first\n // element 'fn' returns truthy for. 'fn' is invoked with two arguments: 'key'\n // and 'value'. 'key' is an int index if 'x' is array. 'key' is a string key if\n // 'x' is map. It returns undefined if 'x' is not enumerable.\n find_key: func(x, fn) {\n if !is_enumerable(x) { return undefined }\n\n for k, v in x {\n if fn(k, v) { return k }\n }\n },\n\n // map(x map, fn func(key, value) any) (result array)\n // map creates an array of values by running each element in 'x' through 'fn'.\n // 'fn' is invoked with two arguments: 'key' and 'value'. 'key' is an int index\n // if 'x' is array. 'key' is a string key if 'x' is map. It returns undefined\n // if 'x' is not enumerable.\n map: func(x, fn) {\n if !is_enumerable(x) { return undefined }\n\n dst := []\n for k, v in x {\n dst = append(dst, fn(k, v))\n }\n\n return dst\n },\n\n // key(k, v) (result any)\n // key returns the first argument.\n key: func(k, _) { return k },\n\n // value(k, v) (result any)\n // value returns the second argument.\n value: func(_, v) { return v }\n}\n"), }
SourceModules are source type standard library modules.
Functions ¶
func AllModuleNames ¶
func AllModuleNames() []string
AllModuleNames returns a list of all default module names.
func CompileAndRun ¶
CompileAndRun compiles the source code and executes it.
func CompileOnly ¶
CompileOnly compiles the source code and writes the compiled binary into outputFile.
func Exports ¶
Exports returns the lazily-initialized export map of all standard library modules. The map is computed on first call and cached for subsequent calls.
func GetExportMap ¶
GetExportMap returns the export map of all modules for the given module names.
func GetModuleMap ¶
GetModuleMap returns the module map that includes all modules for the given module names.
func Modules ¶
Modules returns the lazily-initialized module map containing all standard library modules. The map is computed on first call and cached for subsequent calls. (Issue #11: avoids eager init that forces all stdlib into every binary.)
func RunCompiled ¶
RunCompiled reads the compiled binary from file and executes it.
Types ¶
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program is a compiled instance of the user script. Use Script.Compile() to create Compiled object.
func (*Program) Clone ¶
Clone creates a new copy of Compiled. Cloned copies are safe for concurrent use by multiple goroutines.
func (*Program) IsDefined ¶
IsDefined returns true if the variable name is defined (has value) before or after the execution.
func (*Program) RunContext ¶
RunContext is like Run but includes a context.
func (*Program) Set ¶
Set replaces the value of a global variable identified by the name. An error will be returned if the name was not defined during compilation.
type Script ¶
type Script struct {
// contains filtered or unexported fields
}
Script can simplify compilation and execution of embedded scripts.
func (*Script) Compile ¶
Compile compiles the script with all the defined variables and returns Program object.
func (*Script) EnableFileImport ¶
EnableFileImport enables or disables module loading from local files. Local file modules are disabled by default.
func (*Script) Remove ¶
Remove removes (undefines) an existing variable for the script. It returns false if the variable name is not defined.
func (*Script) Run ¶
Run compiles and runs the scripts. Use returned compiled object to access global variables.
func (*Script) RunContext ¶
RunContext is like Run but includes a context.
func (*Script) SetImportDir ¶
SetImportDir sets the initial import directory for script files.
func (*Script) SetImports ¶
SetImports sets import modules.
func (*Script) SetMaxAllocs ¶
SetMaxAllocs sets the maximum number of objects allocations during the run time. Compiled script will return ErrObjectAllocLimit error if it exceeds this limit.
func (*Script) SetMaxConstObjects ¶
SetMaxConstObjects sets the maximum number of objects in the compiled constants.
type Variable ¶
type Variable struct {
// contains filtered or unexported fields
}
Variable is a user-defined variable for the script.
func NewVariable ¶
NewVariable creates a Variable.
func (*Variable) Array ¶
func (v *Variable) Array() []interface{}
Array returns []interface value of the variable value. It returns nil if the value is not convertible to []interface.
func (*Variable) Bool ¶
Bool returns bool value of the variable value. It returns false if the value is not convertible to bool.
func (*Variable) Bytes ¶
Bytes returns a byte slice of the variable value. It returns nil if the value is not convertible to byte slice.
func (*Variable) Char ¶
Char returns rune value of the variable value. It returns 0 if the value is not convertible to rune.
func (*Variable) Error ¶
Error returns an error if the underlying value is error object. If not, this returns nil.
func (*Variable) Float ¶
Float returns float64 value of the variable value. It returns 0.0 if the value is not convertible to float64.
func (*Variable) Int ¶
Int returns int value of the variable value. It returns 0 if the value is not convertible to int.
func (*Variable) Int64 ¶
Int64 returns int64 value of the variable value. It returns 0 if the value is not convertible to int64.
func (*Variable) IsUndefined ¶
IsUndefined returns true if the underlying value is undefined.
func (*Variable) Map ¶
Map returns map[string]interface{} value of the variable value. It returns nil if the value is not convertible to map[string]interface{}.
func (*Variable) Object ¶
Object returns an underlying Object of the variable value. Note that returned Object is a copy of an actual Object used in the script.
func (*Variable) String ¶
String returns string value of the variable value. It returns an empty string if the value is not convertible to string.
Directories
¶
| Path | Synopsis |
|---|---|
|
cui
Package cui implements rich widgets for terminal based user interfaces.
|
Package cui implements rich widgets for terminal based user interfaces. |
|
cui/demo/barchart
command
Demo code for the bar chart widget.
|
Demo code for the bar chart widget. |
|
cui/demo/box
command
Demo code for the Box widget.
|
Demo code for the Box widget. |
|
cui/demo/button
command
Demo code for the Button widget.
|
Demo code for the Button widget. |
|
cui/demo/checkbox
command
Demo code for the CheckBox widget.
|
Demo code for the CheckBox widget. |
|
cui/demo/dialog
command
Demo code for the bar chart widget.
|
Demo code for the bar chart widget. |
|
cui/demo/dropdown
command
Demo code for the DropDown widget.
|
Demo code for the DropDown widget. |
|
cui/demo/edit
command
|
|
|
cui/demo/edit/autocomplete
command
Demo code for edit.View autocomplete.
|
Demo code for edit.View autocomplete. |
|
cui/demo/flex
command
Demo code for the Flex widget.
|
Demo code for the Flex widget. |
|
cui/demo/focusmanager
command
Demo code for the FocusManager utility.
|
Demo code for the FocusManager utility. |
|
cui/demo/form
command
Demo code for the Form widget.
|
Demo code for the Form widget. |
|
cui/demo/frame
command
Demo code for the Frame widget.
|
Demo code for the Frame widget. |
|
cui/demo/gauge_pm
command
Demo code for the bar chart widget.
|
Demo code for the bar chart widget. |
|
cui/demo/gauge_um
command
Demo code for the bar chart widget.
|
Demo code for the bar chart widget. |
|
cui/demo/grid
command
Demo code for the Grid widget.
|
Demo code for the Grid widget. |
|
cui/demo/hexview
command
Demo code for the Box widget.
|
Demo code for the Box widget. |
|
cui/demo/image
command
|
|
|
cui/demo/inputfield/autocomplete
command
|
|
|
cui/demo/inputfield/simple
command
Demo code for the InputField widget.
|
Demo code for the InputField widget. |
|
cui/demo/list
command
Demo code for the List widget.
|
Demo code for the List widget. |
|
cui/demo/menu
command
|
|
|
cui/demo/modal
command
Demo code for the Modal widget.
|
Demo code for the Modal widget. |
|
cui/demo/panels
command
Demo code for the Panels widget.
|
Demo code for the Panels widget. |
|
cui/demo/plot
command
|
|
|
cui/demo/plot_x_labels
command
|
|
|
cui/demo/presentation
command
A presentation of the cui package, implemented with cui.
|
A presentation of the cui package, implemented with cui. |
|
cui/demo/primitive
command
Demo code which illustrates how to implement your own widget.
|
Demo code which illustrates how to implement your own widget. |
|
cui/demo/progressbar
command
Demo code for the ProgressBar widget.
|
Demo code for the ProgressBar widget. |
|
cui/demo/sparkline
command
|
|
|
cui/demo/spinner
command
|
|
|
cui/demo/tabbedpanels
command
Demo code for the TabbedPanels widget.
|
Demo code for the TabbedPanels widget. |
|
cui/demo/table
command
Demo code for the Table widget.
|
Demo code for the Table widget. |
|
cui/demo/textview
command
Demo code for the TextView widget.
|
Demo code for the TextView widget. |
|
cui/demo/treeview
command
Demo code for the TreeView widget.
|
Demo code for the TreeView widget. |
|
cui/demo/unicode
command
Demo code for unicode support (demonstrates wide Chinese characters).
|
Demo code for unicode support (demonstrates wide Chinese characters). |
|
cui/demo/vte/bash
command
Demo showing how to run an interactive shell inside a cui terminal widget.
|
Demo showing how to run an interactive shell inside a cui terminal widget. |
|
cui/demo/vte/command
command
Demo showing how to run a one-shot command inside a cui terminal widget.
|
Demo showing how to run a one-shot command inside a cui terminal widget. |
|
cui/demo/vte/shell
command
|
|
|
cui/demo/vte/ssh
command
|
|
|
cui/demo/whichkeybind
command
|
|
|
cui/edit/runtime/files/syntax
command
|
|
|
cui/vte/pty/examples/command
command
|
|
|
cui/vte/pty/examples/shell
command
|
|
|
cui/vte/pty/examples/ssh
command
|
|
|
shell/term
Package term provides support functions for dealing with terminals, as commonly found on UNIX systems.
|
Package term provides support functions for dealing with terminals, as commonly found on UNIX systems. |
|
Package vm provides a virtual machine for executing rumo bytecode
|
Package vm provides a virtual machine for executing rumo bytecode |
|
codec
Package codec provides functions to marshal and unmarshal data types.
|
Package codec provides functions to marshal and unmarshal data types. |