Skip to content

Commit

Permalink
lang: funcs: vars: Include system package variables in the scope
Browse files Browse the repository at this point in the history
  • Loading branch information
purpleidea committed Aug 7, 2024
1 parent a93c984 commit 8e9c3b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lang/ast/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3433,10 +3433,13 @@ func (obj *StmtProg) importSystemScope(name string) (*interfaces.Scope, error) {
// TODO: do we want to run Interpolate or SetScope?
}

// TODO: pass `data` into ast.VarPrefixToVariablesScope ?
variables := VarPrefixToVariablesScope(name) // strips prefix!

// initial scope, built from core golang code
scope := &interfaces.Scope{
// TODO: we could use the core API for variables somehow...
//Variables: make(map[string]interfaces.Expr),
Variables: variables,
Functions: functions, // map[string]interfaces.Expr
// TODO: we could add a core API for classes too!
//Classes: make(map[string]interfaces.Stmt),
Expand Down
11 changes: 8 additions & 3 deletions lang/funcs/vars/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ const (
ResourceNamespace = "res"
)

// Value is a shortcut to using this type.
// XXX: Eventually we might get rid of this entirely and use types.Value instead
// of interfaces.Var which seems to be unnecessary at the moment.
type Value = interfaces.Var

// registeredVars is a global map of all possible vars which can be used. You
// should never touch this map directly. Use methods like Register instead.
var registeredVars = make(map[string]func() interfaces.Var) // must initialize
Expand All @@ -63,9 +68,9 @@ func Register(name string, fn func() interfaces.Var) {

// ModuleRegister is exactly like Register, except that it registers within a
// named module. This is a helper function.
//func ModuleRegister(module, name string, v func() interfaces.Var) {
// Register(module+interfaces.ModuleSep+name, v)
//}
func ModuleRegister(module, name string, v func() interfaces.Var) {
Register(module+interfaces.ModuleSep+name, v)
}

// resourceConstHelper is a helper function to manage the const topology.
func resourceConstHelper(kind, param, field string) string {
Expand Down

0 comments on commit 8e9c3b6

Please sign in to comment.