Documentation ¶
Overview ¶
Package convert provides functions for converting data and functions between Go and Starlark.
Index ¶
- Variables
- func FromDict(m *starlark.Dict) map[interface{}]interface{}
- func FromList(l *starlark.List) []interface{}
- func FromSet(s *starlark.Set) map[interface{}]bool
- func FromStringDict(m starlark.StringDict) map[string]interface{}
- func FromTuple(v starlark.Tuple) []interface{}
- func FromValue(v starlark.Value) interface{}
- func MakeDict(v interface{}) (starlark.Value, error)
- func MakeDictWithTag(v interface{}, tagName string) (starlark.Value, error)
- func MakeList(v []interface{}) (*starlark.List, error)
- func MakeSet(s map[interface{}]bool) (*starlark.Set, error)
- func MakeSetFromSlice(s []interface{}) (*starlark.Set, error)
- func MakeStarFn(name string, gofn interface{}) *starlark.Builtin
- func MakeStringDict(m map[string]interface{}) (starlark.StringDict, error)
- func MakeStringDictWithTag(m map[string]interface{}, tagName string) (starlark.StringDict, error)
- func MakeTuple(v []interface{}) (starlark.Tuple, error)
- func ToValue(v interface{}) (starlark.Value, error)
- func ToValueWithTag(v interface{}, tagName string) (starlark.Value, error)
- type GoInterface
- func (g *GoInterface) Attr(name string) (starlark.Value, error)
- func (g *GoInterface) AttrNames() []string
- func (g *GoInterface) Freeze()
- func (g *GoInterface) Hash() (uint32, error)
- func (g *GoInterface) String() string
- func (g *GoInterface) ToBool() (bool, error)
- func (g *GoInterface) ToFloat() (float64, error)
- func (g *GoInterface) ToInt() (int64, error)
- func (g *GoInterface) ToString() (string, error)
- func (g *GoInterface) ToUint() (uint64, error)
- func (g *GoInterface) Truth() starlark.Bool
- func (g *GoInterface) Type() string
- func (g *GoInterface) Value() reflect.Value
- type GoMap
- func (g *GoMap) Attr(name string) (starlark.Value, error)
- func (g *GoMap) AttrNames() []string
- func (g *GoMap) Clear() error
- func (g *GoMap) Delete(k starlark.Value) (v starlark.Value, found bool, err error)
- func (g *GoMap) Freeze()
- func (g *GoMap) Get(in starlark.Value) (out starlark.Value, found bool, err error)
- func (g *GoMap) Hash() (uint32, error)
- func (g *GoMap) Items() []starlark.Tuple
- func (g *GoMap) Iterate() starlark.Iterator
- func (g *GoMap) Keys() []starlark.Value
- func (g *GoMap) Len() int
- func (g *GoMap) SetKey(k, v starlark.Value) (err error)
- func (g *GoMap) String() string
- func (g *GoMap) Truth() starlark.Bool
- func (g *GoMap) Type() string
- func (g *GoMap) Value() reflect.Value
- type GoSlice
- func (g *GoSlice) Attr(name string) (starlark.Value, error)
- func (g *GoSlice) AttrNames() []string
- func (g *GoSlice) Clear() error
- func (g *GoSlice) Freeze()
- func (g *GoSlice) Hash() (uint32, error)
- func (g *GoSlice) Index(i int) starlark.Value
- func (g *GoSlice) Iterate() starlark.Iterator
- func (g *GoSlice) Len() int
- func (g *GoSlice) SetIndex(index int, v starlark.Value) error
- func (g *GoSlice) Slice(start, end, step int) starlark.Value
- func (g *GoSlice) String() string
- func (g *GoSlice) Truth() starlark.Bool
- func (g *GoSlice) Type() string
- func (g *GoSlice) Value() reflect.Value
- type GoStruct
- func (g *GoStruct) Attr(name string) (starlark.Value, error)
- func (g *GoStruct) AttrNames() []string
- func (g *GoStruct) Freeze()
- func (g *GoStruct) Hash() (uint32, error)
- func (g *GoStruct) SetField(name string, val starlark.Value) error
- func (g *GoStruct) String() string
- func (g *GoStruct) Truth() starlark.Bool
- func (g *GoStruct) Type() string
- func (g *GoStruct) Value() reflect.Value
- type Kwarg
Constants ¶
This section is empty.
Variables ¶
var (
// DefaultPropertyTag is the default struct tag to use when converting
DefaultPropertyTag = "starlark"
)
Functions ¶
func FromStringDict ¶
func FromStringDict(m starlark.StringDict) map[string]interface{}
FromStringDict makes a map[string]interface{} from the given arg. Any inconvertible values are ignored.
func MakeDict ¶
MakeDict makes a Dict from the given map. The acceptable keys and values are the same as ToValue.
func MakeDictWithTag ¶ added in v0.0.8
MakeDictWithTag makes a Dict from the given map with custom tag. The acceptable keys and values are the same as ToValueWithTag.
func MakeList ¶ added in v0.0.5
MakeList makes a Starlark List from the given Go slice. The types supported are the same as ToValue.
func MakeSetFromSlice ¶ added in v0.0.5
MakeSetFromSlice makes a Set from the given slice. The acceptable keys the same as ToValue.
func MakeStarFn ¶
MakeStarFn creates a wrapper around the given function that can be called from a starlark 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 starlark function. If there are no other errors, the function will return None. If there's exactly one other value, the function will return the starlark equivalent of that value. If there is more than one return value, they'll be returned as a tuple. MakeStarFn will panic if you pass it something other than a function.
func MakeStringDict ¶
func MakeStringDict(m map[string]interface{}) (starlark.StringDict, error)
MakeStringDict makes a StringDict from the given arg. The types supported are the same as ToValue.
func MakeStringDictWithTag ¶ added in v0.0.8
func MakeStringDictWithTag(m map[string]interface{}, tagName string) (starlark.StringDict, error)
MakeStringDictWithTag makes a StringDict from the given arg with custom tag. The types supported are the same as ToValueWithTag.
func MakeTuple ¶ added in v0.0.5
MakeTuple makes a Starlark Tuple from the given Go slice. The types supported are the same as ToValue.
Types ¶
type GoInterface ¶
type GoInterface struct {
// contains filtered or unexported fields
}
GoInterface wraps a go value to expose its methods to starlark scripts. Basic types will not behave as their base type (you can't add 2 to an ID, even if it is an int underneath).
func MakeGoInterface ¶
func MakeGoInterface(v interface{}) *GoInterface
MakeGoInterface converts the given value into a GoInterface. This will panic if the value is nil or the type is not a bool, string, float kind, int kind, or uint kind.
func (*GoInterface) Attr ¶
func (g *GoInterface) Attr(name string) (starlark.Value, error)
Attr returns a starlark value that wraps the method or field with the given name.
func (*GoInterface) AttrNames ¶
func (g *GoInterface) AttrNames() []string
AttrNames returns the list of all fields and methods on this struct.
func (*GoInterface) Freeze ¶
func (g *GoInterface) Freeze()
Freeze causes the value, and all values transitively reachable from it through collections and closures, to be marked as frozen. All subsequent mutations to the data structure through this API will fail dynamically, making the data structure immutable and safe for publishing to other Starlark interpreters running concurrently.
func (*GoInterface) Hash ¶
func (g *GoInterface) Hash() (uint32, error)
Hash returns a function of x such that Equals(x, y) => Hash(x) == Hash(y). Hash may fail if the value's type is not hashable, or if the value contains a non-hashable value.
func (*GoInterface) String ¶
func (g *GoInterface) String() string
String returns the string representation of the value. Starlark string values are quoted as if by Python's repr.
func (*GoInterface) ToBool ¶
func (g *GoInterface) ToBool() (bool, error)
ToBool converts the interface value into a starlark bool. This will fail if the underlying type is not a bool type or pointer to a bool type.
func (*GoInterface) ToFloat ¶
func (g *GoInterface) ToFloat() (float64, error)
ToFloat converts the interface value into a starlark float. This will fail if the underlying type is not a float type (including if the underlying type is a pointer to a float).
func (*GoInterface) ToInt ¶
func (g *GoInterface) ToInt() (int64, error)
ToInt converts the interface value into a starlark int. This will fail if the underlying type is not an int type or pointer to an int type.
func (*GoInterface) ToString ¶
func (g *GoInterface) ToString() (string, error)
ToString converts the interface value into a starlark string. This will fail if the underlying type is not a string (including if the underlying type is a pointer to a string).
func (*GoInterface) ToUint ¶
func (g *GoInterface) ToUint() (uint64, error)
ToUint converts the interface value into a starlark int. This will fail if the underlying type is not an uint type or pointer to an uint type.
func (*GoInterface) Truth ¶
func (g *GoInterface) Truth() starlark.Bool
Truth returns the truth value of an object.
func (*GoInterface) Type ¶
func (g *GoInterface) Type() string
Type returns a short string describing the value's type.
func (*GoInterface) Value ¶ added in v0.0.3
func (g *GoInterface) Value() reflect.Value
Value returns reflect.Value of the underlying value.
type GoMap ¶
type GoMap struct {
// contains filtered or unexported fields
}
GoMap is a wrapper around a Go map that makes it satisfy starlark's expectations of a starlark dict.
func NewGoMap ¶
func NewGoMap(m interface{}) *GoMap
NewGoMap wraps the given map m in a new GoMap. This function will panic if m is nil or not a map.
func (*GoMap) Freeze ¶
func (g *GoMap) Freeze()
Freeze causes the value, and all values transitively reachable from it through collections and closures, to be marked as frozen. All subsequent mutations to the data structure through this API will fail dynamically, making the data structure immutable and safe for publishing to other Starlark interpreters running concurrently.
func (*GoMap) Hash ¶
Hash returns a function of x such that Equals(x, y) => Hash(x) == Hash(y). Hash may fail if the value's type is not hashable, or if the value contains a non-hashable value.
func (*GoMap) String ¶
String returns the string representation of the value. Starlark string values are quoted as if by Python's repr.
type GoSlice ¶
type GoSlice struct {
// contains filtered or unexported fields
}
GoSlice is a wrapper around a Go slice to adapt it for use with starlark.
func NewGoSlice ¶
func NewGoSlice(slice interface{}) *GoSlice
NewGoSlice wraps the given slice in a new GoSlice. This function will panic if m is nil or not a slice nor array.
func (*GoSlice) Freeze ¶
func (g *GoSlice) Freeze()
Freeze causes the value, and all values transitively reachable from it through collections and closures, to be marked as frozen. All subsequent mutations to the data structure through this API will fail dynamically, making the data structure immutable and safe for publishing to other Starlark interpreters running concurrently.
func (*GoSlice) Hash ¶
Hash returns a function of x such that Equals(x, y) => Hash(x) == Hash(y). Hash may fail if the value's type is not hashable, or if the value contains a non-hashable value.
func (*GoSlice) String ¶
String returns the string representation of the value. Starlark string values are quoted as if by Python's repr.
type GoStruct ¶
type GoStruct struct {
// contains filtered or unexported fields
}
GoStruct is a wrapper around a Go struct to let it be manipulated by Starlark scripts.
func NewStruct ¶
func NewStruct(strct interface{}) *GoStruct
NewStruct makes a new Starlark-compatible Struct from the given struct or pointer to struct. This will panic if you pass it nil or anything else.
func NewStructWithTag ¶
NewStructWithTag makes a new Starlark-compatible Struct from the given struct or pointer to struct, using the given struct tag to determine which fields to expose. This will panic if you pass it anything else.
func (*GoStruct) Attr ¶
Attr returns a Starlark value that wraps the method or field with the given name.
func (*GoStruct) Freeze ¶
func (g *GoStruct) Freeze()
Freeze causes the value, and all values transitively reachable from it through collections and closures, to be marked as frozen. All subsequent mutations to the data structure through this API will fail dynamically, making the data structure immutable and safe for publishing to other Starlark interpreters running concurrently.
func (*GoStruct) Hash ¶
Hash returns a function of x such that Equals(x, y) => Hash(x) == Hash(y). Hash may fail if the value's type is not hashable, or if the value contains a non-hashable value.
func (*GoStruct) SetField ¶
SetField sets the struct field with the given name with the given value.
func (*GoStruct) String ¶
String returns the string representation of the value. Starlark string values are quoted as if by Python's repr.