tconvert.nim 791 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. converter FloatConversion64(x: int): float64 = return toFloat(x)
  2. converter FloatConversion32(x: int): float32 = return toFloat(x)
  3. converter FloatConversionPlain(x: int): float = return toFloat(x)
  4. const width = 500
  5. const height = 500
  6. proc ImageSurfaceCreate(w, h: float) = discard
  7. ImageSurfaceCreate(width, height)
  8. type TFoo = object
  9. converter toPtr*(some: var TFoo): ptr TFoo = (addr some)
  10. proc zoot(x: ptr TFoo) = discard
  11. var x: Tfoo
  12. zoot(x)
  13. # issue #6544
  14. converter withVar(b: var string): int = ord(b[1])
  15. block:
  16. var x = "101"
  17. var y: int = x # instantiate withVar
  18. doAssert(y == ord('0'))
  19. ######################
  20. # bug #3503
  21. type Foo = object
  22. r: float
  23. converter toFoo(r: float): Foo =
  24. result.r = r
  25. proc `+=`*(x: var Foo, r: float) =
  26. x.r += r
  27. var a: Foo
  28. a.r += 3.0