luci: go.chromium.org/luci/lucicfg/vars Index | Files

package vars

import "go.chromium.org/luci/lucicfg/vars"

Package vars implement lucicfg.var() support.

See lucicfg.var() doc for more info.

Index

Package Files

vars.go

type ID Uses

type ID int

ID is an opaque starlark value that represents a lucifg.var() variable.

It is just a unique identifier for this particular variable, used as a key in a map with variables values.

func (ID) Freeze Uses

func (v ID) Freeze()

func (ID) Hash Uses

func (v ID) Hash() (uint32, error)

func (ID) String Uses

func (v ID) String() string

func (ID) Truth Uses

func (v ID) Truth() starlark.Bool

func (ID) Type Uses

func (v ID) Type() string

type Vars Uses

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

Vars holds definitions and current state of lucicfg.var() variables.

It exposes OpenScope/CloseScope that should be connected to PreExec/PostExec interpreter hooks. They "open" and "close" scopes for variables: all changes made to vars state within a scope (i.e. within single exec-ed module) are discarded when the scope is closed.

func (*Vars) ClearValues Uses

func (v *Vars) ClearValues()

ClearValues resets values of all variables, in all scopes.

Should be used only from tests that want a clean slate.

func (*Vars) CloseScope Uses

func (v *Vars) CloseScope(th *starlark.Thread)

CloseScope discards changes made to variables since the matching OpenScope.

func (*Vars) Declare Uses

func (v *Vars) Declare() ID

Declare allocates a new variable.

func (*Vars) Get Uses

func (v *Vars) Get(th *starlark.Thread, id ID, def starlark.Value) (starlark.Value, error)

Get returns the value of a variable, auto-initializing it to 'def' if it was unset before.

Variable can be assigned or read only from threads that perform 'exec' calls, NOT when loading library modules via 'load' (the library modules must not have side effects or depend on a transient state in vars), or executing callbacks (callbacks do not have enough context to safely use vars).

func (*Vars) OpenScope Uses

func (v *Vars) OpenScope(th *starlark.Thread)

OpenScope opens a new scope for variables.

All changes to variables' values made within this scope are discarded when it is closed.

func (*Vars) Set Uses

func (v *Vars) Set(th *starlark.Thread, id ID, value starlark.Value) error

Set sets the value of a variable within the current scope iff the variable was unset before (in the current or any parent scopes).

Variable can be assigned or read only from threads that perform 'exec' calls, NOT when loading library modules via 'load' (the library modules must not have side effects or depend on a transient state in vars), or executing callbacks (callbacks do not have enough context to safely use vars).

Freezes the value as a side effect.

Package vars imports 4 packages (graph) and is imported by 2 packages. Updated 2019-08-25. Refresh now. Tools for package owners.