Documentation
¶
Overview ¶
Package lib Package starlarkstruct defines the Starlark types 'struct' and 'module', both optional language extensions.
Index ¶
- Constants
- Variables
- func AddSelfParamBuiltin(role *Role, val *starlark.Function) ...
- func BuiltinAttr(recv starlark.Value, name string, methods map[string]*starlark.Builtin) (starlark.Value, error)
- func BuiltinAttrNames(methods map[string]*starlark.Builtin) []string
- func ClearChannelRefs()
- func ClearRoleRefs()
- func CompareStringer[E fmt.Stringer](a, b E) int
- func CreateChannelBuiltin(channels map[int]*Channel) *starlark.Builtin
- func CreateResolveRoleBuiltIn(roles *[]*Role) *starlark.Builtin
- func CreateRoleBuiltin(astRole *ast.Role, symmetric bool, roles *[]*Role) *starlark.Builtin
- func GenerateAllPermutations[T any](arr [][]T) [][][]T
- func GeneratePermutations[T any](arr []T) [][]T
- func GenerateRefString(name string, ref int) string
- func JsonToYaml(jsonData []byte) ([]byte, error)
- func Make(_ *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, ...) (starlark.Value, error)
- func MakeBag(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, ...) (starlark.Value, error)
- func MakeEnum(_ *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, ...) (starlark.Value, error)
- func MakeGenericMap(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, ...) (starlark.Value, error)
- func MakeGenericSet(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, ...) (starlark.Value, error)
- func MakeSymmetricValues(thread *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, ...) (starlark.Value, error)
- func MarshalJSON(obj interface{}) ([]byte, error)
- func MarshalJSONStarlarkValue(m starlark.Value, depth int) ([]byte, error)
- func RandString(n int) string
- func ReadProtoFromBytes(yamlBytes []byte, protomsg proto.Message) error
- func ReadProtoFromFile(filename string, protomsg proto.Message) error
- func YamlToJson(yamlData []byte) ([]byte, error)
- type Bag
- func (b *Bag) Attr(name string) (starlark.Value, error)
- func (b *Bag) AttrNames() []string
- func (b *Bag) Clear() error
- func (b *Bag) CompareSameType(op syntax.Token, y_ starlark.Value, depth int) (bool, error)
- func (b *Bag) Delete(k starlark.Value) (bool, error)
- func (b *Bag) Find(k starlark.Value) (int, error)
- func (b *Bag) Freeze()
- func (b *Bag) Get(value starlark.Value) (v starlark.Value, found bool, err error)
- func (b *Bag) Has(x starlark.Value) (found bool, err error)
- func (b *Bag) Hash() (uint32, error)
- func (b *Bag) Insert(val starlark.Value) error
- func (b *Bag) InsertAll(v starlark.Iterable) error
- func (b *Bag) Iterate() starlark.Iterator
- func (b *Bag) Len() int
- func (b *Bag) String() string
- func (b *Bag) Truth() starlark.Bool
- func (b *Bag) Type() string
- type Channel
- func (c *Channel) Attr(name string) (starlark.Value, error)
- func (c *Channel) AttrNames() []string
- func (c *Channel) Freeze()
- func (c *Channel) Hash() (uint32, error)
- func (c *Channel) MayDropMessages() bool
- func (c *Channel) RefStringShort() string
- func (c *Channel) String() string
- func (c *Channel) Truth() starlark.Bool
- func (c *Channel) Type() string
- type Counter
- type GenericMap
- func (g *GenericMap) Attr(name string) (starlark.Value, error)
- func (g *GenericMap) AttrNames() []string
- func (g *GenericMap) Clear() error
- func (g *GenericMap) CompareSameType(op syntax.Token, y_ starlark.Value, depth int) (bool, error)
- func (g *GenericMap) Delete(k starlark.Value) (v starlark.Value, found bool, err error)
- func (g *GenericMap) Freeze()
- func (g *GenericMap) Get(key starlark.Value) (v starlark.Value, found bool, err error)
- func (g *GenericMap) Hash() (uint32, error)
- func (g *GenericMap) Items() []starlark.Tuple
- func (g *GenericMap) Iterate() starlark.Iterator
- func (g *GenericMap) Keys() []starlark.Value
- func (g *GenericMap) Len() int
- func (g *GenericMap) SetKey(key, value starlark.Value) error
- func (g *GenericMap) String() string
- func (g *GenericMap) Truth() starlark.Bool
- func (g *GenericMap) Type() string
- type GenericSet
- func (g *GenericSet) Attr(name string) (starlark.Value, error)
- func (g *GenericSet) AttrNames() []string
- func (g *GenericSet) Clear() error
- func (g *GenericSet) CompareSameType(op syntax.Token, y_ starlark.Value, depth int) (bool, error)
- func (g *GenericSet) Delete(k starlark.Value) (found bool, err error)
- func (g *GenericSet) Difference(other starlark.Iterator) (starlark.Value, error)
- func (g *GenericSet) Freeze()
- func (g *GenericSet) Get(value starlark.Value) (v starlark.Value, found bool, err error)
- func (g *GenericSet) Has(k starlark.Value) (found bool, err error)
- func (g *GenericSet) Hash() (uint32, error)
- func (g *GenericSet) Insert(k starlark.Value) error
- func (s *GenericSet) Intersection(other starlark.Iterator) (starlark.Value, error)
- func (g *GenericSet) IsSubset(other *GenericSet) (bool, error)
- func (s *GenericSet) IsSuperset(other starlark.Iterator) (bool, error)
- func (g *GenericSet) Iterate() starlark.Iterator
- func (g *GenericSet) Len() int
- func (g *GenericSet) String() string
- func (s *GenericSet) SymmetricDifference(other starlark.Iterator) (starlark.Value, error)
- func (g *GenericSet) Truth() starlark.Bool
- func (g *GenericSet) Type() string
- func (g *GenericSet) Union(iter starlark.Iterator) (starlark.Value, error)
- type LinearCollection
- type ModelValue
- func (m ModelValue) CompareSameType(op syntax.Token, y_ starlark.Value, depth int) (bool, error)
- func (m ModelValue) Freeze()
- func (m ModelValue) FullString() string
- func (m ModelValue) GetId() int
- func (m ModelValue) GetPrefix() string
- func (m ModelValue) Hash() (uint32, error)
- func (m ModelValue) MarshalJSON() ([]byte, error)
- func (m ModelValue) ShortString() string
- func (m ModelValue) String() string
- func (m ModelValue) Truth() starlark.Bool
- func (m ModelValue) Type() string
- type Pair
- type Queue
- func (q *Queue[T]) Add(t T)
- func (q *Queue[T]) Clear(int)
- func (q *Queue[T]) ClearAll()
- func (q *Queue[T]) Count() int
- func (q *Queue[T]) Dequeue() (T, bool)
- func (q *Queue[T]) Empty() bool
- func (q *Queue[T]) Enqueue(v T) *Queue[T]
- func (q *Queue[T]) Len() int
- func (q *Queue[T]) Remove() (T, bool)
- func (q *Queue[T]) Retain(n int)
- type RandomQueue
- type Role
- func (r *Role) AddMethod(name string, val starlark.Value) error
- func (r *Role) Attr(name string) (starlark.Value, error)
- func (r *Role) AttrNames() []string
- func (r *Role) Freeze()
- func (r *Role) GetId() starlark.Value
- func (r *Role) Hash() (uint32, error)
- func (r *Role) IsSymmetric() bool
- func (r *Role) MarshalJSON() ([]byte, error)
- func (r *Role) RefString() string
- func (r *Role) RefStringShort() string
- func (r *Role) SetField(name string, val starlark.Value) error
- func (r *Role) String() string
- func (r *Role) Truth() starlark.Bool
- func (r *Role) Type() string
- type RoleStub
- type Stack
- func (s *Stack[T]) Add(t T)
- func (s *Stack[T]) Clear(n int)
- func (s *Stack[T]) ClearAll()
- func (s *Stack[T]) Clone() *Stack[T]
- func (s *Stack[T]) Empty() bool
- func (s *Stack[T]) Head() (T, bool)
- func (s *Stack[T]) Len() int
- func (s *Stack[T]) MarshalJSON() ([]byte, error)
- func (s *Stack[T]) Peek() (T, bool)
- func (s *Stack[T]) Pop() (T, bool)
- func (s *Stack[T]) Push(v T) *Stack[T]
- func (s *Stack[T]) RawArray() []T
- func (s *Stack[T]) RawArrayCopy() []T
- func (s *Stack[T]) Remove() (T, bool)
- func (s *Stack[T]) Retain(n int)
- type Struct
- func (s *Struct) Attr(name string) (starlark.Value, error)
- func (s *Struct) AttrNames() []string
- func (x *Struct) Binary(op syntax.Token, y starlark.Value, side starlark.Side) (starlark.Value, error)
- func (x *Struct) CompareSameType(op syntax.Token, y_ starlark.Value, depth int) (bool, error)
- func (s *Struct) Constructor() starlark.Value
- func (s *Struct) Freeze()
- func (s *Struct) Hash() (uint32, error)
- func (s *Struct) MarshalJSON() ([]byte, error)
- func (s *Struct) ReplaceEntriesFromStringDict(d starlark.StringDict)
- func (s *Struct) SetField(name string, val starlark.Value) error
- func (s *Struct) String() string
- func (s *Struct) ToStringDict(d starlark.StringDict)
- func (s *Struct) Truth() starlark.Bool
- func (s *Struct) Type() string
- type SymmetricValue
- type SymmetricValues
- type TriState
Constants ¶
const CacheLineSize = int(unsafe.Sizeof(cpu.CacheLinePad{}))
const Default = starlark.String("record")
Default is the default constructor for structs. It is merely the string "record".
const ModelValueType = "model_value"
const SymmetricValueType = "symmetric_value"
Variables ¶
var ( SymmetryPrefix = RandString(9) + "-" // Replace this with a UUID Builtins = starlark.StringDict{ "struct": starlark.NewBuiltin("struct", starlarkstruct.Make), "record": starlark.NewBuiltin("record", Make), "enum": starlark.NewBuiltin("enum", MakeEnum), "genericmap": starlark.NewBuiltin("genericmap", MakeGenericMap), "genericset": starlark.NewBuiltin("genericset", MakeGenericSet), "symmetric_values": starlark.NewBuiltin("symmetric_values", MakeSymmetricValues), "bag": starlark.NewBuiltin("bag", MakeBag), "math": math.Module, "itertools": ItertoolsModule, } StarlarkPtrTypes = []starlark.Value{ &starlark.Set{}, &starlark.List{}, &starlark.Dict{}, &starlarkstruct.Struct{}, &starlark.Tuple{}, &Struct{}, &Bag{}, &GenericSet{}, &GenericMap{}, &Role{}, } )
var ItertoolsModule = &starlarkstruct.Module{ Name: "itertools", Members: starlark.StringDict{ "chain": starlark.NewBuiltin("chain", itertoolsChain), "combinations": starlark.NewBuiltin("combinations", itertoolsCombinations), "permutations": starlark.NewBuiltin("permutations", itertoolsPermutations), "product": starlark.NewBuiltin("product", itertoolsProduct), "combinations_with_replacement": starlark.NewBuiltin("combinations_with_replacement", itertoolsCombinationsWithReplacement), }, }
Functions ¶
func AddSelfParamBuiltin ¶
func BuiltinAttr ¶
func ClearChannelRefs ¶
func ClearChannelRefs()
func ClearRoleRefs ¶
func ClearRoleRefs()
func CompareStringer ¶
func CreateResolveRoleBuiltIn ¶ added in v0.2.0
CreateResolveRoleBuiltIn returns a builtin resolve_role, when called with a role's __id__ (GetId()), returns the Role object in the roles array with the given id.
func CreateRoleBuiltin ¶
func GenerateAllPermutations ¶
func GenerateAllPermutations[T any](arr [][]T) [][][]T
GenerateAllPermutations generates all permutations of each subarray and all combinations of these permutations.
func GeneratePermutations ¶
func GeneratePermutations[T any](arr []T) [][]T
GeneratePermutations is a helper function that initializes the result and calls the permute function.
func GenerateRefString ¶
func JsonToYaml ¶
JsonToYaml converts JSON data to YAML data
func Make ¶
func Make(_ *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)
Make is the implementation of a built-in function that instantiates an immutable struct from the specified keyword arguments.
An application can add 'struct' to the Starlark environment like so:
globals := starlark.StringDict{
"struct": starlark.NewBuiltin("struct", starlarkstruct.Make),
}
func MakeGenericMap ¶
func MakeGenericSet ¶
func MakeSymmetricValues ¶
func MarshalJSON ¶
func RandString ¶
func YamlToJson ¶
YamlToJson converts YAML data to JSON data
Types ¶
type Bag ¶
type Bag struct {
// contains filtered or unexported fields
}
func (*Bag) CompareSameType ¶
type Channel ¶
type Channel struct {
Id int `json:"id"`
Name string `json:"name,omitempty"`
// contains filtered or unexported fields
}
Channel represents a custom Starlark object
func (*Channel) MayDropMessages ¶
func (*Channel) RefStringShort ¶
RefStringShort returns a string representation of the Channel object
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
func NewCounter ¶
func NewCounter() *Counter
type GenericMap ¶
type GenericMap struct {
// contains filtered or unexported fields
}
func NewGenericMap ¶
func NewGenericMap() *GenericMap
func (*GenericMap) AttrNames ¶
func (g *GenericMap) AttrNames() []string
func (*GenericMap) Clear ¶
func (g *GenericMap) Clear() error
func (*GenericMap) CompareSameType ¶
func (*GenericMap) Freeze ¶
func (g *GenericMap) Freeze()
func (*GenericMap) Hash ¶
func (g *GenericMap) Hash() (uint32, error)
func (*GenericMap) Items ¶
func (g *GenericMap) Items() []starlark.Tuple
func (*GenericMap) Iterate ¶
func (g *GenericMap) Iterate() starlark.Iterator
func (*GenericMap) Keys ¶
func (g *GenericMap) Keys() []starlark.Value
func (*GenericMap) Len ¶
func (g *GenericMap) Len() int
func (*GenericMap) String ¶
func (g *GenericMap) String() string
func (*GenericMap) Truth ¶
func (g *GenericMap) Truth() starlark.Bool
func (*GenericMap) Type ¶
func (g *GenericMap) Type() string
type GenericSet ¶
type GenericSet struct {
// contains filtered or unexported fields
}
func NewGenericSet ¶
func NewGenericSet() *GenericSet
func (*GenericSet) AttrNames ¶
func (g *GenericSet) AttrNames() []string
func (*GenericSet) Clear ¶
func (g *GenericSet) Clear() error
func (*GenericSet) CompareSameType ¶
func (*GenericSet) Difference ¶
func (*GenericSet) Freeze ¶
func (g *GenericSet) Freeze()
func (*GenericSet) Hash ¶
func (g *GenericSet) Hash() (uint32, error)
func (*GenericSet) Intersection ¶
func (*GenericSet) IsSubset ¶
func (g *GenericSet) IsSubset(other *GenericSet) (bool, error)
func (*GenericSet) IsSuperset ¶
func (s *GenericSet) IsSuperset(other starlark.Iterator) (bool, error)
func (*GenericSet) Iterate ¶
func (g *GenericSet) Iterate() starlark.Iterator
func (*GenericSet) Len ¶
func (g *GenericSet) Len() int
func (*GenericSet) String ¶
func (g *GenericSet) String() string
func (*GenericSet) SymmetricDifference ¶
func (*GenericSet) Truth ¶
func (g *GenericSet) Truth() starlark.Bool
func (*GenericSet) Type ¶
func (g *GenericSet) Type() string
type LinearCollection ¶
type ModelValue ¶
type ModelValue struct {
// contains filtered or unexported fields
}
func NewModelValue ¶
func NewModelValue(prefix string, i int) ModelValue
func (ModelValue) CompareSameType ¶
func (ModelValue) Freeze ¶
func (m ModelValue) Freeze()
func (ModelValue) FullString ¶
func (m ModelValue) FullString() string
func (ModelValue) GetId ¶
func (m ModelValue) GetId() int
func (ModelValue) GetPrefix ¶
func (m ModelValue) GetPrefix() string
func (ModelValue) Hash ¶
func (m ModelValue) Hash() (uint32, error)
func (ModelValue) MarshalJSON ¶
func (m ModelValue) MarshalJSON() ([]byte, error)
func (ModelValue) ShortString ¶
func (m ModelValue) ShortString() string
func (ModelValue) String ¶
func (m ModelValue) String() string
func (ModelValue) Truth ¶
func (m ModelValue) Truth() starlark.Bool
func (ModelValue) Type ¶
func (m ModelValue) Type() string
type RandomQueue ¶
type RandomQueue[T any] struct { // contains filtered or unexported fields }
func NewRandomQueue ¶
func NewRandomQueue[T any](random rand.Rand) *RandomQueue[T]
func (*RandomQueue[T]) Add ¶
func (r *RandomQueue[T]) Add(t T)
func (*RandomQueue[T]) Clear ¶
func (r *RandomQueue[T]) Clear(n int)
func (*RandomQueue[T]) ClearAll ¶
func (r *RandomQueue[T]) ClearAll()
func (*RandomQueue[T]) Empty ¶
func (r *RandomQueue[T]) Empty() bool
func (*RandomQueue[T]) Len ¶
func (r *RandomQueue[T]) Len() int
func (*RandomQueue[T]) Remove ¶
func (r *RandomQueue[T]) Remove() (T, bool)
func (*RandomQueue[T]) Retain ¶
func (r *RandomQueue[T]) Retain(n int)
type Role ¶
type Role struct {
Ref int
Name string
Symmetric bool
Params *Struct
Fields *Struct
Methods map[string]*starlark.Function
RoleMethods map[string]*starlark.Builtin
InitValues *Struct
}
func (*Role) IsSymmetric ¶
func (*Role) MarshalJSON ¶
func (*Role) RefStringShort ¶
type RoleStub ¶
RoleStub wraps an existing Role and associates it with a Channel
func NewRoleStub ¶
type Stack ¶
type Stack[T any] struct { // contains filtered or unexported fields }
func (*Stack[T]) MarshalJSON ¶
func (*Stack[T]) RawArrayCopy ¶
func (s *Stack[T]) RawArrayCopy() []T
type Struct ¶
type Struct struct {
// contains filtered or unexported fields
}
Struct is an immutable Starlark type that maps field names to values. It is not iterable and does not support len.
A struct has a constructor, a distinct value that identifies a class of structs, and which appears in the struct's string representation.
Operations such as x+y fail if the constructors of the two operands are not equal.
The default constructor, Default, is the string "struct", but clients may wish to 'brand' structs for their own purposes. The constructor value appears in the printed form of the value, and is accessible using the Constructor method.
Use Attr to access its fields and AttrNames to enumerate them.
func FromKeywords ¶
FromKeywords returns a new struct instance whose fields are specified by the key/value pairs in kwargs. (Each kwargs[i][0] must be a starlark.String.)
func FromStringDict ¶
func FromStringDict(constructor starlark.Value, d starlark.StringDict) *Struct
FromStringDict returns a new struct instance whose elements are those of d. The constructor parameter specifies the constructor; use Default for an ordinary struct.
func (*Struct) CompareSameType ¶
func (*Struct) Constructor ¶
Constructor returns the constructor used to create this struct.
func (*Struct) MarshalJSON ¶
func (*Struct) ReplaceEntriesFromStringDict ¶
func (s *Struct) ReplaceEntriesFromStringDict(d starlark.StringDict)
func (*Struct) ToStringDict ¶
func (s *Struct) ToStringDict(d starlark.StringDict)
ToStringDict adds a name/value entry to d for each field of the struct.
type SymmetricValue ¶
type SymmetricValue struct {
ModelValue
}
func NewSymmetricValue ¶
func NewSymmetricValue(prefix string, i int) SymmetricValue
func (SymmetricValue) CompareSameType ¶
func (SymmetricValue) Type ¶
func (s SymmetricValue) Type() string
type SymmetricValues ¶
func NewSymmetricValues ¶
func NewSymmetricValues(values []SymmetricValue) *SymmetricValues
func (SymmetricValues) Index ¶
func (s SymmetricValues) Index(i int) SymmetricValue
func (SymmetricValues) Type ¶
func (s SymmetricValues) Type() string
type TriState ¶
type TriState struct {
// contains filtered or unexported fields
}