lua_AudioSource.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_AudioSource.h"
  4. #include "Animation.h"
  5. #include "AnimationTarget.h"
  6. #include "AudioBuffer.h"
  7. #include "AudioController.h"
  8. #include "AudioSource.h"
  9. #include "Base.h"
  10. #include "Game.h"
  11. #include "Node.h"
  12. #include "Ref.h"
  13. #include "ScriptController.h"
  14. #include "ScriptTarget.h"
  15. #include "Transform.h"
  16. #include "lua_AudioSourceState.h"
  17. #include "lua_CurveInterpolationType.h"
  18. namespace gameplay
  19. {
  20. void luaRegister_AudioSource()
  21. {
  22. const luaL_Reg lua_members[] =
  23. {
  24. {"addRef", lua_AudioSource_addRef},
  25. {"getGain", lua_AudioSource_getGain},
  26. {"getNode", lua_AudioSource_getNode},
  27. {"getPitch", lua_AudioSource_getPitch},
  28. {"getRefCount", lua_AudioSource_getRefCount},
  29. {"getState", lua_AudioSource_getState},
  30. {"getVelocity", lua_AudioSource_getVelocity},
  31. {"isLooped", lua_AudioSource_isLooped},
  32. {"pause", lua_AudioSource_pause},
  33. {"play", lua_AudioSource_play},
  34. {"release", lua_AudioSource_release},
  35. {"resume", lua_AudioSource_resume},
  36. {"rewind", lua_AudioSource_rewind},
  37. {"setGain", lua_AudioSource_setGain},
  38. {"setLooped", lua_AudioSource_setLooped},
  39. {"setPitch", lua_AudioSource_setPitch},
  40. {"setVelocity", lua_AudioSource_setVelocity},
  41. {"stop", lua_AudioSource_stop},
  42. {NULL, NULL}
  43. };
  44. const luaL_Reg lua_statics[] =
  45. {
  46. {"create", lua_AudioSource_static_create},
  47. {NULL, NULL}
  48. };
  49. std::vector<std::string> scopePath;
  50. ScriptUtil::registerClass("AudioSource", lua_members, NULL, lua_AudioSource__gc, lua_statics, scopePath);
  51. }
  52. static AudioSource* getInstance(lua_State* state)
  53. {
  54. void* userdata = luaL_checkudata(state, 1, "AudioSource");
  55. luaL_argcheck(state, userdata != NULL, 1, "'AudioSource' expected.");
  56. return (AudioSource*)((ScriptUtil::LuaObject*)userdata)->instance;
  57. }
  58. int lua_AudioSource__gc(lua_State* state)
  59. {
  60. // Get the number of parameters.
  61. int paramCount = lua_gettop(state);
  62. // Attempt to match the parameters to a valid binding.
  63. switch (paramCount)
  64. {
  65. case 1:
  66. {
  67. if ((lua_type(state, 1) == LUA_TUSERDATA))
  68. {
  69. void* userdata = luaL_checkudata(state, 1, "AudioSource");
  70. luaL_argcheck(state, userdata != NULL, 1, "'AudioSource' expected.");
  71. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  72. if (object->owns)
  73. {
  74. AudioSource* instance = (AudioSource*)object->instance;
  75. SAFE_RELEASE(instance);
  76. }
  77. return 0;
  78. }
  79. else
  80. {
  81. lua_pushstring(state, "lua_AudioSource__gc - Failed to match the given parameters to a valid function signature.");
  82. lua_error(state);
  83. }
  84. break;
  85. }
  86. default:
  87. {
  88. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  89. lua_error(state);
  90. break;
  91. }
  92. }
  93. return 0;
  94. }
  95. int lua_AudioSource_addRef(lua_State* state)
  96. {
  97. // Get the number of parameters.
  98. int paramCount = lua_gettop(state);
  99. // Attempt to match the parameters to a valid binding.
  100. switch (paramCount)
  101. {
  102. case 1:
  103. {
  104. if ((lua_type(state, 1) == LUA_TUSERDATA))
  105. {
  106. AudioSource* instance = getInstance(state);
  107. instance->addRef();
  108. return 0;
  109. }
  110. else
  111. {
  112. lua_pushstring(state, "lua_AudioSource_addRef - Failed to match the given parameters to a valid function signature.");
  113. lua_error(state);
  114. }
  115. break;
  116. }
  117. default:
  118. {
  119. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  120. lua_error(state);
  121. break;
  122. }
  123. }
  124. return 0;
  125. }
  126. int lua_AudioSource_getGain(lua_State* state)
  127. {
  128. // Get the number of parameters.
  129. int paramCount = lua_gettop(state);
  130. // Attempt to match the parameters to a valid binding.
  131. switch (paramCount)
  132. {
  133. case 1:
  134. {
  135. if ((lua_type(state, 1) == LUA_TUSERDATA))
  136. {
  137. AudioSource* instance = getInstance(state);
  138. float result = instance->getGain();
  139. // Push the return value onto the stack.
  140. lua_pushnumber(state, result);
  141. return 1;
  142. }
  143. else
  144. {
  145. lua_pushstring(state, "lua_AudioSource_getGain - Failed to match the given parameters to a valid function signature.");
  146. lua_error(state);
  147. }
  148. break;
  149. }
  150. default:
  151. {
  152. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  153. lua_error(state);
  154. break;
  155. }
  156. }
  157. return 0;
  158. }
  159. int lua_AudioSource_getNode(lua_State* state)
  160. {
  161. // Get the number of parameters.
  162. int paramCount = lua_gettop(state);
  163. // Attempt to match the parameters to a valid binding.
  164. switch (paramCount)
  165. {
  166. case 1:
  167. {
  168. if ((lua_type(state, 1) == LUA_TUSERDATA))
  169. {
  170. AudioSource* instance = getInstance(state);
  171. void* returnPtr = (void*)instance->getNode();
  172. if (returnPtr)
  173. {
  174. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  175. object->instance = returnPtr;
  176. object->owns = false;
  177. luaL_getmetatable(state, "Node");
  178. lua_setmetatable(state, -2);
  179. }
  180. else
  181. {
  182. lua_pushnil(state);
  183. }
  184. return 1;
  185. }
  186. else
  187. {
  188. lua_pushstring(state, "lua_AudioSource_getNode - Failed to match the given parameters to a valid function signature.");
  189. lua_error(state);
  190. }
  191. break;
  192. }
  193. default:
  194. {
  195. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  196. lua_error(state);
  197. break;
  198. }
  199. }
  200. return 0;
  201. }
  202. int lua_AudioSource_getPitch(lua_State* state)
  203. {
  204. // Get the number of parameters.
  205. int paramCount = lua_gettop(state);
  206. // Attempt to match the parameters to a valid binding.
  207. switch (paramCount)
  208. {
  209. case 1:
  210. {
  211. if ((lua_type(state, 1) == LUA_TUSERDATA))
  212. {
  213. AudioSource* instance = getInstance(state);
  214. float result = instance->getPitch();
  215. // Push the return value onto the stack.
  216. lua_pushnumber(state, result);
  217. return 1;
  218. }
  219. else
  220. {
  221. lua_pushstring(state, "lua_AudioSource_getPitch - Failed to match the given parameters to a valid function signature.");
  222. lua_error(state);
  223. }
  224. break;
  225. }
  226. default:
  227. {
  228. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  229. lua_error(state);
  230. break;
  231. }
  232. }
  233. return 0;
  234. }
  235. int lua_AudioSource_getRefCount(lua_State* state)
  236. {
  237. // Get the number of parameters.
  238. int paramCount = lua_gettop(state);
  239. // Attempt to match the parameters to a valid binding.
  240. switch (paramCount)
  241. {
  242. case 1:
  243. {
  244. if ((lua_type(state, 1) == LUA_TUSERDATA))
  245. {
  246. AudioSource* instance = getInstance(state);
  247. unsigned int result = instance->getRefCount();
  248. // Push the return value onto the stack.
  249. lua_pushunsigned(state, result);
  250. return 1;
  251. }
  252. else
  253. {
  254. lua_pushstring(state, "lua_AudioSource_getRefCount - Failed to match the given parameters to a valid function signature.");
  255. lua_error(state);
  256. }
  257. break;
  258. }
  259. default:
  260. {
  261. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  262. lua_error(state);
  263. break;
  264. }
  265. }
  266. return 0;
  267. }
  268. int lua_AudioSource_getState(lua_State* state)
  269. {
  270. // Get the number of parameters.
  271. int paramCount = lua_gettop(state);
  272. // Attempt to match the parameters to a valid binding.
  273. switch (paramCount)
  274. {
  275. case 1:
  276. {
  277. if ((lua_type(state, 1) == LUA_TUSERDATA))
  278. {
  279. AudioSource* instance = getInstance(state);
  280. AudioSource::State result = instance->getState();
  281. // Push the return value onto the stack.
  282. lua_pushstring(state, lua_stringFromEnum_AudioSourceState(result));
  283. return 1;
  284. }
  285. else
  286. {
  287. lua_pushstring(state, "lua_AudioSource_getState - Failed to match the given parameters to a valid function signature.");
  288. lua_error(state);
  289. }
  290. break;
  291. }
  292. default:
  293. {
  294. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  295. lua_error(state);
  296. break;
  297. }
  298. }
  299. return 0;
  300. }
  301. int lua_AudioSource_getVelocity(lua_State* state)
  302. {
  303. // Get the number of parameters.
  304. int paramCount = lua_gettop(state);
  305. // Attempt to match the parameters to a valid binding.
  306. switch (paramCount)
  307. {
  308. case 1:
  309. {
  310. if ((lua_type(state, 1) == LUA_TUSERDATA))
  311. {
  312. AudioSource* instance = getInstance(state);
  313. void* returnPtr = (void*)&(instance->getVelocity());
  314. if (returnPtr)
  315. {
  316. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  317. object->instance = returnPtr;
  318. object->owns = false;
  319. luaL_getmetatable(state, "Vector3");
  320. lua_setmetatable(state, -2);
  321. }
  322. else
  323. {
  324. lua_pushnil(state);
  325. }
  326. return 1;
  327. }
  328. else
  329. {
  330. lua_pushstring(state, "lua_AudioSource_getVelocity - Failed to match the given parameters to a valid function signature.");
  331. lua_error(state);
  332. }
  333. break;
  334. }
  335. default:
  336. {
  337. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  338. lua_error(state);
  339. break;
  340. }
  341. }
  342. return 0;
  343. }
  344. int lua_AudioSource_isLooped(lua_State* state)
  345. {
  346. // Get the number of parameters.
  347. int paramCount = lua_gettop(state);
  348. // Attempt to match the parameters to a valid binding.
  349. switch (paramCount)
  350. {
  351. case 1:
  352. {
  353. if ((lua_type(state, 1) == LUA_TUSERDATA))
  354. {
  355. AudioSource* instance = getInstance(state);
  356. bool result = instance->isLooped();
  357. // Push the return value onto the stack.
  358. lua_pushboolean(state, result);
  359. return 1;
  360. }
  361. else
  362. {
  363. lua_pushstring(state, "lua_AudioSource_isLooped - Failed to match the given parameters to a valid function signature.");
  364. lua_error(state);
  365. }
  366. break;
  367. }
  368. default:
  369. {
  370. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  371. lua_error(state);
  372. break;
  373. }
  374. }
  375. return 0;
  376. }
  377. int lua_AudioSource_pause(lua_State* state)
  378. {
  379. // Get the number of parameters.
  380. int paramCount = lua_gettop(state);
  381. // Attempt to match the parameters to a valid binding.
  382. switch (paramCount)
  383. {
  384. case 1:
  385. {
  386. if ((lua_type(state, 1) == LUA_TUSERDATA))
  387. {
  388. AudioSource* instance = getInstance(state);
  389. instance->pause();
  390. return 0;
  391. }
  392. else
  393. {
  394. lua_pushstring(state, "lua_AudioSource_pause - Failed to match the given parameters to a valid function signature.");
  395. lua_error(state);
  396. }
  397. break;
  398. }
  399. default:
  400. {
  401. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  402. lua_error(state);
  403. break;
  404. }
  405. }
  406. return 0;
  407. }
  408. int lua_AudioSource_play(lua_State* state)
  409. {
  410. // Get the number of parameters.
  411. int paramCount = lua_gettop(state);
  412. // Attempt to match the parameters to a valid binding.
  413. switch (paramCount)
  414. {
  415. case 1:
  416. {
  417. if ((lua_type(state, 1) == LUA_TUSERDATA))
  418. {
  419. AudioSource* instance = getInstance(state);
  420. instance->play();
  421. return 0;
  422. }
  423. else
  424. {
  425. lua_pushstring(state, "lua_AudioSource_play - Failed to match the given parameters to a valid function signature.");
  426. lua_error(state);
  427. }
  428. break;
  429. }
  430. default:
  431. {
  432. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  433. lua_error(state);
  434. break;
  435. }
  436. }
  437. return 0;
  438. }
  439. int lua_AudioSource_release(lua_State* state)
  440. {
  441. // Get the number of parameters.
  442. int paramCount = lua_gettop(state);
  443. // Attempt to match the parameters to a valid binding.
  444. switch (paramCount)
  445. {
  446. case 1:
  447. {
  448. if ((lua_type(state, 1) == LUA_TUSERDATA))
  449. {
  450. AudioSource* instance = getInstance(state);
  451. instance->release();
  452. return 0;
  453. }
  454. else
  455. {
  456. lua_pushstring(state, "lua_AudioSource_release - Failed to match the given parameters to a valid function signature.");
  457. lua_error(state);
  458. }
  459. break;
  460. }
  461. default:
  462. {
  463. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  464. lua_error(state);
  465. break;
  466. }
  467. }
  468. return 0;
  469. }
  470. int lua_AudioSource_resume(lua_State* state)
  471. {
  472. // Get the number of parameters.
  473. int paramCount = lua_gettop(state);
  474. // Attempt to match the parameters to a valid binding.
  475. switch (paramCount)
  476. {
  477. case 1:
  478. {
  479. if ((lua_type(state, 1) == LUA_TUSERDATA))
  480. {
  481. AudioSource* instance = getInstance(state);
  482. instance->resume();
  483. return 0;
  484. }
  485. else
  486. {
  487. lua_pushstring(state, "lua_AudioSource_resume - Failed to match the given parameters to a valid function signature.");
  488. lua_error(state);
  489. }
  490. break;
  491. }
  492. default:
  493. {
  494. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  495. lua_error(state);
  496. break;
  497. }
  498. }
  499. return 0;
  500. }
  501. int lua_AudioSource_rewind(lua_State* state)
  502. {
  503. // Get the number of parameters.
  504. int paramCount = lua_gettop(state);
  505. // Attempt to match the parameters to a valid binding.
  506. switch (paramCount)
  507. {
  508. case 1:
  509. {
  510. if ((lua_type(state, 1) == LUA_TUSERDATA))
  511. {
  512. AudioSource* instance = getInstance(state);
  513. instance->rewind();
  514. return 0;
  515. }
  516. else
  517. {
  518. lua_pushstring(state, "lua_AudioSource_rewind - Failed to match the given parameters to a valid function signature.");
  519. lua_error(state);
  520. }
  521. break;
  522. }
  523. default:
  524. {
  525. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  526. lua_error(state);
  527. break;
  528. }
  529. }
  530. return 0;
  531. }
  532. int lua_AudioSource_setGain(lua_State* state)
  533. {
  534. // Get the number of parameters.
  535. int paramCount = lua_gettop(state);
  536. // Attempt to match the parameters to a valid binding.
  537. switch (paramCount)
  538. {
  539. case 2:
  540. {
  541. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  542. lua_type(state, 2) == LUA_TNUMBER)
  543. {
  544. // Get parameter 1 off the stack.
  545. float param1 = (float)luaL_checknumber(state, 2);
  546. AudioSource* instance = getInstance(state);
  547. instance->setGain(param1);
  548. return 0;
  549. }
  550. else
  551. {
  552. lua_pushstring(state, "lua_AudioSource_setGain - Failed to match the given parameters to a valid function signature.");
  553. lua_error(state);
  554. }
  555. break;
  556. }
  557. default:
  558. {
  559. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  560. lua_error(state);
  561. break;
  562. }
  563. }
  564. return 0;
  565. }
  566. int lua_AudioSource_setLooped(lua_State* state)
  567. {
  568. // Get the number of parameters.
  569. int paramCount = lua_gettop(state);
  570. // Attempt to match the parameters to a valid binding.
  571. switch (paramCount)
  572. {
  573. case 2:
  574. {
  575. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  576. lua_type(state, 2) == LUA_TBOOLEAN)
  577. {
  578. // Get parameter 1 off the stack.
  579. bool param1 = ScriptUtil::luaCheckBool(state, 2);
  580. AudioSource* instance = getInstance(state);
  581. instance->setLooped(param1);
  582. return 0;
  583. }
  584. else
  585. {
  586. lua_pushstring(state, "lua_AudioSource_setLooped - Failed to match the given parameters to a valid function signature.");
  587. lua_error(state);
  588. }
  589. break;
  590. }
  591. default:
  592. {
  593. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  594. lua_error(state);
  595. break;
  596. }
  597. }
  598. return 0;
  599. }
  600. int lua_AudioSource_setPitch(lua_State* state)
  601. {
  602. // Get the number of parameters.
  603. int paramCount = lua_gettop(state);
  604. // Attempt to match the parameters to a valid binding.
  605. switch (paramCount)
  606. {
  607. case 2:
  608. {
  609. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  610. lua_type(state, 2) == LUA_TNUMBER)
  611. {
  612. // Get parameter 1 off the stack.
  613. float param1 = (float)luaL_checknumber(state, 2);
  614. AudioSource* instance = getInstance(state);
  615. instance->setPitch(param1);
  616. return 0;
  617. }
  618. else
  619. {
  620. lua_pushstring(state, "lua_AudioSource_setPitch - Failed to match the given parameters to a valid function signature.");
  621. lua_error(state);
  622. }
  623. break;
  624. }
  625. default:
  626. {
  627. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  628. lua_error(state);
  629. break;
  630. }
  631. }
  632. return 0;
  633. }
  634. int lua_AudioSource_setVelocity(lua_State* state)
  635. {
  636. // Get the number of parameters.
  637. int paramCount = lua_gettop(state);
  638. // Attempt to match the parameters to a valid binding.
  639. switch (paramCount)
  640. {
  641. case 2:
  642. {
  643. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  644. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  645. {
  646. // Get parameter 1 off the stack.
  647. ScriptUtil::LuaArray<Vector3> param1 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", true);
  648. AudioSource* instance = getInstance(state);
  649. instance->setVelocity(*param1);
  650. return 0;
  651. }
  652. else
  653. {
  654. lua_pushstring(state, "lua_AudioSource_setVelocity - Failed to match the given parameters to a valid function signature.");
  655. lua_error(state);
  656. }
  657. break;
  658. }
  659. case 4:
  660. {
  661. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  662. lua_type(state, 2) == LUA_TNUMBER &&
  663. lua_type(state, 3) == LUA_TNUMBER &&
  664. lua_type(state, 4) == LUA_TNUMBER)
  665. {
  666. // Get parameter 1 off the stack.
  667. float param1 = (float)luaL_checknumber(state, 2);
  668. // Get parameter 2 off the stack.
  669. float param2 = (float)luaL_checknumber(state, 3);
  670. // Get parameter 3 off the stack.
  671. float param3 = (float)luaL_checknumber(state, 4);
  672. AudioSource* instance = getInstance(state);
  673. instance->setVelocity(param1, param2, param3);
  674. return 0;
  675. }
  676. else
  677. {
  678. lua_pushstring(state, "lua_AudioSource_setVelocity - Failed to match the given parameters to a valid function signature.");
  679. lua_error(state);
  680. }
  681. break;
  682. }
  683. default:
  684. {
  685. lua_pushstring(state, "Invalid number of parameters (expected 2 or 4).");
  686. lua_error(state);
  687. break;
  688. }
  689. }
  690. return 0;
  691. }
  692. int lua_AudioSource_static_create(lua_State* state)
  693. {
  694. // Get the number of parameters.
  695. int paramCount = lua_gettop(state);
  696. // Attempt to match the parameters to a valid binding.
  697. switch (paramCount)
  698. {
  699. case 1:
  700. {
  701. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
  702. {
  703. // Get parameter 1 off the stack.
  704. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(1, false);
  705. void* returnPtr = (void*)AudioSource::create(param1);
  706. if (returnPtr)
  707. {
  708. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  709. object->instance = returnPtr;
  710. object->owns = true;
  711. luaL_getmetatable(state, "AudioSource");
  712. lua_setmetatable(state, -2);
  713. }
  714. else
  715. {
  716. lua_pushnil(state);
  717. }
  718. return 1;
  719. }
  720. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL))
  721. {
  722. // Get parameter 1 off the stack.
  723. ScriptUtil::LuaArray<Properties> param1 = ScriptUtil::getObjectPointer<Properties>(1, "Properties", false);
  724. void* returnPtr = (void*)AudioSource::create(param1);
  725. if (returnPtr)
  726. {
  727. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  728. object->instance = returnPtr;
  729. object->owns = true;
  730. luaL_getmetatable(state, "AudioSource");
  731. lua_setmetatable(state, -2);
  732. }
  733. else
  734. {
  735. lua_pushnil(state);
  736. }
  737. return 1;
  738. }
  739. else
  740. {
  741. lua_pushstring(state, "lua_AudioSource_static_create - Failed to match the given parameters to a valid function signature.");
  742. lua_error(state);
  743. }
  744. break;
  745. }
  746. default:
  747. {
  748. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  749. lua_error(state);
  750. break;
  751. }
  752. }
  753. return 0;
  754. }
  755. int lua_AudioSource_stop(lua_State* state)
  756. {
  757. // Get the number of parameters.
  758. int paramCount = lua_gettop(state);
  759. // Attempt to match the parameters to a valid binding.
  760. switch (paramCount)
  761. {
  762. case 1:
  763. {
  764. if ((lua_type(state, 1) == LUA_TUSERDATA))
  765. {
  766. AudioSource* instance = getInstance(state);
  767. instance->stop();
  768. return 0;
  769. }
  770. else
  771. {
  772. lua_pushstring(state, "lua_AudioSource_stop - Failed to match the given parameters to a valid function signature.");
  773. lua_error(state);
  774. }
  775. break;
  776. }
  777. default:
  778. {
  779. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  780. lua_error(state);
  781. break;
  782. }
  783. }
  784. return 0;
  785. }
  786. }