bldy.build / skylark / skylarkstruct

Index | Files | Exmaples | Directories
go get bldy.build/skylark/skylarkstruct

Package skylarkstruct defines the Skylark ‘struct’ type, an optional language extension.

Index

Package Files

struct.go

Constants

const Default = skylark.String("struct")

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

func Make

func Make(_ *skylark.Thread, _ *skylark.Builtin, args skylark.Tuple, kwargs []skylark.Tuple) (skylark.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 Skylark environment like so:

globals := skylark.StringDict{
	"struct":  skylark.NewBuiltin("struct", skylarkstruct.Make),
}

type Struct

type Struct struct {
    // contains filtered or unexported fields
}

Struct is an immutable Skylark type that maps field names to values. It is not iterable.

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

func FromKeywords(constructor skylark.Value, kwargs []skylark.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 skylark.String.)

func FromStringDict

func FromStringDict(constructor skylark.Value, d skylark.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

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

Attr returns the value of the specified field, or deprecated method if the name is "to_json" or "to_proto" and the struct has no field of that name.

func (*Struct) AttrNames

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

AttrNames returns a new sorted list of the struct fields.

func (*Struct) Binary

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

func (*Struct) CompareSameType

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

func (*Struct) Constructor

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

Constructor returns the constructor used to create this struct.

func (*Struct) Freeze

func (s *Struct) Freeze()

func (*Struct) Hash

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

func (*Struct) Len

func (s *Struct) Len() int

func (*Struct) String

func (s *Struct) String() string

func (*Struct) ToStringDict

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

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

func (*Struct) Truth

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

func (*Struct) Type

func (s *Struct) Type() string

Subdirectories