lua_AIAgent.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_AIAgent.h"
  4. #include "AIAgent.h"
  5. #include "Base.h"
  6. #include "Game.h"
  7. #include "Node.h"
  8. #include "Ref.h"
  9. namespace gameplay
  10. {
  11. void luaRegister_AIAgent()
  12. {
  13. const luaL_Reg lua_members[] =
  14. {
  15. {"addRef", lua_AIAgent_addRef},
  16. {"getId", lua_AIAgent_getId},
  17. {"getNode", lua_AIAgent_getNode},
  18. {"getRefCount", lua_AIAgent_getRefCount},
  19. {"getStateMachine", lua_AIAgent_getStateMachine},
  20. {"isEnabled", lua_AIAgent_isEnabled},
  21. {"release", lua_AIAgent_release},
  22. {"setEnabled", lua_AIAgent_setEnabled},
  23. {"setListener", lua_AIAgent_setListener},
  24. {NULL, NULL}
  25. };
  26. const luaL_Reg lua_statics[] =
  27. {
  28. {"create", lua_AIAgent_static_create},
  29. {NULL, NULL}
  30. };
  31. std::vector<std::string> scopePath;
  32. ScriptUtil::registerClass("AIAgent", lua_members, NULL, lua_AIAgent__gc, lua_statics, scopePath);
  33. }
  34. static AIAgent* getInstance(lua_State* state)
  35. {
  36. void* userdata = luaL_checkudata(state, 1, "AIAgent");
  37. luaL_argcheck(state, userdata != NULL, 1, "'AIAgent' expected.");
  38. return (AIAgent*)((ScriptUtil::LuaObject*)userdata)->instance;
  39. }
  40. int lua_AIAgent__gc(lua_State* state)
  41. {
  42. // Get the number of parameters.
  43. int paramCount = lua_gettop(state);
  44. // Attempt to match the parameters to a valid binding.
  45. switch (paramCount)
  46. {
  47. case 1:
  48. {
  49. if ((lua_type(state, 1) == LUA_TUSERDATA))
  50. {
  51. void* userdata = luaL_checkudata(state, 1, "AIAgent");
  52. luaL_argcheck(state, userdata != NULL, 1, "'AIAgent' expected.");
  53. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  54. if (object->owns)
  55. {
  56. AIAgent* instance = (AIAgent*)object->instance;
  57. SAFE_RELEASE(instance);
  58. }
  59. return 0;
  60. }
  61. else
  62. {
  63. lua_pushstring(state, "lua_AIAgent__gc - Failed to match the given parameters to a valid function signature.");
  64. lua_error(state);
  65. }
  66. break;
  67. }
  68. default:
  69. {
  70. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  71. lua_error(state);
  72. break;
  73. }
  74. }
  75. return 0;
  76. }
  77. int lua_AIAgent_addRef(lua_State* state)
  78. {
  79. // Get the number of parameters.
  80. int paramCount = lua_gettop(state);
  81. // Attempt to match the parameters to a valid binding.
  82. switch (paramCount)
  83. {
  84. case 1:
  85. {
  86. if ((lua_type(state, 1) == LUA_TUSERDATA))
  87. {
  88. AIAgent* instance = getInstance(state);
  89. instance->addRef();
  90. return 0;
  91. }
  92. else
  93. {
  94. lua_pushstring(state, "lua_AIAgent_addRef - Failed to match the given parameters to a valid function signature.");
  95. lua_error(state);
  96. }
  97. break;
  98. }
  99. default:
  100. {
  101. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  102. lua_error(state);
  103. break;
  104. }
  105. }
  106. return 0;
  107. }
  108. int lua_AIAgent_getId(lua_State* state)
  109. {
  110. // Get the number of parameters.
  111. int paramCount = lua_gettop(state);
  112. // Attempt to match the parameters to a valid binding.
  113. switch (paramCount)
  114. {
  115. case 1:
  116. {
  117. if ((lua_type(state, 1) == LUA_TUSERDATA))
  118. {
  119. AIAgent* instance = getInstance(state);
  120. const char* result = instance->getId();
  121. // Push the return value onto the stack.
  122. lua_pushstring(state, result);
  123. return 1;
  124. }
  125. else
  126. {
  127. lua_pushstring(state, "lua_AIAgent_getId - Failed to match the given parameters to a valid function signature.");
  128. lua_error(state);
  129. }
  130. break;
  131. }
  132. default:
  133. {
  134. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  135. lua_error(state);
  136. break;
  137. }
  138. }
  139. return 0;
  140. }
  141. int lua_AIAgent_getNode(lua_State* state)
  142. {
  143. // Get the number of parameters.
  144. int paramCount = lua_gettop(state);
  145. // Attempt to match the parameters to a valid binding.
  146. switch (paramCount)
  147. {
  148. case 1:
  149. {
  150. if ((lua_type(state, 1) == LUA_TUSERDATA))
  151. {
  152. AIAgent* instance = getInstance(state);
  153. void* returnPtr = (void*)instance->getNode();
  154. if (returnPtr)
  155. {
  156. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  157. object->instance = returnPtr;
  158. object->owns = false;
  159. luaL_getmetatable(state, "Node");
  160. lua_setmetatable(state, -2);
  161. }
  162. else
  163. {
  164. lua_pushnil(state);
  165. }
  166. return 1;
  167. }
  168. else
  169. {
  170. lua_pushstring(state, "lua_AIAgent_getNode - Failed to match the given parameters to a valid function signature.");
  171. lua_error(state);
  172. }
  173. break;
  174. }
  175. default:
  176. {
  177. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  178. lua_error(state);
  179. break;
  180. }
  181. }
  182. return 0;
  183. }
  184. int lua_AIAgent_getRefCount(lua_State* state)
  185. {
  186. // Get the number of parameters.
  187. int paramCount = lua_gettop(state);
  188. // Attempt to match the parameters to a valid binding.
  189. switch (paramCount)
  190. {
  191. case 1:
  192. {
  193. if ((lua_type(state, 1) == LUA_TUSERDATA))
  194. {
  195. AIAgent* instance = getInstance(state);
  196. unsigned int result = instance->getRefCount();
  197. // Push the return value onto the stack.
  198. lua_pushunsigned(state, result);
  199. return 1;
  200. }
  201. else
  202. {
  203. lua_pushstring(state, "lua_AIAgent_getRefCount - Failed to match the given parameters to a valid function signature.");
  204. lua_error(state);
  205. }
  206. break;
  207. }
  208. default:
  209. {
  210. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  211. lua_error(state);
  212. break;
  213. }
  214. }
  215. return 0;
  216. }
  217. int lua_AIAgent_getStateMachine(lua_State* state)
  218. {
  219. // Get the number of parameters.
  220. int paramCount = lua_gettop(state);
  221. // Attempt to match the parameters to a valid binding.
  222. switch (paramCount)
  223. {
  224. case 1:
  225. {
  226. if ((lua_type(state, 1) == LUA_TUSERDATA))
  227. {
  228. AIAgent* instance = getInstance(state);
  229. void* returnPtr = (void*)instance->getStateMachine();
  230. if (returnPtr)
  231. {
  232. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  233. object->instance = returnPtr;
  234. object->owns = false;
  235. luaL_getmetatable(state, "AIStateMachine");
  236. lua_setmetatable(state, -2);
  237. }
  238. else
  239. {
  240. lua_pushnil(state);
  241. }
  242. return 1;
  243. }
  244. else
  245. {
  246. lua_pushstring(state, "lua_AIAgent_getStateMachine - 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 1).");
  254. lua_error(state);
  255. break;
  256. }
  257. }
  258. return 0;
  259. }
  260. int lua_AIAgent_isEnabled(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. AIAgent* instance = getInstance(state);
  272. bool result = instance->isEnabled();
  273. // Push the return value onto the stack.
  274. lua_pushboolean(state, result);
  275. return 1;
  276. }
  277. else
  278. {
  279. lua_pushstring(state, "lua_AIAgent_isEnabled - 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_AIAgent_release(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 1:
  301. {
  302. if ((lua_type(state, 1) == LUA_TUSERDATA))
  303. {
  304. AIAgent* instance = getInstance(state);
  305. instance->release();
  306. return 0;
  307. }
  308. else
  309. {
  310. lua_pushstring(state, "lua_AIAgent_release - Failed to match the given parameters to a valid function signature.");
  311. lua_error(state);
  312. }
  313. break;
  314. }
  315. default:
  316. {
  317. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  318. lua_error(state);
  319. break;
  320. }
  321. }
  322. return 0;
  323. }
  324. int lua_AIAgent_setEnabled(lua_State* state)
  325. {
  326. // Get the number of parameters.
  327. int paramCount = lua_gettop(state);
  328. // Attempt to match the parameters to a valid binding.
  329. switch (paramCount)
  330. {
  331. case 2:
  332. {
  333. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  334. lua_type(state, 2) == LUA_TBOOLEAN)
  335. {
  336. // Get parameter 1 off the stack.
  337. bool param1 = ScriptUtil::luaCheckBool(state, 2);
  338. AIAgent* instance = getInstance(state);
  339. instance->setEnabled(param1);
  340. return 0;
  341. }
  342. else
  343. {
  344. lua_pushstring(state, "lua_AIAgent_setEnabled - Failed to match the given parameters to a valid function signature.");
  345. lua_error(state);
  346. }
  347. break;
  348. }
  349. default:
  350. {
  351. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  352. lua_error(state);
  353. break;
  354. }
  355. }
  356. return 0;
  357. }
  358. int lua_AIAgent_setListener(lua_State* state)
  359. {
  360. // Get the number of parameters.
  361. int paramCount = lua_gettop(state);
  362. // Attempt to match the parameters to a valid binding.
  363. switch (paramCount)
  364. {
  365. case 2:
  366. {
  367. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  368. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  369. {
  370. // Get parameter 1 off the stack.
  371. AIAgent::Listener* param1 = ScriptUtil::getObjectPointer<AIAgent::Listener>(2, "AIAgentListener", false);
  372. AIAgent* instance = getInstance(state);
  373. instance->setListener(param1);
  374. return 0;
  375. }
  376. else
  377. {
  378. lua_pushstring(state, "lua_AIAgent_setListener - Failed to match the given parameters to a valid function signature.");
  379. lua_error(state);
  380. }
  381. break;
  382. }
  383. default:
  384. {
  385. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  386. lua_error(state);
  387. break;
  388. }
  389. }
  390. return 0;
  391. }
  392. int lua_AIAgent_static_create(lua_State* state)
  393. {
  394. // Get the number of parameters.
  395. int paramCount = lua_gettop(state);
  396. // Attempt to match the parameters to a valid binding.
  397. switch (paramCount)
  398. {
  399. case 0:
  400. {
  401. void* returnPtr = (void*)AIAgent::create();
  402. if (returnPtr)
  403. {
  404. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  405. object->instance = returnPtr;
  406. object->owns = false;
  407. luaL_getmetatable(state, "AIAgent");
  408. lua_setmetatable(state, -2);
  409. }
  410. else
  411. {
  412. lua_pushnil(state);
  413. }
  414. return 1;
  415. break;
  416. }
  417. default:
  418. {
  419. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  420. lua_error(state);
  421. break;
  422. }
  423. }
  424. return 0;
  425. }
  426. }