env

package
v0.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Packages is a where packages can be stored so VM import command can be used to import them.
	// reflect.Value must be valid or VM may crash.
	// For nil must use NilValue.
	Packages = make(map[string]map[string]reflect.Value)
	// PackageTypes is a where package types can be stored so VM import command can be used to import them
	// reflect.Type must be valid or VM may crash.
	// For nil type must use NilType.
	PackageTypes = make(map[string]map[string]reflect.Type)

	// NilType is the reflect.type of nil
	NilType = reflect.TypeOf(nil)
	// NilValue is the reflect.value of nil
	NilValue = reflect.New(reflect.TypeOf((*interface{})(nil)).Elem()).Elem()

	// ErrSymbolContainsDot symbol contains .
	ErrSymbolContainsDot = errors.New("symbol contains '.'")
)

Functions

This section is empty.

Types

type Env

type Env struct {
	// Load will be executed every time there's a call from `load()` in a script.
	Load LoadFrom
	// Import will be called every time there's a local import ex: import .mylib
	Import ImportFrom
	// contains filtered or unexported fields
}

Env is the environment needed for a VM to run in.

func NewEnv

func NewEnv() *Env

NewEnv creates new global scope.

func (*Env) Addr

func (e *Env) Addr(symbol string) (reflect.Value, error)

Addr returns reflect.Addr of value for first matching symbol found in current or parent scope.

func (*Env) Copy

func (e *Env) Copy() *Env

Copy the Env for current scope

func (*Env) DeepCopy

func (e *Env) DeepCopy() *Env

DeepCopy the Env for current scope and parent scopes. Note that each scope is a consistent snapshot but not the whole.

func (*Env) Define

func (e *Env) Define(symbol string, value interface{}) error

Define defines/sets interface value to symbol in current scope.

func (*Env) DefineGlobal

func (e *Env) DefineGlobal(symbol string, value interface{}) error

DefineGlobal defines/sets interface value to symbol in global scope.

func (*Env) DefineGlobalReflectType

func (e *Env) DefineGlobalReflectType(symbol string, reflectType reflect.Type) error

DefineGlobalReflectType defines type in global scope.

func (*Env) DefineGlobalType

func (e *Env) DefineGlobalType(symbol string, aType interface{}) error

DefineGlobalType defines type in global scope.

func (*Env) DefineGlobalValue

func (e *Env) DefineGlobalValue(symbol string, value reflect.Value) error

DefineGlobalValue defines/sets reflect value to symbol in global scope.

func (*Env) DefineMethod added in v0.2.4

func (e *Env) DefineMethod(symbol string, v reflect.Value)

DefineMethod will define a method in a struct.

func (*Env) DefineReflectType

func (e *Env) DefineReflectType(symbol string, reflectType reflect.Type) error

DefineReflectType defines type in current scope.

func (*Env) DefineType

func (e *Env) DefineType(symbol string, aType interface{}) error

DefineType defines type in current scope.

func (*Env) DefineValue

func (e *Env) DefineValue(symbol string, value reflect.Value) error

DefineValue defines/sets reflect value to symbol in current scope.

func (*Env) Delete

func (e *Env) Delete(symbol string)

Delete deletes symbol in current scope.

func (*Env) DeleteGlobal

func (e *Env) DeleteGlobal(symbol string)

DeleteGlobal deletes the first matching symbol found in current or parent scope.

func (*Env) Get

func (e *Env) Get(symbol string) (interface{}, error)

Get returns interface value from the scope where symbol is frist found.

func (*Env) GetEnvFromPath

func (e *Env) GetEnvFromPath(path []string) (*Env, error)

GetEnvFromPath returns Env from path

func (*Env) GetValue

func (e *Env) GetValue(symbol string) (reflect.Value, error)

GetValue returns reflect value from the scope where symbol is frist found.

func (*Env) Method added in v0.2.4

func (e *Env) Method(symbol string) (reflect.Value, error)

Method is used to define methods in structs.

The symbol should be the name of the struct + "." + function name.

func (*Env) NewEnv

func (e *Env) NewEnv() *Env

NewEnv creates new child scope.

func (*Env) NewModule

func (e *Env) NewModule(symbol string) (*Env, error)

NewModule creates new child scope and define it as a symbol. This is a shortcut for calling e.NewEnv then Define that new Env.

func (*Env) Set

func (e *Env) Set(symbol string, value interface{}) error

Set interface value to the scope where symbol is frist found.

func (*Env) SetExternalLookup

func (e *Env) SetExternalLookup(externalLookup ExternalLookup)

SetExternalLookup sets an external lookup

func (*Env) SetValue

func (e *Env) SetValue(symbol string, value reflect.Value) error

SetValue reflect value to the scope where symbol is frist found.

func (*Env) SetValueEvict added in v0.2.1

func (e *Env) SetValueEvict(symbol string, value reflect.Value) (reflect.Value, error)

SetValueEvict returns the last value.

func (*Env) String

func (e *Env) String() string

String returns string of values and types in current scope.

func (*Env) Type

func (e *Env) Type(symbol string) (reflect.Type, error)

Type returns reflect type from the scope where symbol is frist found.

type ExternalLookup

type ExternalLookup interface {
	Get(string) (reflect.Value, error)
	Type(string) (reflect.Type, error)
}

ExternalLookup for Env external lookup of values and types.

type ImportFrom added in v0.2.1

type ImportFrom func(string) (*Env, error)

Import implements a script importing.

The function will get the package name and must return the env of the executed script or an error.

type LoadFrom added in v0.2.1

type LoadFrom func(string) (string, error)

LoadFrom implements a script loader that will be called when the user calls the function `load` from a script.

Must return the body of the script or an error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL