Documentation ¶
Overview ¶
Package wdteutil provides higher-level automatic wrappers and convenience functions for Go/WDTE interoperability.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromFunc ¶
FromFunc does the opposite of Func, returning a Go function with the signature given by expected that, when called, calls w with frame. Type conversions are handled the same as in Func, but in reverse, such that the return type stipulations in Func apply to the arguments to w, and vice versa for the return value of w. The requested function type must return exactly zero or one values.
func Func ¶
Func returns a wdte.Func that wraps the given function f. The returned function automatically translates any supported types to and from the appropriate types for both arguments and return values. The given name is used to name the frame used inside the function.
Note that currently this is limited to functions that have a single return value.
Unrecognized types are passed through with an attempted conversion, allowing a function to, for example, take a stream.Stream as an argument. Similarly, if an expected type of an argument is the exact type of the value passed, the value is passed through directly. If a return value's type implements wdte.Func, it is also passed directly. Types with special handling are as follows:
Arguments:
- Arrays and slices. Note that the passed WDTE array's length must match the expected length of the array in the Go function's arguments.
Return types:
- Arrays and slices.
- Pointers.
- Functions that are supported by this function. The functions will use a frame with the name "<auto>".
Example ¶
package main import ( "fmt" "strings" "github.com/DeedleFake/wdte" "github.com/DeedleFake/wdte/wdteutil" ) func main() { c, err := wdte.Parse(strings.NewReader(`add 3 2;`), nil, nil) if err != nil { panic(err) } scope := wdte.S().Add("add", wdteutil.Func("add", func(n1, n2 int) int { return n1 + n2 }), ) fmt.Println(c.Call(wdte.F().WithScope(scope))) }
Output: 5
Types ¶
This section is empty.