Vector2i.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #include "precompiled.h"
  28. #include "Vector2i.h"
  29. namespace Rocket {
  30. namespace Core {
  31. namespace Lua {
  32. int Vector2inew(lua_State* L)
  33. {
  34. int x = luaL_checkint(L,1);
  35. int y = luaL_checkint(L,2);
  36. Vector2i* vect = new Vector2i(x,y);
  37. LuaType<Vector2i>::push(L,vect,true); //true means it will be deleted when it is garbage collected
  38. return 1;
  39. }
  40. int Vector2i__mul(lua_State* L)
  41. {
  42. Vector2i* lhs = LuaType<Vector2i>::check(L,1);
  43. LUACHECKOBJ(lhs);
  44. int rhs = luaL_checkint(L,2);
  45. Vector2i* res = new Vector2i(*lhs);
  46. (*res) *= rhs;
  47. LuaType<Vector2i>::push(L,res,true);
  48. return 1;
  49. }
  50. int Vector2i__div(lua_State* L)
  51. {
  52. Vector2i* lhs = LuaType<Vector2i>::check(L,1);
  53. LUACHECKOBJ(lhs);
  54. int rhs = luaL_checkint(L,2);
  55. Vector2i* res = new Vector2i(*lhs);
  56. (*res) /= rhs;
  57. LuaType<Vector2i>::push(L,res,true);
  58. return 1;
  59. }
  60. int Vector2i__add(lua_State* L)
  61. {
  62. Vector2i* lhs = LuaType<Vector2i>::check(L,1);
  63. LUACHECKOBJ(lhs);
  64. Vector2i* rhs = LuaType<Vector2i>::check(L,2);
  65. LUACHECKOBJ(rhs);
  66. Vector2i* res = new Vector2i(*lhs);
  67. (*res) += (*rhs);
  68. LuaType<Vector2i>::push(L,res,true);
  69. return 1;
  70. }
  71. int Vector2i__sub(lua_State* L)
  72. {
  73. Vector2i* lhs = LuaType<Vector2i>::check(L,1);
  74. LUACHECKOBJ(lhs);
  75. Vector2i* rhs = LuaType<Vector2i>::check(L,2);
  76. LUACHECKOBJ(rhs);
  77. Vector2i* res = new Vector2i(*lhs);
  78. (*res) -= (*rhs);
  79. LuaType<Vector2i>::push(L,res,true);
  80. return 1;
  81. }
  82. int Vector2i__eq(lua_State* L)
  83. {
  84. Vector2i* lhs = LuaType<Vector2i>::check(L,1);
  85. LUACHECKOBJ(lhs);
  86. Vector2i* rhs = LuaType<Vector2i>::check(L,2);
  87. LUACHECKOBJ(rhs);
  88. lua_pushboolean(L, (*lhs) == (*rhs) ? 1 : 0);
  89. return 1;
  90. }
  91. int Vector2iGetAttrx(lua_State*L)
  92. {
  93. Vector2i* self = LuaType<Vector2i>::check(L,1);
  94. LUACHECKOBJ(self);
  95. lua_pushinteger(L,self->x);
  96. return 1;
  97. }
  98. int Vector2iGetAttry(lua_State*L)
  99. {
  100. Vector2i* self = LuaType<Vector2i>::check(L,1);
  101. LUACHECKOBJ(self);
  102. lua_pushinteger(L,self->y);
  103. return 1;
  104. }
  105. int Vector2iGetAttrmagnitude(lua_State*L)
  106. {
  107. Vector2i* self = LuaType<Vector2i>::check(L,1);
  108. LUACHECKOBJ(self);
  109. lua_pushnumber(L,self->Magnitude());
  110. return 1;
  111. }
  112. int Vector2iSetAttrx(lua_State*L)
  113. {
  114. Vector2i* self = LuaType<Vector2i>::check(L,1);
  115. LUACHECKOBJ(self);
  116. int value = luaL_checkint(L,2);
  117. self->x = value;
  118. return 0;
  119. }
  120. int Vector2iSetAttry(lua_State*L)
  121. {
  122. Vector2i* self = LuaType<Vector2i>::check(L,1);
  123. LUACHECKOBJ(self);
  124. int value = luaL_checkint(L,2);
  125. self->y = value;
  126. return 0;
  127. }
  128. RegType<Vector2i> Vector2iMethods[] =
  129. {
  130. { NULL, NULL },
  131. };
  132. luaL_reg Vector2iGetters[]=
  133. {
  134. LUAGETTER(Vector2i,x)
  135. LUAGETTER(Vector2i,y)
  136. LUAGETTER(Vector2i,magnitude)
  137. { NULL, NULL },
  138. };
  139. luaL_reg Vector2iSetters[]=
  140. {
  141. LUASETTER(Vector2i,x)
  142. LUASETTER(Vector2i,y)
  143. { NULL, NULL },
  144. };
  145. }
  146. }
  147. }