globalaux.nim 258 B

12345678910111213141516
  1. type
  2. TObj*[T] = object
  3. val*: T
  4. var
  5. totalGlobals* = 0
  6. proc makeObj[T](x: T): TObj[T] =
  7. totalGlobals += 1
  8. result.val = x
  9. proc globalInstance*[T]: var TObj[T] =
  10. var g {.global.} = when T is int: makeObj(10) else: makeObj("hello")
  11. result = g