Skip to content

Instantly share code, notes, and snippets.

@Yardanico
Last active October 21, 2017 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yardanico/7b961cbeb5c8d797e5f4ecf80ff639b0 to your computer and use it in GitHub Desktop.
Save Yardanico/7b961cbeb5c8d797e5f4ecf80ff639b0 to your computer and use it in GitHub Desktop.
import macros, tables
macro echoType(x: typed): untyped =
let impl = x.symbol.getImpl()
# we're called on some type
if impl.kind == nnkTypeDef:
echo "type ", toStrLit(impl)
# we're called on a variable
else:
echo "type ", impl.getTypeInst(), " = ", toStrLit(impl.getTypeImpl())
type
MyObj = object
x: int
echoType(MyObj)
let a = MyObj(x: 5)
echoType(a)
@perpetual-hydrofoil
Copy link

perpetual-hydrofoil commented Oct 21, 2017

Excellent!!

@perpetual-hydrofoil
Copy link

perpetual-hydrofoil commented Oct 21, 2017

Now I get: type Response = ref Response:ObjectType .. I guess it's surprisingly hard to see the attributes of Response at runtime!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment