Thank you guys! I stayed with templates, don't know why I didn't use them from the beginning.
But typedesc[T] is really, really evil and black magic:
proc getMutableVal[T](key: int, desc: typedesc[T]): var T =
getTableOf(T)[key]
