convert

package
v0.0.0-...-2eca010 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2017 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromDict

func FromDict(m *skylark.Dict) (map[interface{}]interface{}, error)

FromDict converts a skylark.Dict to a map[interface{}]interface{}

func FromList

func FromList(l *skylark.List) ([]interface{}, error)

FromList creates a go slice from the given skylark list.

func FromSet

func FromSet(s *skylark.Set) (map[interface{}]bool, error)

FromSet converts a skylark.Set to a map[interface{}]bool

func FromStringDict

func FromStringDict(m skylark.StringDict) map[string]interface{}

FromStringDict makes a map[string]interface{} from the given arg. Any unconvertible values are ignored.

func FromTuple

func FromTuple(v skylark.Tuple) ([]interface{}, error)

FromTuple converts a skylark.Tuple into a []interface{}.

func FromValue

func FromValue(v skylark.Value) (interface{}, error)

FromValue converts a skylark value to a go value.

func MakeDict

func MakeDict(d map[interface{}]interface{}) (*skylark.Dict, error)

MakeDict makes a Dict from the given map. The acceptable keys and values are the same as ToValue.

func MakeList

func MakeList(v []interface{}) (*skylark.List, error)

MakeList makes a list from the given values. The acceptable values are the same as ToValue.

func MakeSet

func MakeSet(s map[interface{}]bool) (*skylark.Set, error)

MakeSet makes a Set from the given map. The acceptable keys the same as ToValue.

func MakeSkyFn

func MakeSkyFn(name string, gofn interface{}) *skylark.Builtin

MakeSkyFn creates a wrapper around the given function that can be called from a skylark script. Argument support is the same as ToValue. If the last value the function returns is an error, it will cause an error to be returned from the skylark function. If there are no other errors, the function will return None. If there's exactly one other value, the function will return the skylark equivalent of that value. If there is more than one return value, they'll be returned as a tuple. MakeSkyFn will panic if you pass it something other than a function.

func MakeStringDict

func MakeStringDict(m map[string]interface{}) (skylark.StringDict, error)

MakeStringDict makes a StringDict from the given arg. The types supported are the same as ToValue.

func MakeTuple

func MakeTuple(v []interface{}) (skylark.Tuple, error)

MakeTuple makes a tuple from the given values. The acceptable values are the same as ToValue.

func ToValue

func ToValue(v interface{}) (skylark.Value, error)

ToValue attempts to convert the given value to a skylark.Value. It supports all int, uint, and float numeric types, strings, and bools. Any skylark.Value is passed through as-is. A []interface{} is converted with MakeList, map[interface{}]interface{} is converted with MakeDict, and map[interface{}]bool is converted with MakeSet.

Types

type Kwarg

type Kwarg struct {
	Name  string
	Value interface{}
}

Kwarg is a single instance of a python foo=bar style named argument.

func FromKwargs

func FromKwargs(kwargs []skylark.Tuple) ([]Kwarg, error)

FromKwargs converts a python style name=val, name2=val2 list of tuples into a []Kwarg. It is an error if any tuple is not exactly 2 values, or if the first one is not a string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL