Here are 2 ways
## Sol 1 - if you can get by with identifier input
proc fun1() = echo "ok1"
proc fun2() = echo "ok2"
template callfun(fun: untyped) =
fun()
## Sol 2 - if you really need string input
## This also unrolls the loop
import macros
const fns = [fun1, fun2]
macro callfun2(fun: string, listfunc: typed): untyped =
result = newStmtList()
echo listfunc.symbol.getImpl.treerepr
for function in listfunc.symbol.getImpl:
let f_str = $function
result.add quote do:
if `f_str` == `fun`:
`function`()
when isMainModule:
callfun(fun1)
callfun2("fun2", fns)