PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/lua/overload_template_fast_runme.lua

#
Lua | 81 lines | 47 code | 16 blank | 18 comment | 38 complexity | a480f39f10d7bd7394d59ecaf9cd514c MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. require("import") -- the import fn
  2. import("overload_template_fast") -- import code
  3. for k,v in pairs(overload_template_fast) do _G[k]=v end -- move to global
  4. -- lua has only one numeric type, so maximum(int,int) and maximum(double,double) are the same
  5. -- whichever one was wrapper first will be used (which is int)
  6. f = foo()
  7. a = maximum(3,4)
  8. -- mix 1
  9. assert(mix1("hi") == 101)
  10. assert(mix1(1.0, 1.0) == 102)
  11. assert(mix1(1.0) == 103)
  12. -- mix 2
  13. assert(mix2("hi") == 101)
  14. assert(mix2(1.0, 1.0) == 102)
  15. assert(mix2(1.0) == 103)
  16. -- mix 3
  17. assert(mix3("hi") == 101)
  18. assert(mix3(1.0, 1.0) == 102)
  19. assert(mix3(1.0) == 103)
  20. -- Combination 1
  21. assert(overtparams1(100) == 10)
  22. assert(overtparams1(100.0, 100) == 20)
  23. -- Combination 2
  24. assert(overtparams2(100.0, 100) == 40)
  25. -- Combination 3
  26. assert(overloaded() == 60)
  27. assert(overloaded(100.0, 100) == 70)
  28. -- Combination 4
  29. assert(overloadedagain("hello") == 80)
  30. assert(overloadedagain() == 90)
  31. -- specializations
  32. assert(specialization(10) == 202 or specialization(10.0) == 203) -- only one works
  33. assert(specialization(10, 10) == 204 or specialization(10.0, 10.0) == 205) -- ditto
  34. assert(specialization("hi", "hi") == 201)
  35. -- simple specialization
  36. xyz()
  37. xyz_int()
  38. xyz_double()
  39. -- a bit of everything
  40. assert(overload("hi") == 0)
  41. assert(overload(1) == 10)
  42. assert(overload(1, 1) == 20)
  43. assert(overload(1, "hello") == 30)
  44. k = Klass()
  45. assert(overload(k) == 10)
  46. assert(overload(k, k) == 20)
  47. assert(overload(k, "hello") == 30)
  48. -- this one is incorrect: it mactches overload(10.0, "hi") with int overload(T t, const char *c)
  49. --print(overload(10.0, "hi"))
  50. --assert(overload(10.0, "hi") == 40)
  51. assert(overload() == 50)
  52. -- everything put in a namespace
  53. assert(nsoverload("hi") == 1000,"nsoverload()")
  54. assert(nsoverload(1) == 1010,"nsoverload(int t)")
  55. assert(nsoverload(1, 1) == 1020,"nsoverload(int t, const int &)")
  56. assert(nsoverload(1, "hello") == 1030,"nsoverload(int t, const char *)")
  57. assert(nsoverload(k) == 1010,"nsoverload(Klass t)")
  58. assert(nsoverload(k, k) == 1020,"nsoverload(Klass t, const Klass &)")
  59. assert(nsoverload(k, "hello") == 1030,"nsoverload(Klass t, const char *)")
  60. -- again this one fails
  61. --assert(nsoverload(10.0, "hi") == 1040,"nsoverload(double t, const char *)")
  62. assert(nsoverload() == 1050,"nsoverload(const char *)")
  63. A_foo(1)
  64. b = B()
  65. b:foo(1)