AddFunctionDecls adds one or more functions to the config, converting them to serializable values first. FunctionDecl inputs are expected to be well-formed.
(funcs ...*decls.FunctionDecl)
| 144 | // |
| 145 | // FunctionDecl inputs are expected to be well-formed. |
| 146 | func (c *Config) AddFunctionDecls(funcs ...*decls.FunctionDecl) *Config { |
| 147 | convFuncs := make([]*Function, len(funcs)) |
| 148 | for i, fn := range funcs { |
| 149 | if fn == nil { |
| 150 | continue |
| 151 | } |
| 152 | overloads := make([]*Overload, 0, len(fn.OverloadDecls())) |
| 153 | for _, o := range fn.OverloadDecls() { |
| 154 | overloadID := o.ID() |
| 155 | args := make([]*TypeDesc, 0, len(o.ArgTypes())) |
| 156 | for _, a := range o.ArgTypes() { |
| 157 | args = append(args, SerializeTypeDesc(a)) |
| 158 | } |
| 159 | ret := SerializeTypeDesc(o.ResultType()) |
| 160 | var overload *Overload |
| 161 | if o.IsMemberFunction() { |
| 162 | overload = NewMemberOverload(overloadID, args[0], args[1:], ret) |
| 163 | } else { |
| 164 | overload = NewOverload(overloadID, args, ret) |
| 165 | } |
| 166 | exampleCount := len(o.Examples()) |
| 167 | if exampleCount > 0 { |
| 168 | overload.Examples = o.Examples() |
| 169 | } |
| 170 | overloads = append(overloads, overload) |
| 171 | } |
| 172 | cf := NewFunction(fn.Name(), overloads...) |
| 173 | cf.Description = fn.Description() |
| 174 | convFuncs[i] = cf |
| 175 | } |
| 176 | return c.AddFunctions(convFuncs...) |
| 177 | } |
| 178 | |
| 179 | // AddFunctions adds one or more functions to the config. |
| 180 | func (c *Config) AddFunctions(funcs ...*Function) *Config { |