From 472adc840789b23201b3e1f7f977553436f52431 Mon Sep 17 00:00:00 2001 From: Erik Veld Date: Mon, 21 Oct 2024 17:34:08 +0200 Subject: [PATCH] make it possible to return booleans from custom funcs --- functions.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/functions.go b/functions.go index eb33256..429ed56 100644 --- a/functions.go +++ b/functions.go @@ -82,6 +82,8 @@ func createCtyFunctionFromGoFunc(f interface{}) (function.Function, error) { fallthrough case reflect.Uint: outParam = function.StaticReturnType(cty.Number) + case reflect.Bool: + outParam = function.StaticReturnType(cty.Bool) default: return function.Function{}, fmt.Errorf("type %v is not a valid cyt type, only primative types like string and basic numbers are supported", rf.Out(0).Kind()) } @@ -130,6 +132,8 @@ func createCtyFunctionFromGoFunc(f interface{}) (function.Function, error) { val, _ := bf.Float64() in = append(in, reflect.ValueOf(float64(val))) } + case cty.Bool: + in = append(in, reflect.ValueOf(a.True())) } } @@ -177,6 +181,12 @@ func createCtyFunctionFromGoFunc(f interface{}) (function.Function, error) { return cty.NumberFloatVal(out[0].Float()), out[1].Interface().(error) } } + case cty.Bool: + if out[1].Interface() == nil { + return cty.BoolVal(out[0].Bool()), nil + } else { + return cty.BoolVal(out[0].Bool()), out[1].Interface().(error) + } } return cty.NullVal(retType), nil