skylarkstruct

package
v0.0.0-...-a5f7082 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2018 License: BSD-3-Clause Imports: 6 Imported by: 6

Documentation

Overview

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

Index

Constants

View Source
const Default = skylark.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(_ *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),
}

Types

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 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

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.

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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL