control.go: use of UnsafeSetVar() in place of SetVar(). SetCtrl() added
This commit is contained in:
parent
0760141caf
commit
cfddbd60b9
13
control.go
13
control.go
@ -11,6 +11,7 @@ const (
|
|||||||
ControlBoolShortcut = "_bool_shortcut"
|
ControlBoolShortcut = "_bool_shortcut"
|
||||||
ControlSearchPath = "_search_path"
|
ControlSearchPath = "_search_path"
|
||||||
ControlParentContext = "_parent_context"
|
ControlParentContext = "_parent_context"
|
||||||
|
ControlStdout = "_stdout"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Other control variables
|
// Other control variables
|
||||||
@ -23,11 +24,17 @@ const (
|
|||||||
init_search_path = "~/.local/lib/go-pkg/expr:/usr/local/lib/go-pkg/expr:/usr/lib/go-pkg/expr"
|
init_search_path = "~/.local/lib/go-pkg/expr:/usr/local/lib/go-pkg/expr:/usr/lib/go-pkg/expr"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func SetCtrl(ctx ExprContext, name string, value any) (current any) {
|
||||||
|
current, _ = ctx.GetVar(name)
|
||||||
|
ctx.UnsafeSetVar(name, value)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func initDefaultVars(ctx ExprContext) {
|
func initDefaultVars(ctx ExprContext) {
|
||||||
if _, exists := ctx.GetVar(ControlPreset); exists {
|
if _, exists := ctx.GetVar(ControlPreset); exists {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.SetVar(ControlPreset, true)
|
ctx.UnsafeSetVar(ControlPreset, true)
|
||||||
ctx.SetVar(ControlBoolShortcut, true)
|
ctx.UnsafeSetVar(ControlBoolShortcut, true)
|
||||||
ctx.SetVar(ControlSearchPath, init_search_path)
|
ctx.UnsafeSetVar(ControlSearchPath, init_search_path)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user