lua_AIMessage.cpp 25 KB

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