Documentation ¶
Index ¶
- Constants
- Variables
- type ContextHandlerFunc
- type Environment
- func (self *Environment) Commands() []string
- func (self *Environment) DisableCommand(module string, cmdname string)
- func (self *Environment) EnableCommand(module string, cmdname string)
- func (self *Environment) Evaluate(script *scripting.Friendscript, scope ...*scripting.Scope) (*scripting.Scope, error)
- func (self *Environment) EvaluateFile(path string, scope ...*scripting.Scope) (*scripting.Scope, error)
- func (self *Environment) EvaluateReader(reader io.Reader, scope ...*scripting.Scope) (*scripting.Scope, error)
- func (self *Environment) EvaluateString(data string, scope ...*scripting.Scope) (*scripting.Scope, error)
- func (self *Environment) Get(key string, fallback ...interface{}) interface{}
- func (self *Environment) GetReaderForPath(path string) (io.ReadCloser, error)
- func (self *Environment) GetWriterForPath(path string) (string, io.Writer, error)
- func (self *Environment) Module(name string) (Module, bool)
- func (self *Environment) Modules() map[string]Module
- func (self *Environment) MustModule(name string) Module
- func (self *Environment) Open(fileOrReader interface{}) (io.ReadCloser, error)
- func (self *Environment) REPL() (*scripting.Scope, error)
- func (self *Environment) RegisterCommandHandler(command string, handler InteractiveHandlerFunc) error
- func (self *Environment) RegisterContextHandler(handler ContextHandlerFunc) int
- func (self *Environment) RegisterModule(prefix string, module Module)
- func (self *Environment) RegisterPathReader(handler utils.PathReaderFunc)
- func (self *Environment) RegisterPathWriter(handler utils.PathWriterFunc)
- func (self *Environment) Run(scriptName string, options *utils.RunOptions) (interface{}, error)
- func (self *Environment) Scope() *scripting.Scope
- func (self *Environment) Set(key string, value interface{})
- func (self *Environment) SetData(data map[string]interface{})
- func (self *Environment) UnregisterContextHandler(id int)
- func (self *Environment) UnregisterModule(prefix string)
- type InteractiveContext
- type InteractiveHandlerFunc
- type Module
Constants ¶
const DefaultEnvironmentName = `friendscript`
const Version = `0.8.4`
Variables ¶
var MaxReaderWait = time.Duration(5) * time.Second
Functions ¶
This section is empty.
Types ¶
type ContextHandlerFunc ¶
type Environment ¶
type Environment struct { Name string // contains filtered or unexported fields }
func NewEnvironment ¶
func NewEnvironment(data ...map[string]interface{}) *Environment
Create a new scripting environment.
func (*Environment) Commands ¶
func (self *Environment) Commands() []string
List all commands supported by all registered modules.
func (*Environment) DisableCommand ¶
func (self *Environment) DisableCommand(module string, cmdname string)
Specify a command that should not be permitted to execute.
func (*Environment) EnableCommand ¶
func (self *Environment) EnableCommand(module string, cmdname string)
Specify a command that should be permitted to execute.
func (*Environment) Evaluate ¶
func (self *Environment) Evaluate(script *scripting.Friendscript, scope ...*scripting.Scope) (*scripting.Scope, error)
func (*Environment) EvaluateFile ¶
func (*Environment) EvaluateReader ¶
func (*Environment) EvaluateString ¶
func (*Environment) Get ¶
func (self *Environment) Get(key string, fallback ...interface{}) interface{}
func (*Environment) GetReaderForPath ¶
func (self *Environment) GetReaderForPath(path string) (io.ReadCloser, error)
Takes a path string and consults all registered PathReaderFuncs. The first one to claim it can handle the path will be responsible for returning an io.ReadCloser that represents the stream of data being sought.
func (*Environment) GetWriterForPath ¶
Takes a path string and consults all registered PathWriterFuncs. The first one to claim it can handle the path will be responsible for returning a possibly-rewritten path string and an io.Writer that will accept the data being written.
func (*Environment) Module ¶
func (self *Environment) Module(name string) (Module, bool)
Retrieve the named module.
func (*Environment) Modules ¶
func (self *Environment) Modules() map[string]Module
Retrieve a copy of the currently registered modules.
func (*Environment) MustModule ¶
func (self *Environment) MustModule(name string) Module
Retrieve the named module, or panic if it is not registered.
func (*Environment) Open ¶
func (self *Environment) Open(fileOrReader interface{}) (io.ReadCloser, error)
Open a readable destination file for reading. If fileOrReader is a string, it will be treated as a path and will be sent to GetReaderForPath(). If it is an io.Reader, it will be returned without reading from it.
func (*Environment) RegisterCommandHandler ¶
func (self *Environment) RegisterCommandHandler(command string, handler InteractiveHandlerFunc) error
Registers a function to handle a specific REPL command. If command is an empty string, the function will be called for each command entered into the REPL.
func (*Environment) RegisterContextHandler ¶
func (self *Environment) RegisterContextHandler(handler ContextHandlerFunc) int
Registers a handler that will receive updates on execution context and state as the script is running. Will return an integer that can be used to remove the handler at a later point.
func (*Environment) RegisterModule ¶
func (self *Environment) RegisterModule(prefix string, module Module)
Registers a command module to the given prefix. If a module with the same prefix already exists, it will be replaced with the given module. Prefixes will be stripped of spaces and converted to snake_case. If an empty prefix is given, the default UnqualifiedModuleName ("core") will be used.
func (*Environment) RegisterPathReader ¶
func (self *Environment) RegisterPathReader(handler utils.PathReaderFunc)
Registers a new handler function that will be used for turning paths into readable streams.
func (*Environment) RegisterPathWriter ¶
func (self *Environment) RegisterPathWriter(handler utils.PathWriterFunc)
Registers a new handler function that will be used for turning paths into writable streams.
func (*Environment) Run ¶
func (self *Environment) Run(scriptName string, options *utils.RunOptions) (interface{}, error)
func (*Environment) Scope ¶
func (self *Environment) Scope() *scripting.Scope
func (*Environment) Set ¶
func (self *Environment) Set(key string, value interface{})
func (*Environment) SetData ¶
func (self *Environment) SetData(data map[string]interface{})
func (*Environment) UnregisterContextHandler ¶
func (self *Environment) UnregisterContextHandler(id int)
Remove the context handler with the given ID.
func (*Environment) UnregisterModule ¶
func (self *Environment) UnregisterModule(prefix string)
Removes a registered module at the given prefix.
type InteractiveContext ¶
type InteractiveHandlerFunc ¶
type InteractiveHandlerFunc func(ctx *InteractiveContext, environment *Environment) ([]string, error)
Directories ¶
Path | Synopsis |
---|---|
commands
|
|
assert
Suite of testing-oriented commands that will trigger errors or failures if they aren't satistifed.
|
Suite of testing-oriented commands that will trigger errors or failures if they aren't satistifed. |
core
This package provides default implementations of commands that can be used when creating modules.
|
This package provides default implementations of commands that can be used when creating modules. |
file
Commands for reading and writing files.
|
Commands for reading and writing files. |
fmt
Suite of string formatting utilities.
|
Suite of string formatting utilities. |
http
Commands for interacting with HTTP resources
|
Commands for interacting with HTTP resources |
parse
Commands used to load and parse various formats of serialized data (JSON, YAML, etc.)
|
Commands used to load and parse various formats of serialized data (JSON, YAML, etc.) |
url
Commands for processing and working with URLs.
|
Commands for processing and working with URLs. |
utils
Contains miscellaneous utility commands.
|
Contains miscellaneous utility commands. |
vars
Commands for manipulating the current Friendscript variable scope.
|
Commands for manipulating the current Friendscript variable scope. |
examples
|
|