script

package
v0.0.0-...-371d674 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2018 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExposeFunction

func ExposeFunction(name string, f EFunCreator)

Types

type BindValueWithInstance

type BindValueWithInstance interface {
	SetScriptInstance(ctx *ScriptContext)
}

When binding a variable to the script context that implements this interface it will receive the virtual machine instance used for parsing the script on execution.

type ContextCreator

type ContextCreator interface {
	// GetPrivilegeLevel provides the script privilege level of the creator
	GetScriptPrivilegeLevel() privilege.Level

	// GetScriptReferenceEntity provides a pointer to the entity that
	// is associated with the code that created the script context.
	//
	// This might be nil if no entity is associated with the creator (e.g.
	// specific driver code might not have an entity as the init script)
	GetScriptReferenceEntity() *entity.Entity
}

Everything that creates a script context should implement this interface and refer to itself so we can trace what create a script. This is especially important for taking over creator information like the inherited privilege level

type DriverAPI

type DriverAPI interface {

	// SpawnExcluse creates a new exclusive(!) entity from the given file.
	// it works like SpawnEntity but ensures that the entity exists only once
	// or will return an error
	SpawnExclusive(rpath string, creator ContextCreator) (*entity.Entity, error)

	// SpawnEntity creates a new entity from the given script file
	SpawnEntity(rpath string, creator ContextCreator) (*entity.Entity, error)

	// GetEntityById will return the entity object matching to the given ID or
	// nil in case no entity with this ID was found
	GetEntityById(id string) *entity.Entity

	// Logger() is used to provide a logger for the driver.
	Logger() *logrus.Logger

	// SetHook sets a driver hook to the given value
	SetHook(hook int64, value interface{}) error

	// Shutdown is called when something wants the driver to stop.
	Shutdown(reason string) error

	// Enable or disable a driver subsystem
	SetSubsystemState(stype int64, status bool) error

	// RemoveEntity will take care that entities are set inactive. They
	// are not necessarily deleted right away but must not be accessible
	// after calling this function
	RemoveEntity(id string) error

	// QueueUserEvent is supposed to distribute an event to a user. The
	// payload will be handed unparsed to the given uid.
	QueueUserEvent(token, payload string) error
}

type EFunCreator

type EFunCreator func(ctx *ScriptContext) ExposedFunction

type ExposedFunction

type ExposedFunction interface {
	Function() func(call otto.FunctionCall) otto.Value
	RequiredPrivilegeLevel() privilege.Level
}

type Instance

type Instance struct {
	Vm    *otto.Otto
	Cache *ScriptCache
	// contains filtered or unexported fields
}

type ScriptCache

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

func NewCache

func NewCache() ScriptCache

func (*ScriptCache) Cleanup

func (cache *ScriptCache) Cleanup(olderThan time.Duration)

Cleanup will remove all cache entries older than the given duration

type ScriptContext

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

ScriptContext provides (duh!) a context for running a script. This is required for executing any control scripts and will take care of providing values and embedded functions (efuns)

func ContextForScript

func ContextForScript(driver DriverAPI, script, libDir string, cache *ScriptCache) (ScriptContext, error)

func NewContext

func NewContext(driver DriverAPI, libDir string, cache *ScriptCache) ScriptContext

NewContext generates a new ScriptContext for running a script.

func (*ScriptContext) Bind

func (ctx *ScriptContext) Bind(vname string, value interface{})

Bind allows you to expose internal values and objects to the executed script.

func (ScriptContext) Call

func (ctx ScriptContext) Call(name string, this interface{}, args ...interface{}) (otto.Value, error)

func (ScriptContext) Creator

func (ctx ScriptContext) Creator() ContextCreator

func (ScriptContext) Driver

func (ctx ScriptContext) Driver() DriverAPI

func (ScriptContext) GetFunction

func (ctx ScriptContext) GetFunction(name string) (otto.Value, error)

func (*ScriptContext) GrantPrivilege

func (ctx *ScriptContext) GrantPrivilege(lvl privilege.Level)

GrantPrivilege sets the privilege level of this script context to the defined one. This can be used to allow scripts access to protected functions or restrict their access.

By default a context is created with PrivilegeBasis level.

func (ScriptContext) LoadScript

func (ctx ScriptContext) LoadScript(path string) (string, error)

func (ScriptContext) PrivilegeLevel

func (ctx ScriptContext) PrivilegeLevel() privilege.Level

func (ScriptContext) RaiseError

func (ctx ScriptContext) RaiseError(name, message string)

func (*ScriptContext) RunScript

func (ctx *ScriptContext) RunScript(rpath string) error

RunScrupt executes the script given from the path relative to the drivers library directory.

func (*ScriptContext) SetCreator

func (ctx *ScriptContext) SetCreator(c ContextCreator)

func (ScriptContext) Vm

func (ctx ScriptContext) Vm() *otto.Otto

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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