mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-31 02:12:11 +00:00
16 lines
258 B
Nim
16 lines
258 B
Nim
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
|
|
|