wrap_Source.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /**
  2. * Copyright (c) 2006-2010 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. #include "wrap_Source.h"
  21. namespace love
  22. {
  23. namespace audio
  24. {
  25. Source * luax_checksource(lua_State * L, int idx)
  26. {
  27. return luax_checktype<Source>(L, idx, "Source", AUDIO_SOURCE_T);
  28. }
  29. int w_Source_play(lua_State * L)
  30. {
  31. Source * t = luax_checksource(L, 1);
  32. t->play();
  33. return 0;
  34. }
  35. int w_Source_stop(lua_State * L)
  36. {
  37. Source * t = luax_checksource(L, 1);
  38. t->stop();
  39. return 0;
  40. }
  41. int w_Source_pause(lua_State * L)
  42. {
  43. Source * t = luax_checksource(L, 1);
  44. t->pause();
  45. return 0;
  46. }
  47. int w_Source_resume(lua_State * L)
  48. {
  49. Source * t = luax_checksource(L, 1);
  50. t->resume();
  51. return 0;
  52. }
  53. int w_Source_rewind(lua_State * L)
  54. {
  55. Source * t = luax_checksource(L, 1);
  56. t->rewind();
  57. return 0;
  58. }
  59. int w_Source_setPitch(lua_State * L)
  60. {
  61. Source * t = luax_checksource(L, 1);
  62. float p = (float)luaL_checknumber(L, 2);
  63. t->setPitch(p);
  64. return 0;
  65. }
  66. int w_Source_getPitch(lua_State * L)
  67. {
  68. Source * t = luax_checksource(L, 1);
  69. lua_pushnumber(L, t->getPitch());
  70. return 1;
  71. }
  72. int w_Source_setVolume(lua_State * L)
  73. {
  74. Source * t = luax_checksource(L, 1);
  75. float p = (float)luaL_checknumber(L, 2);
  76. t->setVolume(p);
  77. return 0;
  78. }
  79. int w_Source_getVolume(lua_State * L)
  80. {
  81. Source * t = luax_checksource(L, 1);
  82. lua_pushnumber(L, t->getVolume());
  83. return 1;
  84. }
  85. int w_Source_setPosition(lua_State * L)
  86. {
  87. Source * t = luax_checksource(L, 1);
  88. float v[3];
  89. v[0] = (float)luaL_checknumber(L, 2);
  90. v[1] = (float)luaL_checknumber(L, 3);
  91. v[2] = (float)luaL_checknumber(L, 4);
  92. t->setPosition(v);
  93. return 0;
  94. }
  95. int w_Source_getPosition(lua_State * L)
  96. {
  97. Source * t = luax_checksource(L, 1);
  98. float v[3];
  99. t->getPosition(v);
  100. lua_pushnumber(L, v[0]);
  101. lua_pushnumber(L, v[1]);
  102. lua_pushnumber(L, v[2]);
  103. return 3;
  104. }
  105. int w_Source_setVelocity(lua_State * L)
  106. {
  107. Source * t = luax_checksource(L, 1);
  108. float v[3];
  109. v[0] = (float)luaL_checknumber(L, 2);
  110. v[1] = (float)luaL_checknumber(L, 3);
  111. v[2] = (float)luaL_checknumber(L, 4);
  112. t->setVelocity(v);
  113. return 0;
  114. }
  115. int w_Source_getVelocity(lua_State * L)
  116. {
  117. Source * t = luax_checksource(L, 1);
  118. float v[3];
  119. t->getVelocity(v);
  120. lua_pushnumber(L, v[0]);
  121. lua_pushnumber(L, v[1]);
  122. lua_pushnumber(L, v[2]);
  123. return 3;
  124. }
  125. int w_Source_setDirection(lua_State * L)
  126. {
  127. Source * t = luax_checksource(L, 1);
  128. float v[3];
  129. v[0] = (float)luaL_checknumber(L, 2);
  130. v[1] = (float)luaL_checknumber(L, 3);
  131. v[2] = (float)luaL_checknumber(L, 4);
  132. t->setDirection(v);
  133. return 0;
  134. }
  135. int w_Source_getDirection(lua_State * L)
  136. {
  137. Source * t = luax_checksource(L, 1);
  138. float v[3];
  139. t->getDirection(v);
  140. lua_pushnumber(L, v[0]);
  141. lua_pushnumber(L, v[1]);
  142. lua_pushnumber(L, v[2]);
  143. return 3;
  144. }
  145. int w_Source_setLooping(lua_State * L)
  146. {
  147. Source * t = luax_checksource(L, 1);
  148. t->setLooping(luax_toboolean(L, 2));
  149. return 0;
  150. }
  151. int w_Source_isLooping(lua_State * L)
  152. {
  153. Source * t = luax_checksource(L, 1);
  154. luax_pushboolean(L, t->isLooping());
  155. return 1;
  156. }
  157. int w_Source_isStopped(lua_State * L)
  158. {
  159. Source * t = luax_checksource(L, 1);
  160. luax_pushboolean(L, t->isStopped());
  161. return 1;
  162. }
  163. int w_Source_isStatic(lua_State * L)
  164. {
  165. Source * t= luax_checksource(L, 1);
  166. luax_pushboolean(L, t->isStatic());
  167. return 1;
  168. }
  169. static const luaL_Reg functions[] = {
  170. { "play", w_Source_play },
  171. { "stop", w_Source_stop },
  172. { "pause", w_Source_pause },
  173. { "resume", w_Source_resume },
  174. { "rewind", w_Source_rewind },
  175. { "setPitch", w_Source_setPitch },
  176. { "getPitch", w_Source_getPitch },
  177. { "setVolume", w_Source_setVolume },
  178. { "getVolume", w_Source_getVolume },
  179. { "setPosition", w_Source_setPosition },
  180. { "getPosition", w_Source_getPosition },
  181. { "setVelocity", w_Source_setVelocity },
  182. { "getVelocity", w_Source_getVelocity },
  183. { "setDirection", w_Source_setDirection },
  184. { "getDirection", w_Source_getDirection },
  185. { "setLooping", w_Source_setLooping },
  186. { "isLooping", w_Source_isLooping },
  187. { "isStopped", w_Source_isStopped },
  188. { "isStatic", w_Source_isStatic },
  189. { 0, 0 }
  190. };
  191. int luaopen_source(lua_State * L)
  192. {
  193. return luax_register_type(L, "Source", functions);
  194. }
  195. } // audio
  196. } // love