[EDIT] Well, does not even work correctly, expected result would be "times.DateTime". "When compiles()" give the same.
import times, macros
macro m(o: typed): untyped =
#let ot = getType(o)
let oti = getTypeInst(o)
#let s1 = $ot.toStrLit
let s2 = $oti.toStrLit
#echo s1
echo s2
if compiles("var h:" & "tables." & s2):
echo "tables." & s2
elif compiles("var h:" & "times." & s2):
echo "times." & s2
var x: times.DateTime
m(x)
DateTime
tables.DateTime
Why I may need the module? Well, some months ago someone asked if we can use GtkBuilder with gintro. Answer is yes of course, but to make it typesafe we would have to create a macro which tests type of result from Builder.getObject(). In most cases module will be gtk, but not always. For example, if we pass a var of type Button, we would have to check if result returned by Builder.getObject() is GtkButton. (https://developer.gnome.org/gtk3/stable/ch01s03.html)
compiles takes an expression argument, not a string argument. I myself don't know a way to do this other than to do something like:
import macros, times, tables
macro m(o: typed): untyped =
let oti = getTypeInst(o)
let s2 = oti.toStrLit.strVal
let s2ident = newIdentNode(s2)
echo s2
result = quote do:
when declared(tables.`s2ident`):
static: echo "tables.", `s2`
elif declared(times.`s2ident`):
static: echo "times.", `s2`
var x: times.DateTime
m(x)