lua_Light.cpp 26 KB

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