wdte: github.com/DeedleFake/wdte/auto Index | Examples | Files

package auto

import "github.com/DeedleFake/wdte/auto"

Package auto provides higher-level automatic wrappers and convenience for Go/WDTE interoperability.



Package Files

auto.go doc.go func.go save.go

func FromFunc Uses

func FromFunc(frame wdte.Frame, w wdte.Func, expected reflect.Type) reflect.Value

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 Uses

func Func(name string, f interface{}) wdte.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:


* 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>".


c, err := wdte.Parse(strings.NewReader(`add 3 2;`), nil, nil)
if err != nil {

scope := wdte.S().Add("add",
    auto.Func("add", func(n1, n2 int) int {
        return n1 + n2




func SaveArgs Uses

func SaveArgs(f wdte.Func, args ...wdte.Func) wdte.Func

SaveArgs returns a function which, when called, prepends args to its argument list.

func SaveArgsReverse Uses

func SaveArgsReverse(f wdte.Func, args ...wdte.Func) wdte.Func

SaveArgsReverse returns a function which, when called, appends args to its argument list.

Package auto imports 4 packages (graph) and is imported by 5 packages. Updated 2019-02-13. Refresh now. Tools for package owners.