thirdlib

package module
v0.0.0-...-853ce1f Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2021 License: MIT Imports: 14 Imported by: 1

README

starlark-go-lib

starlark-go-lib not only provide some libs for starlark-go, but also provide a simple method to create modules from go-lib to starlark-go lib.

examples to create modules

package httplib

import (
	"net/http"

	thirdlib "github.com/u2takey/starlark-go-lib"
	"go.starlark.net/starlark"
	"go.starlark.net/starlarkstruct"
)

var httpModules = &starlarkstruct.Module{
	Name: "http",
	Members: starlark.StringDict{
		"get":           thirdlib.ToValue(http.Get),
		"pos":           thirdlib.ToValue(http.Post),
		"defaultClient": thirdlib.ToValue(http.DefaultClient),
	},
}

examples to use created modules

➜ ./starlark -recursion -set -globalreassign -lambda
Welcome to Starlark (go.starlark.net)
>>> resp, err = http.get("http://baidu.com")
>>> resp.StatusCode
200

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GreetModule = &starlarkstruct.Module{
	Name: "greet",
	Members: starlark.StringDict{
		"new":         ToValue(NewGreet),
		"default":     ToValue(&Greet{}),
		"newWithName": ToValue(NewGreetWith),
	},
}

Functions

func DecodeValue

func DecodeValue(value interface{}) starlark.Value

only for decode, userValue not included in return types

func InstallAllExampleModule

func InstallAllExampleModule(d starlark.StringDict)

func ToValue

func ToValue(value interface{}) starlark.Value

Types

type E

type E = []M

type Greet

type Greet struct {
	Name string
}

func NewGreet

func NewGreet() *Greet

func NewGreetWith

func NewGreetWith(name string) *Greet

func (*Greet) CopyFrom

func (t *Greet) CopyFrom(b *Greet) *Greet

func (*Greet) Hello

func (t *Greet) Hello() string

func (*Greet) HelloTo

func (t *Greet) HelloTo(a string) string

func (*Greet) RenameWithFunc

func (t *Greet) RenameWithFunc(f func(a string) string) *Greet

type M

type M = map[string]interface{}

type UserValue

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

func NewUserValue

func NewUserValue(value interface{}, thread *starlark.Thread) *UserValue

func (*UserValue) Attr

func (u *UserValue) Attr(name string) (starlark.Value, error)

func (*UserValue) AttrNames

func (u *UserValue) AttrNames() (ret []string)

func (*UserValue) CallInternal

func (u *UserValue) CallInternal(thread *starlark.Thread, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

func (*UserValue) Freeze

func (u *UserValue) Freeze()

func (*UserValue) Get

func (u *UserValue) Get(k starlark.Value) (v starlark.Value, found bool, err error)

func (*UserValue) Hash

func (u *UserValue) Hash() (uint32, error)

func (*UserValue) Index

func (u *UserValue) Index(i int) starlark.Value

func (*UserValue) Items

func (u *UserValue) Items() (ret []starlark.Tuple)

func (*UserValue) Iterate

func (u *UserValue) Iterate() starlark.Iterator

func (*UserValue) Len

func (u *UserValue) Len() int

func (*UserValue) Name

func (u *UserValue) Name() string

func (*UserValue) SetField

func (u *UserValue) SetField(name string, val starlark.Value) error

func (*UserValue) SetIndex

func (u *UserValue) SetIndex(index int, v starlark.Value) error

func (*UserValue) SetKey

func (u *UserValue) SetKey(k, v starlark.Value) error

func (*UserValue) Slice

func (u *UserValue) Slice(start, end, step int) starlark.Value

func (*UserValue) String

func (u *UserValue) String() string

func (*UserValue) Truth

func (u *UserValue) Truth() starlark.Bool

func (*UserValue) Type

func (u *UserValue) Type() string

Directories

Path Synopsis
cmd
starlark
The starlark command interprets a Starlark file.
The starlark command interprets a Starlark file.

Jump to

Keyboard shortcuts

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