wrap_Source.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /**
  2. * Copyright (c) 2006-2009 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_setPitch(lua_State * L)
  30. {
  31. Source * t = luax_checksource(L, 1);
  32. float p = (float)luaL_checknumber(L, 2);
  33. t->setPitch(p);
  34. return 0;
  35. }
  36. int w_Source_getPitch(lua_State * L)
  37. {
  38. Source * t = luax_checksource(L, 1);
  39. lua_pushnumber(L, t->getPitch());
  40. return 1;
  41. }
  42. int w_Source_setVolume(lua_State * L)
  43. {
  44. Source * t = luax_checksource(L, 1);
  45. float p = (float)luaL_checknumber(L, 2);
  46. t->setVolume(p);
  47. return 0;
  48. }
  49. int w_Source_getVolume(lua_State * L)
  50. {
  51. Source * t = luax_checksource(L, 1);
  52. lua_pushnumber(L, t->getVolume());
  53. return 1;
  54. }
  55. int w_Source_setPosition(lua_State * L)
  56. {
  57. Source * t = luax_checksource(L, 1);
  58. float v[3];
  59. v[0] = (float)luaL_checknumber(L, 2);
  60. v[1] = (float)luaL_checknumber(L, 3);
  61. v[2] = (float)luaL_checknumber(L, 4);
  62. t->setPosition(v);
  63. return 0;
  64. }
  65. int w_Source_getPosition(lua_State * L)
  66. {
  67. Source * t = luax_checksource(L, 1);
  68. float v[3];
  69. t->getPosition(v);
  70. lua_pushnumber(L, v[0]);
  71. lua_pushnumber(L, v[1]);
  72. lua_pushnumber(L, v[2]);
  73. return 3;
  74. }
  75. int w_Source_setVelocity(lua_State * L)
  76. {
  77. Source * t = luax_checksource(L, 1);
  78. float v[3];
  79. v[0] = (float)luaL_checknumber(L, 2);
  80. v[1] = (float)luaL_checknumber(L, 3);
  81. v[2] = (float)luaL_checknumber(L, 4);
  82. t->setVelocity(v);
  83. return 0;
  84. }
  85. int w_Source_getVelocity(lua_State * L)
  86. {
  87. Source * t = luax_checksource(L, 1);
  88. float v[3];
  89. t->getVelocity(v);
  90. lua_pushnumber(L, v[0]);
  91. lua_pushnumber(L, v[1]);
  92. lua_pushnumber(L, v[2]);
  93. return 3;
  94. }
  95. int w_Source_setDirection(lua_State * L)
  96. {
  97. Source * t = luax_checksource(L, 1);
  98. float v[3];
  99. v[0] = (float)luaL_checknumber(L, 2);
  100. v[1] = (float)luaL_checknumber(L, 3);
  101. v[2] = (float)luaL_checknumber(L, 4);
  102. t->setDirection(v);
  103. return 0;
  104. }
  105. int w_Source_getDirection(lua_State * L)
  106. {
  107. Source * t = luax_checksource(L, 1);
  108. float v[3];
  109. t->getDirection(v);
  110. lua_pushnumber(L, v[0]);
  111. lua_pushnumber(L, v[1]);
  112. lua_pushnumber(L, v[2]);
  113. return 3;
  114. }
  115. int w_Source_setLooping(lua_State * L)
  116. {
  117. Source * t = luax_checksource(L, 1);
  118. t->setLooping(luax_toboolean(L, 2));
  119. return 0;
  120. }
  121. int w_Source_isLooping(lua_State * L)
  122. {
  123. Source * t = luax_checksource(L, 1);
  124. luax_pushboolean(L, t->isLooping());
  125. return 1;
  126. }
  127. int luaopen_source(lua_State * L)
  128. {
  129. static const luaL_Reg functions[] = {
  130. { "setPitch", w_Source_setPitch },
  131. { "getPitch", w_Source_getPitch },
  132. { "setVolume", w_Source_setVolume },
  133. { "getVolume", w_Source_getVolume },
  134. { "setLooping", w_Source_setLooping },
  135. { "isLooping", w_Source_isLooping },
  136. { 0, 0 }
  137. };
  138. return luax_register_type(L, "Source", functions);
  139. }
  140. } // audio
  141. } // love