lang: core, funcs: Port some functions to CallableFunc API

Some modern features of our function engine and language might require
this new API, so port what we can and figure out the rest later.
This commit is contained in:
James Shubin
2025-03-16 23:23:57 -04:00
parent f313380480
commit 642c6b952f
29 changed files with 702 additions and 291 deletions

View File

@@ -115,12 +115,14 @@ func (obj *IfFunc) Stream(ctx context.Context) error {
}
obj.last = input // store for next
var result types.Value
args, err := interfaces.StructToCallableArgs(input) // []types.Value, error)
if err != nil {
return err
}
if input.Struct()["c"].Bool() {
result = input.Struct()["a"] // true branch
} else {
result = input.Struct()["b"] // false branch
result, err := obj.Call(ctx, args) // get the value...
if err != nil {
return err
}
// skip sending an update...
@@ -141,3 +143,13 @@ func (obj *IfFunc) Stream(ctx context.Context) error {
}
}
}
// Call this function with the input args and return the value if it is possible
// to do so at this time.
// XXX: Is is correct to implement this here for this particular function?
func (obj *IfFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) {
if c := args[0].Bool(); c {
return args[1], nil // true branch
}
return args[2], nil
}