declarations.nut 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. static int32_t num32 = 32; //static is accepted but ignored
  2. static int32_t count32; //C/C++ style declarations
  3. print(num32, count32);
  4. int32_t doIt(int32_t a, char_t b) //C/C++ style declarations
  5. {
  6. static int32_t i =0; //static is accepted but ignored, inside functions a warning is emmited
  7. print("doIt", i, a, b);
  8. }
  9. doIt(3, "dad");
  10. void_t sleepOnly(uint16_t sec)
  11. {
  12. print("sleeping", sec);
  13. }
  14. sleepOnly(12);
  15. class K
  16. {
  17. v1 = 0;
  18. v2 = 0;
  19. function f1(){}
  20. }
  21. struct Person //struct is handled internally as a class
  22. {
  23. int32_t age; //C/C++ style declarations
  24. string_t name;
  25. int32_t weight;
  26. };
  27. Person person;
  28. Person checkCredit(int64_t id)
  29. {
  30. Person p = Person();
  31. p.name = "Bert";
  32. return p;
  33. }
  34. print(checkCredit(12).name);
  35. class BaseVector {
  36. constructor(...)
  37. {
  38. if(vargv.len() >= 3) {
  39. x = vargv[0];
  40. y = vargv[1];
  41. z = vargv[2];
  42. }
  43. }
  44. x = 0;
  45. y = 0;
  46. z = 0;
  47. int32_t i32;
  48. }
  49. class Vector3 extends BaseVector {
  50. function _add(other)
  51. {
  52. if(other instanceof this.getclass())
  53. return ::Vector3(x+other.x,y+other.y,z+other.z);
  54. else
  55. throw "wrong parameter";
  56. }
  57. function Print()
  58. {
  59. ::print(x+","+y+","+z+"\n");
  60. }
  61. bool_t isEmpty()
  62. {
  63. return true;
  64. }
  65. }
  66. class Vector4 : public Vector3 //C/C++ style declarations
  67. {
  68. bool_t isFull()
  69. {
  70. return false;
  71. }
  72. }
  73. local v0 = Vector3(1,2,3)
  74. local v1 = Vector3(11,12,13)
  75. local v2 = v0 + v1;
  76. v2.Print();
  77. print(v2.isEmpty());
  78. Vector4 v4 = Vector4();
  79. print(v4.isFull());
  80. FakeNamespace <- {
  81. Utils = {}
  82. }
  83. class FakeNamespace.Utils.SuperClass {
  84. constructor()
  85. {
  86. ::print("FakeNamespace.Utils.SuperClass")
  87. }
  88. }
  89. local testy = FakeNamespace.Utils.SuperClass();