How can I make macro that works when used as pragma to also work if used as plain call?
Please note that it has to be untyped
as for some reason I can't use typed
macro.
import macros
proc fn_signature(fn: NimNode): string =
let fn_impl = case fn.kind
of nnk_ident: fn.get_impl
of nnk_proc_def: fn
else: return "invalid usage"
fn_impl.tree_repr()
macro fn_signature_macro(fn: untyped) =
echo fn.fn_signature
proc a: string {.fn_signature_macro.} = ""
fn_signature_macro a
Error:
stack trace: (most recent call last)
/usercode/in.nim(12, 10) fn_signature_macro
/usercode/in.nim(5, 22) fn_signature
/usercode/in.nim(15, 20) template/generic instantiation of `fn_signature_macro` from here
/usercode/in.nim(5, 22) Error: node is not a symbol