Skip to content

Commit 5a39513

Browse files
authored
messagix/bloks: support bk.action.core.Let (#264)
1 parent cd0293c commit 5a39513

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

pkg/messagix/bloks/interp.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,23 @@ func (i *Interpreter) Evaluate(ctx context.Context, form *BloksScriptNode) (*Blo
368368
return first, nil
369369
}
370370
return i.Evaluate(ctx, &call.Args[1])
371+
case "bk.action.core.Let":
372+
// Lazy-init: return arg0 if non-null, else apply the FuncConst in arg1.
373+
current, err := i.Evaluate(ctx, &call.Args[0])
374+
if err != nil {
375+
return nil, err
376+
}
377+
if current.IsTruthy() {
378+
return current, nil
379+
}
380+
init, err := evalAs[*BloksLambda](ctx, i, &call.Args[1], "let.init")
381+
if err != nil {
382+
return nil, err
383+
}
384+
newArgs := make([]*BloksScriptLiteral, maxInterpArgs)
385+
copy(newArgs, init.BoundArgs)
386+
ctx = context.WithValue(ctx, interpCtxArgs, newArgs)
387+
return i.Evaluate(ctx, init.Body)
371388
case "bk.action.bloks.GetVariable2", "bk.action.bloks.GetVariableWithScope":
372389
// The second argument to the WithScope variant is an integer that may specify
373390
// whether to get a local or global variable. For now, ignore.

0 commit comments

Comments
 (0)