about summary refs log blame commit diff stats
path: root/src/js/typeptr.nim
blob: 0d5c4deb55d4f4115470f546d8628430d0f1a258 (plain) (tree)


















                                                                      
# Get a unique pointer for each type.
proc getTypePtr*[T](x: T): pointer =
  when T is RootRef:
    # I'm so sorry.
    # (This dereferences the object's first member, m_type. Probably.)
    return cast[ptr pointer](x)[]
  elif T is RootObj:
    return cast[pointer](x)
  else:
    return getTypeInfo(x)

func getTypePtr*(t: typedesc[ref object]): pointer =
  var x: t
  new(x)
  return getTypePtr(x)

func getTypePtr*(t: type): pointer =
  var x: t
  return getTypePtr(x)