Vector2i.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #include "precompiled.h"
  2. #include "Vector2i.h"
  3. namespace Rocket {
  4. namespace Core {
  5. namespace Lua {
  6. int Vector2inew(lua_State* L)
  7. {
  8. int x = luaL_checkint(L,1);
  9. int y = luaL_checkint(L,2);
  10. Vector2i* vect = new Vector2i(x,y);
  11. LuaType<Vector2i>::push(L,vect,true); //true means it will be deleted when it is garbage collected
  12. return 1;
  13. }
  14. int Vector2i__mul(lua_State* L)
  15. {
  16. Vector2i* lhs = LuaType<Vector2i>::check(L,1);
  17. LUACHECKOBJ(lhs);
  18. int rhs = luaL_checkint(L,2);
  19. Vector2i* res = new Vector2i(*lhs);
  20. (*res) *= rhs;
  21. LuaType<Vector2i>::push(L,res,true);
  22. return 1;
  23. }
  24. int Vector2i__div(lua_State* L)
  25. {
  26. Vector2i* lhs = LuaType<Vector2i>::check(L,1);
  27. LUACHECKOBJ(lhs);
  28. int rhs = luaL_checkint(L,2);
  29. Vector2i* res = new Vector2i(*lhs);
  30. (*res) /= rhs;
  31. LuaType<Vector2i>::push(L,res,true);
  32. return 1;
  33. }
  34. int Vector2i__add(lua_State* L)
  35. {
  36. Vector2i* lhs = LuaType<Vector2i>::check(L,1);
  37. LUACHECKOBJ(lhs);
  38. Vector2i* rhs = LuaType<Vector2i>::check(L,2);
  39. LUACHECKOBJ(rhs);
  40. Vector2i* res = new Vector2i(*lhs);
  41. (*res) += (*rhs);
  42. LuaType<Vector2i>::push(L,res,true);
  43. return 1;
  44. }
  45. int Vector2i__sub(lua_State* L)
  46. {
  47. Vector2i* lhs = LuaType<Vector2i>::check(L,1);
  48. LUACHECKOBJ(lhs);
  49. Vector2i* rhs = LuaType<Vector2i>::check(L,2);
  50. LUACHECKOBJ(rhs);
  51. Vector2i* res = new Vector2i(*lhs);
  52. (*res) -= (*rhs);
  53. LuaType<Vector2i>::push(L,res,true);
  54. return 1;
  55. }
  56. int Vector2i__eq(lua_State* L)
  57. {
  58. Vector2i* lhs = LuaType<Vector2i>::check(L,1);
  59. LUACHECKOBJ(lhs);
  60. Vector2i* rhs = LuaType<Vector2i>::check(L,2);
  61. LUACHECKOBJ(rhs);
  62. lua_pushboolean(L, (*lhs) == (*rhs) ? 1 : 0);
  63. return 1;
  64. }
  65. int Vector2iGetAttrx(lua_State*L)
  66. {
  67. Vector2i* self = LuaType<Vector2i>::check(L,1);
  68. LUACHECKOBJ(self);
  69. lua_pushinteger(L,self->x);
  70. return 1;
  71. }
  72. int Vector2iGetAttry(lua_State*L)
  73. {
  74. Vector2i* self = LuaType<Vector2i>::check(L,1);
  75. LUACHECKOBJ(self);
  76. lua_pushinteger(L,self->y);
  77. return 1;
  78. }
  79. int Vector2iGetAttrmagnitude(lua_State*L)
  80. {
  81. Vector2i* self = LuaType<Vector2i>::check(L,1);
  82. LUACHECKOBJ(self);
  83. lua_pushnumber(L,self->Magnitude());
  84. return 1;
  85. }
  86. int Vector2iSetAttrx(lua_State*L)
  87. {
  88. Vector2i* self = LuaType<Vector2i>::check(L,1);
  89. LUACHECKOBJ(self);
  90. int value = luaL_checkint(L,2);
  91. self->x = value;
  92. return 0;
  93. }
  94. int Vector2iSetAttry(lua_State*L)
  95. {
  96. Vector2i* self = LuaType<Vector2i>::check(L,1);
  97. LUACHECKOBJ(self);
  98. int value = luaL_checkint(L,2);
  99. self->y = value;
  100. return 0;
  101. }
  102. RegType<Vector2i> Vector2iMethods[] =
  103. {
  104. { NULL, NULL },
  105. };
  106. luaL_reg Vector2iGetters[]=
  107. {
  108. LUAGETTER(Vector2i,x)
  109. LUAGETTER(Vector2i,y)
  110. LUAGETTER(Vector2i,magnitude)
  111. { NULL, NULL },
  112. };
  113. luaL_reg Vector2iSetters[]=
  114. {
  115. LUASETTER(Vector2i,x)
  116. LUASETTER(Vector2i,y)
  117. { NULL, NULL },
  118. };
  119. }
  120. }
  121. }