Documentation ¶
Overview ¶
Package starlarkstruct defines the Starlark types 'struct' and 'module', both optional language extensions.
Index ¶
- Constants
- func Make(_ *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, ...) (starlark.Value, error)
- func MakeModule(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, ...) (starlark.Value, error)
- type Module
- 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) String() string
- func (s *Struct) ToStringDict(d starlark.StringDict)
- func (s *Struct) Truth() starlark.Bool
- func (s *Struct) Type() string
Constants ¶
const Default = starlark.String("struct")
Default is the default constructor for structs. It is merely the string "struct".
Variables ¶
This section is empty.
Functions ¶
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 MakeModule ¶
func MakeModule(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)
MakeModule may be used as the implementation of a Starlark built-in function, module(name, **kwargs). It returns a new module with the specified name and members.
Types ¶
type Module ¶
type Module struct { Name string Members starlark.StringDict }
A Module is a named collection of values, typically a suite of functions imported by a load statement.
It differs from Struct primarily in that its string representation does not enumerate its fields.
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 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) ToStringDict ¶
func (s *Struct) ToStringDict(d starlark.StringDict)
ToStringDict adds a name/value entry to d for each field of the struct.