Documentation ¶
Overview ¶
Package skylarkstruct defines the Skylark 'struct' type, an optional language extension.
Index ¶
- Constants
- func Make(_ *skylark.Thread, _ *skylark.Builtin, args skylark.Tuple, ...) (skylark.Value, error)
- type Struct
- func (s *Struct) Attr(name string) (skylark.Value, error)
- func (s *Struct) AttrNames() []string
- func (x *Struct) Binary(op syntax.Token, y skylark.Value, side skylark.Side) (skylark.Value, error)
- func (x *Struct) CompareSameType(op syntax.Token, y_ skylark.Value, depth int) (bool, error)
- func (s *Struct) Constructor() skylark.Value
- func (s *Struct) Freeze()
- func (s *Struct) Hash() (uint32, error)
- func (s *Struct) String() string
- func (s *Struct) ToStringDict(d skylark.StringDict)
- func (s *Struct) Truth() skylark.Bool
- func (s *Struct) Type() string
Constants ¶
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 ¶
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 ¶
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 ¶
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) CompareSameType ¶
func (*Struct) Constructor ¶
Constructor returns the constructor used to create this struct.
func (*Struct) ToStringDict ¶
func (s *Struct) ToStringDict(d skylark.StringDict)
ToStringDict adds a name/value entry to d for each field of the struct.