Vector2i.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #include "precompiled.h"
  2. #include "Vector2i.h"
  3. namespace Rocket {
  4. namespace Core {
  5. namespace Lua {
  6. int Vector2i__call(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. int rhs = luaL_checkint(L,2);
  18. Vector2i* res = new Vector2i(*lhs);
  19. (*res) *= rhs;
  20. LuaType<Vector2i>::push(L,res,true);
  21. return 1;
  22. }
  23. int Vector2i__div(lua_State* L)
  24. {
  25. Vector2i* lhs = LuaType<Vector2i>::check(L,1);
  26. int rhs = luaL_checkint(L,2);
  27. Vector2i* res = new Vector2i(*lhs);
  28. (*res) /= rhs;
  29. LuaType<Vector2i>::push(L,res,true);
  30. return 1;
  31. }
  32. int Vector2i__add(lua_State* L)
  33. {
  34. Vector2i* lhs = LuaType<Vector2i>::check(L,1);
  35. Vector2i* rhs = LuaType<Vector2i>::check(L,1);
  36. Vector2i* res = new Vector2i(*lhs);
  37. (*res) += (*rhs);
  38. LuaType<Vector2i>::push(L,res,true);
  39. return 1;
  40. }
  41. int Vector2i__sub(lua_State* L)
  42. {
  43. Vector2i* lhs = LuaType<Vector2i>::check(L,1);
  44. Vector2i* rhs = LuaType<Vector2i>::check(L,1);
  45. Vector2i* res = new Vector2i(*lhs);
  46. (*res) -= (*rhs);
  47. LuaType<Vector2i>::push(L,res,true);
  48. return 1;
  49. }
  50. int Vector2i__eq(lua_State* L)
  51. {
  52. Vector2i* lhs = LuaType<Vector2i>::check(L,1);
  53. Vector2i* rhs = LuaType<Vector2i>::check(L,1);
  54. lua_pushboolean(L, (*lhs) == (*rhs) ? 1 : 0);
  55. return 1;
  56. }
  57. int Vector2iGetAttrx(lua_State*L)
  58. {
  59. Vector2i* self = LuaType<Vector2i>::check(L,1);
  60. lua_pushinteger(L,self->x);
  61. return 1;
  62. }
  63. int Vector2iGetAttry(lua_State*L)
  64. {
  65. Vector2i* self = LuaType<Vector2i>::check(L,1);
  66. lua_pushinteger(L,self->y);
  67. return 1;
  68. }
  69. int Vector2iGetAttrmagnitude(lua_State*L)
  70. {
  71. Vector2i* self = LuaType<Vector2i>::check(L,1);
  72. lua_pushnumber(L,self->Magnitude());
  73. return 1;
  74. }
  75. int Vector2iSetAttrx(lua_State*L)
  76. {
  77. Vector2i* self = LuaType<Vector2i>::check(L,1);
  78. int value = luaL_checkint(L,2);
  79. self->x = value;
  80. return 0;
  81. }
  82. int Vector2iSetAttry(lua_State*L)
  83. {
  84. Vector2i* self = LuaType<Vector2i>::check(L,1);
  85. int value = luaL_checkint(L,2);
  86. self->y = value;
  87. return 0;
  88. }
  89. RegType<Vector2i> Vector2iMethods[] =
  90. {
  91. { NULL, NULL },
  92. };
  93. luaL_reg Vector2iGetters[]=
  94. {
  95. LUAGETTER(Vector2i,x)
  96. LUAGETTER(Vector2i,y)
  97. LUAGETTER(Vector2i,magnitude)
  98. { NULL, NULL },
  99. };
  100. luaL_reg Vector2iSetters[]=
  101. {
  102. LUASETTER(Vector2i,x)
  103. LUASETTER(Vector2i,y)
  104. { NULL, NULL },
  105. };
  106. }
  107. }
  108. }