Documentation
¶
Overview ¶
datalarkengine contains all the low-level binding logic.
Perhaps somewhat surprisingly, it includes even wrapper types for the more primitive kinds (like string). This is important (rather than just converting them directly to starlark's values) because we may want things like IPLD type information (or even just NodePrototype) to be retained, as well as sometimes wanting the original pointer to be retained for efficiency reasons.
Example (Map) ¶
evalExample(`
x = {"bz": "zoo"}
print(datalark.Map(hey="hai", zonk="wot", **x))
print(datalark.Map({datalark.String("fun"): "heeey"}))
`, nil)
Output: map{ string{"hey"}: string{"hai"} string{"zonk"}: string{"wot"} string{"bz"}: string{"zoo"} } map{ string{"fun"}: string{"heeey"} }
Example (MapWithStructKeys) ¶
ts := schema.MustTypeSystem(
schema.SpawnString("String"),
schema.SpawnStruct("FooBar", []schema.StructField{
schema.SpawnStructField("foo", "String", false, false),
schema.SpawnStructField("bar", "String", false, false),
}, schema.SpawnStructRepresentationStringjoin(":")),
schema.SpawnMap("Map__FooBar__String", "FooBar", "String", false),
)
type FooBar struct{ Foo, Bar string }
type M struct {
Keys []FooBar
Values map[FooBar]string
}
evalExample(`
#print(mytypes.Map__FooBar__String({"f:b": "wot"})) # I want this to work someday, but it's not quite that magic yet.
print(mytypes.Map__FooBar__String({mytypes.FooBar(foo="f", bar="b"): "wot"}))
`, []schema.TypedPrototype{
bindnode.Prototype((*FooBar)(nil), ts.TypeByName("FooBar")),
bindnode.Prototype((*M)(nil), ts.TypeByName("Map__FooBar__String")),
})
Output: map<Map__FooBar__String>{ struct<FooBar>{foo: string<String>{"f"}, bar: string<String>{"b"}}: string<String>{"wot"} }
Example (String) ¶
evalExample(`
print(datalark.String("yo"))
`, nil)
Output: string{"yo"}
Example (Structs) ¶
ts := schema.MustTypeSystem(
schema.SpawnString("String"),
schema.SpawnStruct("FooBar", []schema.StructField{
schema.SpawnStructField("foo", "String", false, false),
schema.SpawnStructField("bar", "String", false, false),
}, nil),
)
type FooBar struct{ Foo, Bar string }
evalExample(`
print(mytypes.FooBar)
print(mytypes.FooBar(foo="hai", bar="wot"))
x = {"foo": "z"}
x["bar"] = "å!"
print(mytypes.FooBar(**x))
`, []schema.TypedPrototype{
bindnode.Prototype((*FooBar)(nil), ts.TypeByName("FooBar")),
})
Output: <built-in function datalark.Prototype<FooBar>> struct<FooBar>{ foo: string<String>{"hai"} bar: string<String>{"wot"} } struct<FooBar>{ foo: string<String>{"z"} bar: string<String>{"å!"} }
Index ¶
- func ConstructMap(np datamodel.NodePrototype, _ *starlark.Thread, args starlark.Tuple, ...) (starlark.Value, error)
- func ConstructString(np datamodel.NodePrototype, _ *starlark.Thread, b *starlark.Builtin, ...) (starlark.Value, error)
- func ConstructStruct(npt schema.TypedPrototype, _ *starlark.Thread, args starlark.Tuple, ...) (starlark.Value, error)
- func InjectGlobals(globals starlark.StringDict, obj *Object)
- func Unwrap(sval starlark.Value) datamodel.Node
- type Map
- type Object
- func (g *Object) Attr(name string) (starlark.Value, error)
- func (g *Object) AttrNames() []string
- func (d *Object) Freeze()
- func (d *Object) Get(k starlark.Value) (v starlark.Value, found bool, err error)
- func (d *Object) Hash() (uint32, error)
- func (d *Object) Items() []starlark.Tuple
- func (d *Object) Iterate() starlark.Iterator
- func (d *Object) Keys() []starlark.Value
- func (d *Object) Len() int
- func (d *Object) SetKey(k, v starlark.Value) error
- func (d *Object) String() string
- func (d *Object) Truth() starlark.Bool
- func (d *Object) Type() string
- type Prototype
- func (g *Prototype) CallInternal(thread *starlark.Thread, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)
- func (g *Prototype) Freeze()
- func (g *Prototype) Hash() (uint32, error)
- func (g *Prototype) Name() string
- func (g *Prototype) String() string
- func (g *Prototype) Truth() starlark.Bool
- func (g *Prototype) Type() string
- type String
- type Struct
- func (g *Struct) Attr(name string) (starlark.Value, error)
- func (g *Struct) AttrNames() []string
- func (g *Struct) Freeze()
- func (g *Struct) Hash() (uint32, error)
- func (g *Struct) Node() datamodel.Node
- func (g *Struct) SetField(name string, val starlark.Value) error
- func (g *Struct) String() string
- func (g *Struct) Truth() starlark.Bool
- func (g *Struct) Type() string
- type Value
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConstructMap ¶
func ConstructString ¶
func ConstructStruct ¶
func InjectGlobals ¶
func InjectGlobals(globals starlark.StringDict, obj *Object)
See docs on datalark.InjectGlobals. Typically you should prefer using functions in the datalark package, rather than their equivalents in the datalarkengine package.
Types ¶
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
type Object ¶
Object is a starlark.Value that contains arbitrary attributes (like a starlark.Dict), and also lets you access things with dot notation (e.g. as "attrs") in addition to with map key notation.
We use this for creating hierarchical namespaces. (For example, this is how we make typed constructors available without cluttering global namespaces.)
func ObjOfConstructorsForPrimitives ¶
func ObjOfConstructorsForPrimitives() *Object
See docs on datalark.ObjOfConstructorsForPrimitives. Typically you should prefer using functions in the datalark package, rather than their equivalents in the datalarkengine package.
func ObjOfConstructorsForPrototypes ¶
func ObjOfConstructorsForPrototypes(prototypes ...schema.TypedPrototype) *Object
See docs on datalark.ObjOfConstructorsForPrototypes. Typically you should prefer using functions in the datalark package, rather than their equivalents in the datalarkengine package.
type Prototype ¶
type Prototype struct {
// contains filtered or unexported fields
}
Prototype wraps an IPLD `datamodel.NodePrototype`, and in starlark, is a `Callable` which acts like a constructor for that NodePrototype.
There is only one Prototype type, and its behavior varies based on the `datamodel.NodePrototype` its bound to.