| 1 | package interp |
| 2 | |
| 3 | import "reflect" |
| 4 | |
| 5 | // convertFn is the signature of a symbol converter. |
| 6 | type convertFn func(from, to reflect.Type) func(src, dest reflect.Value) |
| 7 | |
| 8 | // hooks are external symbol bindings. |
| 9 | type hooks struct { |
| 10 | convert []convertFn |
| 11 | } |
| 12 | |
| 13 | func (h *hooks) Parse(m map[string]reflect.Value) { |
| 14 | if con, ok := getConvertFn(m["convert"]); ok { |
| 15 | h.convert = append(h.convert, con) |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | func getConvertFn(v reflect.Value) (convertFn, bool) { |
| 20 | if !v.IsValid() { |
| 21 | return nil, false |
| 22 | } |
| 23 | fn, ok := v.Interface().(func(from, to reflect.Type) func(src, dest reflect.Value)) |
| 24 | if !ok { |
| 25 | return nil, false |
| 26 | } |
| 27 | return fn, true |
| 28 | } |