summary refs log tree commit diff stats
path: root/tests/global/globalaux.nim
blob: 951472695e534c33f9a5724e68ba50318f7f86d9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
type
  TObj*[T] = object
    val*: T

var
  totalGlobals* = 0

proc makeObj[T](x: T): TObj[T] =
  totalGlobals += 1
  result.val = x

proc globalInstance*[T]: var TObj[T] =
  var g {.global.} = when T is int: makeObj(10) else: makeObj("hello")
  result = g