script

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2020 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const EntryPoint = "main"

EntryPoint defines the name of the method that will be called when running a script (if it exists) in addition to executing top level statements.

Variables

View Source
var (
	// ErrMalformattedKwarg occurs when a keyword argument passed to a starlark function is malformatted.
	ErrMalformattedKwarg = errors.New("malformatted keyword argument for method call")

	// ErrMissingKwarg occurs when a keyword argument is missing from a starlark function call.
	ErrMissingKwarg = errors.New("missing keyword argument for method call")

	// ErrMissingArg occurs when an argument is missing from a starlark function call.
	ErrMissingArg = errors.New("missing argument for method call")

	// ErrInvalidArgType occurs when an argument provided to a starlark function call has the wrong type.
	ErrInvalidArgType = errors.New("invalid argument type provided to method")

	// ErrMissingLibrary occurs when attempting to load a library that doesn't exist.
	ErrMissingLibrary = errors.New("could not find library to load")

	// ErrInvalidTypeConversion occurs when converting a golang type to a starlark.Value fails.
	ErrInvalidTypeConversion = errors.New("could not convert golang value to starlark.Value")

	// ErrInvalidKwarg occurs when a user incorrectly passes a kwarg to a starlark function
	ErrInvalidKwarg = errors.New("invalid kwarg was passed to the method")
)

Functions

This section is empty.

Types

type ArgParser

type ArgParser interface {
	RestrictKwargs(kwargs ...string) error

	GetString(index int) (string, error)
	GetStringByName(name string) (string, error)

	GetInt(index int) (int64, error)
	GetIntByName(name string) (int64, error)

	GetBool(index int) (bool, error)
	GetBoolByName(kwarg string) (bool, error)
}

An ArgParser enables golang function implementations to retrieve the positional and keyword arguments provided to the starlark method call.

type Func

type Func func(args ArgParser) (Retval, error)

Func provides a simple wrapper that enables a golang function to be exposed to starlark.

type Library

type Library map[string]Func

Library is a map of identifiers to underlying golang function implementations.

type Option

type Option func(*Script)

An Option enables additional customization of script configuration and execution.

func WithLibraries

func WithLibraries(libs map[string]Library) Option

WithLibraries adds one or more libraries to the script's execution environment.

func WithLibrary

func WithLibrary(name string, lib Library) Option

WithLibrary is an option to add a library to the script's execution environment.

func WithOutput

func WithOutput(w io.Writer) Option

WithOutput sets the destination for script execution output.

type Retval

type Retval interface{}

Retval TODO

type Script

type Script struct {
	io.Reader // Read() instructions to execute
	io.Writer // Write() execution output
	ID        string
	Builtins  map[string]Func
	Libraries map[string]Library
}

A Script provides metadata and instructions to be executed by the interpreter.

func New

func New(id string, content io.Reader, options ...Option) Script

New initializes and returns a script with the provided contents.

func (Script) Exec

func (script Script) Exec(ctx context.Context) error

Exec parses input from the script reader and executes it. It will also invoke the EntryPoint method if one is available.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package stdlib contains all of the basic building blocks of OS operation.
Package stdlib contains all of the basic building blocks of OS operation.
sys

Jump to

Keyboard shortcuts

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