skylark: github.com/google/skylark/skylarkstruct Index | Files

package skylarkstruct

import "github.com/google/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 Uses

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 Uses

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

Struct is an immutable Skylark 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 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 Uses

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 Uses

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 Uses

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

AttrNames returns a new sorted list of the struct fields.

Unlike in the Java implementation, the deprecated struct methods "to_json" and "to_proto" do not appear in AttrNames, and hence dir(struct), since that would force the majority to have to ignore them, but they may nonetheless be called if the struct does not have fields of these names. Ideally these will go away soon. See Google issue b/36412967.

func (*Struct) Binary Uses

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

func (*Struct) CompareSameType Uses

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

func (*Struct) Constructor Uses

func (s *Struct) Constructor() skylark.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 skylark.StringDict)

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

func (*Struct) Truth Uses

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

func (*Struct) Type Uses

func (s *Struct) Type() string

Package skylarkstruct imports 6 packages (graph) and is imported by 3 packages. Updated 2018-10-24. Refresh now. Tools for package owners.