/
TC_cb_function.go
35 lines (28 loc) · 927 Bytes
/
TC_cb_function.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package ThreadComputation
import (
"fmt"
log "github.com/sirupsen/logrus"
)
type TCGenericFunction func(interface{}) interface{}
func GetFunctionCallback(name string, x interface{}) TCGenericFunction {
x_type := TCType(x)
fname := fmt.Sprintf("fun.%v.%v", name, x_type)
log.Debugf("Looking for function for %v(%T)", name, x)
if fun, ok := Callbacks.Load(fname); ok {
log.Debugf("Got: %v", fname)
return fun.(TCGenericFunction)
}
fname = fmt.Sprintf("fun.%v.%v", name, Any)
log.Debugf("Looking for function for %v(Any)", name)
if fun, ok := Callbacks.Load(fname); ok {
log.Debugf("Got: %v", fname)
return fun.(TCGenericFunction)
}
log.Debugf("No function for: %v(%T)", name, x)
return nil
}
func RegisterFunctionCallback(name string, x_type int, fun TCGenericFunction) {
fname := fmt.Sprintf("fun.%v.%v", name, x_type)
Callbacks.Delete(fname)
Callbacks.Store(fname, fun)
}