Globals sets the global variable values for a given program. These values may be shadowed by variables with the same name provided to the Eval() call. If Globals is used in a Library with a Lib EnvOption, vars may shadow variables provided by previously added libraries. The vars value may either be
(vars any)
| 498 | // |
| 499 | // The vars value may either be an `cel.Activation` instance or a `map[string]any`. |
| 500 | func Globals(vars any) ProgramOption { |
| 501 | return func(p *prog) (*prog, error) { |
| 502 | defaultVars, err := NewActivation(vars) |
| 503 | if err != nil { |
| 504 | return nil, err |
| 505 | } |
| 506 | if p.defaultVars != nil { |
| 507 | defaultVars = interpreter.NewHierarchicalActivation(p.defaultVars, defaultVars) |
| 508 | } |
| 509 | p.defaultVars = defaultVars |
| 510 | return p, nil |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | // OptimizeRegex provides a way to replace the InterpretableCall for regex functions. This can be used |
| 515 | // to compile regex string constants at program creation time and report any errors and then use the |