Documentation
¶
Index ¶
- Variables
- func ExplainError(es []*Error, i int) (string, error)
- func GetTraceReport(e *err.Error) string
- func ToGo[T any](sv *Service, pfValue Value) (T, error)
- type Error
- type InHandler
- type List
- type LiteralOutHandler
- type Map
- type OutHandler
- type Service
- func (sv *Service) Api(title string, fonts values.Map, width int) string
- func (s *Service) CallMain() (Value, error)
- func (sv *Service) Do(line string) (Value, error)
- func (sv *Service) DumpCode(functionName string, showMemory bool) string
- func (sv *Service) ErrorsExist() (bool, error)
- func (sv *Service) GetErrorReport() (string, error)
- func (sv *Service) GetErrors() []*Error
- func (sv *Service) GetFilepath() (string, error)
- func (sv *Service) GetMarkdowner(leftMargin string, rightMargin int, fonts values.Map) func(string) string
- func (sv *Service) GetSources() (map[string][]string, error)
- func (sv *Service) GetTrackingReport() (string, error)
- func (sv *Service) GetVariable(vname string) (values.Value, error)
- func (sv *Service) Highlight(code []rune, fonts Map) string
- func (sv *Service) InitializeFromCode(code string) error
- func (sv *Service) InitializeFromCodeWithStore(code string, store Map) error
- func (sv *Service) InitializeFromFilepath(scriptFilepath string) error
- func (sv *Service) InitializeFromFilepathWithStore(scriptFilepath string, store Map) error
- func (sv *Service) IsBroken() bool
- func (sv *Service) IsClone(v Value) bool
- func (sv *Service) IsEnum(v Value) bool
- func (sv *Service) IsInitialized() bool
- func (sv *Service) IsStruct(v Value) bool
- func (sv *Service) MakeLiteralOutHandler(out io.Writer) *LiteralOutHandler
- func (sv *Service) MakeTerminalOutHandler() *SimpleOutHandler
- func (sv *Service) MakeWritingOutHandler(out io.Writer) *SimpleOutHandler
- func (sv *Service) NeedsUpdate() (bool, error)
- func (sv *Service) Output(v Value)
- func (sv *Service) PostHappened() bool
- func (sv *Service) SerializeApi() string
- func (sv *Service) SetEnv(env values.Map) error
- func (sv *Service) SetInHandler(in InHandler) error
- func (sv *Service) SetLocalExternalServices(svs map[string]*Service)
- func (sv *Service) SetOutHandler(out vm.OutHandler) error
- func (sv *Service) SetPostHappened()
- func (sv *Service) SetVariable(vname string, ty values.ValueType, v any) error
- func (sv *Service) ToGoWithType(pfValue Value, goType reflect.Type) (any, error)
- func (sv *Service) ToLiteral(v Value) string
- func (sv *Service) ToString(v Value) string
- func (sv *Service) TypeNameToType(s string) (Type, error)
- func (sv *Service) TypeToTypeName(t Type) (string, error)
- func (sv *Service) UnderlyingType(v Value) Type
- func (sv *Service) WriteSecret(store values.Map, password string) string
- type Set
- type SimpleInHandler
- type SimpleOutHandler
- type TerminalInHandler
- type Type
- type Value
Constants ¶
This section is empty.
Variables ¶
var DEFAULT_TYPE_FOR = map[Type]reflect.Type{ INT: reflect.TypeFor[int](), BOOL: reflect.TypeFor[bool](), STRING: reflect.TypeFor[string](), FLOAT: reflect.TypeFor[float64](), LIST: reflect.TypeFor[[]any](), PAIR: reflect.TypeFor[[2]any](), MAP: reflect.TypeFor[map[any]any](), SET: reflect.TypeFor[map[any]struct{}](), TUPLE: reflect.TypeFor[[]any](), }
What we convert to when we convert to `any`.
Functions ¶
func ExplainError ¶
Provides the answer to `hub why <n>`.
func GetTraceReport ¶
Gets the trace report of a runtime error, in the form of a string that can be passed to the `PrettyString` function for highlighting.
Types ¶
type InHandler ¶
An interface with one method, `Get()`, which supplies a string when the Pipefish code does `get x from Input()`.
type LiteralOutHandler ¶
type LiteralOutHandler = vm.LiteralOutHandler
An OutHandler which serializes the given value and writes it to an io.Writer supplied at its construction.
type OutHandler ¶
type OutHandler = vm.OutHandler
An interface with two methods (1) `Out(v Value)` which takes the value supplied when the Pipefish code says `post x to Output()` and does something with it, presumably serializing it in some way and writing it somewhere; (2) a method `Write(s string)` which if necessary allows the user to write a string to the same place.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) Api ¶
Returns a description of the API in rendered markdown. The `fonts` field is only used for rendering Pipefish code in code blocks, and so may be omitted if you don't want to do that.
func (*Service) Do ¶
Once the service is initialized, will interpret the string supplied as though it had been entered into the REPL of the service. The error field will be non-nil in the case of a compile-time error. In the case of a runtime error, it will be nil, and the error will be returned as the `Value`.
func (*Service) ErrorsExist ¶
Returns `true` if the last thing the service did produced errors, whether runtime or compile time.
func (*Service) GetErrorReport ¶
Gets a summary of the errors produced by the last thing the service did, in the form of a string that can be passed to the `PrettyString` function for highlighting.
func (*Service) GetErrors ¶
Returns the errors produced by the last thing the service did, as a list of things of type `*Error`.
func (*Service) GetFilepath ¶
GetFilepath to the root file of the service.
func (*Service) GetMarkdowner ¶
func (sv *Service) GetMarkdowner(leftMargin string, rightMargin int, fonts values.Map) func(string) string
Gets markdown with appropriate highlighting.
func (*Service) GetSources ¶
Gets the source code of the service as a map from filenames to lists of strings (i.e. lines of source code).
func (*Service) GetTrackingReport ¶
Gets a report of the tracking if any, in the form of a string which can be passed to `PrettyString` for highlighting.
func (*Service) GetVariable ¶
Gets the value of a global variable given its name. Unlike using `Do` for the same purpose, this can get the value of private variables.
func (*Service) Highlight ¶
This highlights the given string on the assumption that it's Pipefish code, and that the `fonts` map is a theme like in `user/themes.pf“.
func (*Service) InitializeFromCode ¶
Initializes the service with the source code supplied in the string.
func (*Service) InitializeFromCodeWithStore ¶
The same as the previous two functions, except that we pass in a map of values to initialize $store. Initializes the service with the source code supplied in the string.
func (*Service) InitializeFromFilepath ¶
Initializes the service with the source code supplied in the file indicated by the filepath.
func (*Service) InitializeFromFilepathWithStore ¶
Initializes the service with the source code supplied in the file indicated by the filepath.
func (*Service) IsInitialized ¶
Returns `true` if the service is initialized.
func (*Service) MakeLiteralOutHandler ¶
func (sv *Service) MakeLiteralOutHandler(out io.Writer) *LiteralOutHandler
An outhandler which always serializes the value, for use by external services.
func (*Service) MakeTerminalOutHandler ¶
func (sv *Service) MakeTerminalOutHandler() *SimpleOutHandler
Method makes an `OutHandler` which applies Pipefish's `literal` or `string` function to the value and then writes the result to Stdout.
func (*Service) MakeWritingOutHandler ¶
func (sv *Service) MakeWritingOutHandler(out io.Writer) *SimpleOutHandler
Method makes an `OutHandler` which applies Pipefish's `literal` or `string` function to the value and then writes the result to the supplied `io.Writer`.
func (*Service) NeedsUpdate ¶
Checks whether the source code for a service has been changed since it was initialized.
func (*Service) PostHappened ¶
Says whether post happened when we called Do.
func (*Service) SerializeApi ¶
Describes the API of a service in a custom reverse polish notation format.
TODO, WARNING! This is extremely unstable, it contains things it doesn't need to contain and omits things it should contain.
func (*Service) SetInHandler ¶
Sets an InHandler, i.e. the thing that decides what happens when you do `get x from Input()`.
func (*Service) SetLocalExternalServices ¶
Makes other services visible to the service, as though they were running on the same hub: their `external` declarations can then allow them to use one another as external services.
func (*Service) SetOutHandler ¶
func (sv *Service) SetOutHandler(out vm.OutHandler) error
Sets an OutHandler, i.e. the thing that decides what happens when you do `post x to Output()`.
func (*Service) SetPostHappened ¶
func (sv *Service) SetPostHappened()
func (*Service) SetVariable ¶
Sets the value of a global variable given its name. Unlike using `Do` for the same purpose, this can set the value of private variables.
func (*Service) ToGoWithType ¶
Tries to turn a given Pipefish value into a given Go type. As it necessarily has return type `any` (plus an error if the coercion is impossible) the value returned will then still need downcasting to the type it was coerced to.
E.g:
func TwoPlusTwo() int {
v, _ := fooService.Do(`2 + 2`) // `v` has type `Value`.
i := fooService.ToGoWithType(v, reflect.TypeFor[int]()) // `i` has type `any`.
return i.(int) // We return an integer as required.
}
The error will be non-nil if the coercion is impossible.
func (*Service) TypeNameToType ¶
Returns the `Type` associated with a given type name.
func (*Service) TypeToTypeName ¶
Returns the type name associated with a given `Type`.
func (*Service) UnderlyingType ¶
Returns the underlying `Type` of a `Value`, i.e. its parent type if it's a clone, otherwise its own type.
type SimpleInHandler ¶
type SimpleInHandler = vm.SimpleInHandler
An InHandler which just gets an input from an io.Reader supplied at its construction.
func MakeSimpleInHandler ¶
func MakeSimpleInHandler(in io.Reader) *SimpleInHandler
Makes an InHandler which does nothing but get a string from terminal input and return it.
type SimpleOutHandler ¶
type SimpleOutHandler = vm.SimpleOutHandler
An OutHandler which stringifies/serializes the given value and writes it to an io.Writer supplied at its construction.
type TerminalInHandler ¶
type TerminalInHandler = vm.StandardInHandler
An InHandler which supplies a prompt and then gets its input from the terminal.
func MakeTerminalInHandler ¶
func MakeTerminalInHandler(prompt string) *TerminalInHandler
Makes an `InHandler` which will get input from the terminal using the string supplied to prompt the end user.
type Type ¶
const ( UNDEFINED_TYPE Type = values.UNDEFINED_TYPE BLING Type = values.BLING UNSATISFIED_CONDITIONAL Type = values.UNSATISFIED_CONDITIONAL OK Type = values.SUCCESSFUL_VALUE TUPLE Type = values.TUPLE ERROR Type = values.ERROR NULL Type = values.NULL INT Type = values.INT BOOL Type = values.BOOL STRING Type = values.STRING RUNE Type = values.RUNE FLOAT Type = values.FLOAT TYPE Type = values.TYPE FUNC Type = values.FUNC PAIR Type = values.PAIR LIST Type = values.LIST MAP Type = values.MAP SET Type = values.SET LABEL Type = values.LABEL SNIPPET Type = values.SNIPPET )
Constants representing Pipefish types.