Documentation ¶
Overview ¶
Package vars implement lucicfg.var() support.
See lucicfg.var() doc for more info.
Index ¶
- func GetDefaultRewriter() *build.Rewriter
- type ID
- type Vars
- func (v *Vars) ClearValues()
- func (v *Vars) CloseScope(th *starlark.Thread)
- func (v *Vars) Declare(th *starlark.Thread, exposeAs string, presetVal starlark.Value) (ID, error)
- func (v *Vars) Get(th *starlark.Thread, id ID, def starlark.Value) (starlark.Value, error)
- func (v *Vars) OpenScope(th *starlark.Thread)
- func (v *Vars) Set(th *starlark.Thread, id ID, value starlark.Value) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetDefaultRewriter ¶
GetDefaultRewriter will return the default rewriter with basic rewriter properties
Types ¶
type ID ¶
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.
type Vars ¶
type Vars struct { // DeclaredExposeAsAliases is a set of all `exposeAs` passed to Declare. DeclaredExposeAsAliases stringset.Set // 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 ¶
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 ¶
CloseScope discards changes made to variables since the matching OpenScope.
func (*Vars) Declare ¶
Declare allocates a new variable, setting it right away to 'presetVal' value if 'exposeAs' not empty.
Variables that were pre-set during declaration are essentially immutable throughout lifetime of the interpreter.
Returns an error if a variable with the same `exposeAs` name has already been exposed.
func (*Vars) Get ¶
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 ¶
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 ¶
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.