From 703ecf6829f940049231817fae77fb21adb682b3 Mon Sep 17 00:00:00 2001 From: Celestino Amoroso Date: Mon, 17 Jun 2024 06:56:32 +0200 Subject: [PATCH] Added utility function GetLast() to context --- context.go | 1 + simple-store.go | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/context.go b/context.go index f263a3c..20ae49b 100644 --- a/context.go +++ b/context.go @@ -40,6 +40,7 @@ type ExprContext interface { SetParent(ctx ExprContext) GetParent() (ctx ExprContext) GetVar(varName string) (value any, exists bool) + GetLast() any SetVar(varName string, value any) UnsafeSetVar(varName string, value any) EnumVars(func(name string) (accept bool)) (varNames []string) diff --git a/simple-store.go b/simple-store.go index c460970..a626274 100644 --- a/simple-store.go +++ b/simple-store.go @@ -7,7 +7,7 @@ package expr import ( "fmt" "slices" -// "strings" + // "strings" ) type SimpleStore struct { @@ -50,6 +50,7 @@ func (ctx *SimpleStore) Merge(src ExprContext) { ctx.funcStore[name], _ = src.GetFuncInfo(name) } } + /* func varsCtxToBuilder(sb *strings.Builder, ctx ExprContext, indent int) { sb.WriteString("vars: {\n") @@ -165,6 +166,11 @@ func (ctx *SimpleStore) GetVar(varName string) (v any, exists bool) { return } +func (ctx *SimpleStore) GetLast() (v any) { + v = ctx.varStore["last"] + return +} + func (ctx *SimpleStore) UnsafeSetVar(varName string, value any) { // fmt.Printf("[%p] setVar(%v, %v)\n", ctx, varName, value) ctx.varStore[varName] = value