scripts

package
v0.53.3 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package scripts allows the Go code to be executed as a script.

Package scripts is EXPERIMENTAL. There is no guarantee that it will be included in the 1.0 version of Scriggo and could be removed at any time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildError added in v0.47.0

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

BuildError represents an error occurred building a script.

func (*BuildError) Error added in v0.47.0

func (err *BuildError) Error() string

Error returns a string representation of the error.

func (*BuildError) Message added in v0.47.0

func (err *BuildError) Message() string

Message returns the error message.

func (*BuildError) Path added in v0.47.0

func (err *BuildError) Path() string

Path returns the path of the file where the error occurred.

func (*BuildError) Position added in v0.47.0

func (err *BuildError) Position() scriggo.Position

Position returns the position in the file where the error occurred.

type BuildOptions added in v0.31.0

type BuildOptions struct {

	// AllowGoStmt, when true, allows the use of the go statement.
	AllowGoStmt bool

	// Packages is a package importer that makes native packages available
	// in scripts through the import statement.
	Packages native.Importer

	// Globals declares constants, types, variables, functions and packages
	// that are accessible from the code in the script.
	Globals native.Declarations
}

BuildOptions contains options for building scripts.

type PanicError added in v0.47.0

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

PanicError represents the error that occurs when an executed script calls the panic built-in and the panic is not recovered.

func (*PanicError) Error added in v0.47.0

func (p *PanicError) Error() string

Error returns all currently active panics as a string.

To print only the message, use the String method instead.

func (*PanicError) Message added in v0.47.0

func (p *PanicError) Message() interface{}

Message returns the panic message.

func (*PanicError) Next added in v0.47.0

func (p *PanicError) Next() *PanicError

Next returns the next panic in the chain.

func (*PanicError) Path added in v0.47.0

func (p *PanicError) Path() string

Path returns the path of the file that panicked.

func (*PanicError) Position added in v0.47.0

func (p *PanicError) Position() scriggo.Position

Position returns the position in file where the panic occurred.

func (*PanicError) Recovered added in v0.47.0

func (p *PanicError) Recovered() bool

Recovered reports whether it has been recovered.

func (*PanicError) String added in v0.47.0

func (p *PanicError) String() string

String returns the panic message as a string.

type RunOptions

type RunOptions struct {

	// Context is a context that can be read by native functions and methods
	// via the Context method of native.Env. Canceling the context, the
	// execution is terminated and the Run method returns Context.Err().
	Context context.Context

	// Print is called by the print and println builtins to print values.
	// If it is nil, the print and println builtins format their arguments as
	// expected and write the result to standard error.
	Print scriggo.PrintFunc
}

RunOptions are the run options.

type Script

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

Script is a script compiled with the Build function.

func Build added in v0.31.0

func Build(src io.Reader, options *BuildOptions) (*Script, error)

Build builds a script reading the source code from src.

If a build error occurs, it returns a *BuildError.

func (*Script) Disassemble

func (p *Script) Disassemble() []byte

Disassemble disassembles the script and returns its assembly code.

func (*Script) Run

func (p *Script) Run(vars map[string]interface{}, options *RunOptions) error

Run starts the script and waits for it to complete. vars contains the values of the global variables.

If the executed script panics, and it is not recovered, Run returns a *PanicError.

If the Stop method of native.Env is called, Run returns the argument passed to Stop.

If the exit builtin is called, Run returns a scriggo.ExitError with the exit code.

If the Fatal method of native.Env is called, Run panics with the argument passed to Fatal.

If the context has been canceled, Run returns the error returned by the Err method of the context.

Jump to

Keyboard shortcuts

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