Control vars are now stored in the globalCtx only.

However, it is still allowed to store control var in a local context in special situation
This commit is contained in:
2024-06-07 14:39:17 +02:00
parent 115ce26ce9
commit f347b15146
7 changed files with 74 additions and 65 deletions
-56
View File
@@ -4,8 +4,6 @@
// control.go
package expr
import "strings"
// Preset control variables
const (
ControlPreset = "_preset"
@@ -34,60 +32,6 @@ func initDefaultVars(ctx ExprContext) {
ctx.SetVar(ControlSearchPath, init_search_path)
}
func CtrlEnable(ctx ExprContext, name string) (currentStatus bool) {
if !strings.HasPrefix(name, "_") {
name = "_" + name
}
if v, exists := ctx.GetVar(name); exists && IsBool(v) {
currentStatus, _ = v.(bool)
}
ctx.SetVar(name, true)
return currentStatus
}
func CtrlDisable(ctx ExprContext, name string) (currentStatus bool) {
if !strings.HasPrefix(name, "_") {
name = "_" + name
}
if v, exists := ctx.GetVar(name); exists && IsBool(v) {
currentStatus, _ = v.(bool)
}
ctx.SetVar(name, false)
return currentStatus
}
func CtrlSet(ctx ExprContext, name string, newValue any) (currentValue any) {
if !strings.HasPrefix(name, "_") {
name = "_" + name
}
currentValue, _ = ctx.GetVar(name)
ctx.SetVar(name, newValue)
for parent := ctx.GetParent(); parent != nil; parent = parent.GetParent() {
parent.SetVar(name, newValue)
}
return currentValue
}
func CtrlGet(ctx ExprContext, name string) (currentValue any) {
if !strings.HasPrefix(name, "_") {
name = "_" + name
}
currentValue, _ = ctx.GetVar(name)
return currentValue
}
func isEnabled(ctx ExprContext, name string) (status bool) {
if v, exists := ctx.GetVar(name); exists {
if b, ok := v.(bool); ok {
status = b
}
}
return
}
func getControlString(ctx ExprContext, name string) (s string, exists bool) {
var v any
if v, exists = ctx.GetVar(name); exists {