From cfddbd60b9d58cd74b6dd11d42a018272a0bbe40 Mon Sep 17 00:00:00 2001 From: Celestino Amoroso Date: Tue, 25 Jun 2024 10:53:05 +0200 Subject: [PATCH] control.go: use of UnsafeSetVar() in place of SetVar(). SetCtrl() added --- control.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/control.go b/control.go index 165a7dc..1c4edeb 100644 --- a/control.go +++ b/control.go @@ -11,6 +11,7 @@ const ( ControlBoolShortcut = "_bool_shortcut" ControlSearchPath = "_search_path" ControlParentContext = "_parent_context" + ControlStdout = "_stdout" ) // 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" ) +func SetCtrl(ctx ExprContext, name string, value any) (current any) { + current, _ = ctx.GetVar(name) + ctx.UnsafeSetVar(name, value) + return +} + func initDefaultVars(ctx ExprContext) { if _, exists := ctx.GetVar(ControlPreset); exists { return } - ctx.SetVar(ControlPreset, true) - ctx.SetVar(ControlBoolShortcut, true) - ctx.SetVar(ControlSearchPath, init_search_path) + ctx.UnsafeSetVar(ControlPreset, true) + ctx.UnsafeSetVar(ControlBoolShortcut, true) + ctx.UnsafeSetVar(ControlSearchPath, init_search_path) }