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"
 | 
			
		||||
	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)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user