ankiddie

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2019 License: MIT Imports: 11 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyStarted = errors.New("environment already started")

ErrAlreadyStarted when an environment had already been started

View Source
var ErrAlreadySuspended = errors.New("environment already suspended")

ErrAlreadySuspended when an environment is already suspended

View Source
var ErrNoPersister = errors.New("script persister not specified")

ErrNoPersister when a script persister is not specified

Functions

This section is empty.

Types

type Ankiddie

type Ankiddie struct {
	// contains filtered or unexported fields
}

Ankiddie manages the execution of anko scripts

func New

func New(configurator PackageConfigurator, store ScriptPersister) *Ankiddie

New returns a new Ankiddie

func (*Ankiddie) Environment

func (ssys *Ankiddie) Environment(eid uint) (*Environment, bool)

Environment returns the environment with the given ID, if one exists

func (*Ankiddie) Environments

func (ssys *Ankiddie) Environments() map[uint]*Environment

Environments returns a map with the currently registered environments

func (*Ankiddie) ForgetEnv

func (ssys *Ankiddie) ForgetEnv(env *Environment)

ForgetEnv stops execution of the given environment as far as possible and unregisters it

func (*Ankiddie) FullReset

func (ssys *Ankiddie) FullReset()

FullReset stops execution on all environments and destroys them

func (*Ankiddie) NewEnvWithCode

func (ssys *Ankiddie) NewEnvWithCode(code string, out func(env *Environment, msg string) error) *Environment

NewEnvWithCode returns a new Environment ready to run the provided code

func (*Ankiddie) NewEnvWithScript

func (ssys *Ankiddie) NewEnvWithScript(script *Script, out func(env *Environment, msg string) error) *Environment

NewEnvWithScript returns a new Environment ready to run the provided Script

func (*Ankiddie) SaveScript

func (ssys *Ankiddie) SaveScript(id string, code string) (*Script, error)

SaveScript saves a script to the database under the specified ID If no ID is provided, a UUID is generated If a script with the same ID already existed, it is overwritten

func (*Ankiddie) StartAutorun

func (ssys *Ankiddie) StartAutorun(level int, async bool, out func(env *Environment, msg string) error) error

StartAutorun executes scripts at the specified autorun level

type Environment

type Environment struct {
	// contains filtered or unexported fields
}

Environment is a anko environment managed by Ankiddie

func (*Environment) Dirty

func (env *Environment) Dirty() bool

Dirty returns whether the code associated with this environment has had changes since the environment was created

func (*Environment) EID

func (env *Environment) EID() uint

EID returns the environment ID

func (*Environment) Execute

func (env *Environment) Execute(source string, appendToSrc bool) (interface{}, error)

Execute parses and runs source in current scope

func (*Environment) Forget

func (env *Environment) Forget()

Forget stops execution of the given environment as far as possible and unregisters it

func (*Environment) Restart

func (env *Environment) Restart() (interface{}, error)

Restart restarts the execution on the environment

func (*Environment) SaveScript

func (env *Environment) SaveScript(id string) (*Script, error)

SaveScript saves the script to the database under the specified ID If no ID is provided, the script is saved under its original ID If the script did not have an ID associated, a UUID is generated

func (*Environment) ScriptID

func (env *Environment) ScriptID() string

ScriptID returns the script ID associated with this environment

func (*Environment) Start

func (env *Environment) Start() (interface{}, error)

Start parses and runs the source associated with the environment

func (*Environment) Started

func (env *Environment) Started() bool

Started returns whether execution has ever started in this environment

func (*Environment) Suspend

func (env *Environment) Suspend() error

Suspend stops the execution on the environment without destroying its state

func (*Environment) Suspended

func (env *Environment) Suspended() bool

Suspended returns whether execution is suspended in this environment

type PackageConfigurator

type PackageConfigurator interface {
	ConfigurePackages(packages map[string]map[string]reflect.Value, packageTypes map[string]map[string]reflect.Type)
}

PackageConfigurator configures additional packages to expose to anko environments

type Script

type Script struct {
	ID      string
	Type    string
	Autorun int
	Code    string
	Notes   string
}

Script contains dynamic behavior for the system to implement at run time

type ScriptLoader

type ScriptLoader interface {
	// GetScript should return an error if a script with the specified ID does not exist
	GetScript(id string) (*Script, error)
	GetAutorunScripts(autorunLevel int) ([]*Script, error)
}

ScriptLoader loads scripts from storage

type ScriptPersister

type ScriptPersister interface {
	ScriptLoader
	ScriptStorer
}

ScriptPersister loads and stores scripts from storage

type ScriptStorer

type ScriptStorer interface {
	StoreScript(script *Script) error
}

ScriptStorer stores scripts to storage

Jump to

Keyboard shortcuts

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