// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
// All rights reserved.

// control.go
package expr

// Preset control variables
const (
	ControlPreset        = "_preset"
	ControlLastResult    = "last"
	ControlBoolShortcut  = "_bool_shortcut"
	ControlSearchPath    = "_search_path"
	ControlParentContext = "_parent_context"
	ControlStdout        = "_stdout"
)

// Other control variables
const (
	control_export_all = "_export_all"
)

// Initial values
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.UnsafeSetVar(ControlPreset, true)
	ctx.UnsafeSetVar(ControlBoolShortcut, true)
	ctx.UnsafeSetVar(ControlSearchPath, init_search_path)
}
