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 loader that makes native packages available
// in scripts through the import statement.
Packages native.PackageLoader
// 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 or the Panic method of native.Env is called 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.
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 ¶
Disassemble disassembles the script and returns its assembly code.
func (*Script) MustRun ¶
func (p *Script) MustRun(vars map[string]interface{}, options *RunOptions)
MustRun is like Run but panics with the returned error if the run fails.
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 or the Panic method of native.Env is called, and the panic is not recovered, Run returns a *PanicError.
If the Exit method of native.Env is called with a non-zero code, Run returns a *ExitError with the exit code.
If the Fatal method of native.Env is called with argument v, Run panics with the value v.