Version: v0.12.0 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2020 License: MIT Imports: 4 Imported by: 0



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




This section is empty.


This section is empty.


func FromFunc

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

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>".
package main

import (


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

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




func SaveArgs

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

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

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


This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to