go.starlark.net: go.starlark.net/starlarkstruct Index | Files

package starlarkstruct

import "go.starlark.net/starlarkstruct"

Package starlarkstruct defines the Starlark types 'struct' and 'module', both optional language extensions.

Index

Package Files

module.go struct.go

Constants

const Default = starlark.String("struct")

Default is the default constructor for structs. It is merely the string "struct".

func Make Uses

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 Uses

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.

type Module Uses

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.

func (*Module) Attr Uses

func (m *Module) Attr(name string) (starlark.Value, error)

func (*Module) AttrNames Uses

func (m *Module) AttrNames() []string

func (*Module) Freeze Uses

func (m *Module) Freeze()

func (*Module) Hash Uses

func (m *Module) Hash() (uint32, error)

func (*Module) String Uses

func (m *Module) String() string

func (*Module) Truth Uses

func (m *Module) Truth() starlark.Bool

func (*Module) Type Uses

func (m *Module) Type() string

type Struct Uses

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 Uses

func FromKeywords(constructor starlark.Value, kwargs []starlark.Tuple) *Struct

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 Uses

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) Attr Uses

func (s *Struct) Attr(name string) (starlark.Value, error)

Attr returns the value of the specified field.

func (*Struct) AttrNames Uses

func (s *Struct) AttrNames() []string

AttrNames returns a new sorted list of the struct fields.

func (*Struct) Binary Uses

func (x *Struct) Binary(op syntax.Token, y starlark.Value, side starlark.Side) (starlark.Value, error)

func (*Struct) CompareSameType Uses

func (x *Struct) CompareSameType(op syntax.Token, y_ starlark.Value, depth int) (bool, error)

func (*Struct) Constructor Uses

func (s *Struct) Constructor() starlark.Value

Constructor returns the constructor used to create this struct.

func (*Struct) Freeze Uses

func (s *Struct) Freeze()

func (*Struct) Hash Uses

func (s *Struct) Hash() (uint32, error)

func (*Struct) String Uses

func (s *Struct) String() string

func (*Struct) ToStringDict Uses

func (s *Struct) ToStringDict(d starlark.StringDict)

ToStringDict adds a name/value entry to d for each field of the struct.

func (*Struct) Truth Uses

func (s *Struct) Truth() starlark.Bool

func (*Struct) Type Uses

func (s *Struct) Type() string

Package starlarkstruct imports 5 packages (graph) and is imported by 34 packages. Updated 2019-06-06. Refresh now. Tools for package owners.