lua_FileSystem.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_FileSystem.h"
  4. #include "Base.h"
  5. #include "FileSystem.h"
  6. #include "Properties.h"
  7. #include "Stream.h"
  8. namespace gameplay
  9. {
  10. void luaRegister_FileSystem()
  11. {
  12. const luaL_Reg lua_members[] =
  13. {
  14. {NULL, NULL}
  15. };
  16. const luaL_Reg lua_statics[] =
  17. {
  18. {"createFileFromAsset", lua_FileSystem_static_createFileFromAsset},
  19. {"fileExists", lua_FileSystem_static_fileExists},
  20. {"getDirectoryName", lua_FileSystem_static_getDirectoryName},
  21. {"getExtension", lua_FileSystem_static_getExtension},
  22. {"getResourcePath", lua_FileSystem_static_getResourcePath},
  23. {"isAbsolutePath", lua_FileSystem_static_isAbsolutePath},
  24. {"loadResourceAliases", lua_FileSystem_static_loadResourceAliases},
  25. {"readAll", lua_FileSystem_static_readAll},
  26. {"resolvePath", lua_FileSystem_static_resolvePath},
  27. {"setResourcePath", lua_FileSystem_static_setResourcePath},
  28. {NULL, NULL}
  29. };
  30. std::vector<std::string> scopePath;
  31. gameplay::ScriptUtil::registerClass("FileSystem", lua_members, NULL, lua_FileSystem__gc, lua_statics, scopePath);
  32. }
  33. static FileSystem* getInstance(lua_State* state)
  34. {
  35. void* userdata = luaL_checkudata(state, 1, "FileSystem");
  36. luaL_argcheck(state, userdata != NULL, 1, "'FileSystem' expected.");
  37. return (FileSystem*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  38. }
  39. int lua_FileSystem__gc(lua_State* state)
  40. {
  41. // Get the number of parameters.
  42. int paramCount = lua_gettop(state);
  43. // Attempt to match the parameters to a valid binding.
  44. switch (paramCount)
  45. {
  46. case 1:
  47. {
  48. if ((lua_type(state, 1) == LUA_TUSERDATA))
  49. {
  50. void* userdata = luaL_checkudata(state, 1, "FileSystem");
  51. luaL_argcheck(state, userdata != NULL, 1, "'FileSystem' expected.");
  52. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  53. if (object->owns)
  54. {
  55. FileSystem* instance = (FileSystem*)object->instance;
  56. SAFE_DELETE(instance);
  57. }
  58. return 0;
  59. }
  60. lua_pushstring(state, "lua_FileSystem__gc - Failed to match the given parameters to a valid function signature.");
  61. lua_error(state);
  62. break;
  63. }
  64. default:
  65. {
  66. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  67. lua_error(state);
  68. break;
  69. }
  70. }
  71. return 0;
  72. }
  73. int lua_FileSystem_static_createFileFromAsset(lua_State* state)
  74. {
  75. // Get the number of parameters.
  76. int paramCount = lua_gettop(state);
  77. // Attempt to match the parameters to a valid binding.
  78. switch (paramCount)
  79. {
  80. case 1:
  81. {
  82. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
  83. {
  84. // Get parameter 1 off the stack.
  85. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  86. FileSystem::createFileFromAsset(param1);
  87. return 0;
  88. }
  89. lua_pushstring(state, "lua_FileSystem_static_createFileFromAsset - Failed to match the given parameters to a valid function signature.");
  90. lua_error(state);
  91. break;
  92. }
  93. default:
  94. {
  95. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  96. lua_error(state);
  97. break;
  98. }
  99. }
  100. return 0;
  101. }
  102. int lua_FileSystem_static_fileExists(lua_State* state)
  103. {
  104. // Get the number of parameters.
  105. int paramCount = lua_gettop(state);
  106. // Attempt to match the parameters to a valid binding.
  107. switch (paramCount)
  108. {
  109. case 1:
  110. {
  111. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
  112. {
  113. // Get parameter 1 off the stack.
  114. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  115. bool result = FileSystem::fileExists(param1);
  116. // Push the return value onto the stack.
  117. lua_pushboolean(state, result);
  118. return 1;
  119. }
  120. lua_pushstring(state, "lua_FileSystem_static_fileExists - Failed to match the given parameters to a valid function signature.");
  121. lua_error(state);
  122. break;
  123. }
  124. default:
  125. {
  126. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  127. lua_error(state);
  128. break;
  129. }
  130. }
  131. return 0;
  132. }
  133. int lua_FileSystem_static_getDirectoryName(lua_State* state)
  134. {
  135. // Get the number of parameters.
  136. int paramCount = lua_gettop(state);
  137. // Attempt to match the parameters to a valid binding.
  138. switch (paramCount)
  139. {
  140. case 1:
  141. {
  142. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
  143. {
  144. // Get parameter 1 off the stack.
  145. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  146. std::string result = FileSystem::getDirectoryName(param1);
  147. // Push the return value onto the stack.
  148. lua_pushstring(state, result.c_str());
  149. return 1;
  150. }
  151. lua_pushstring(state, "lua_FileSystem_static_getDirectoryName - Failed to match the given parameters to a valid function signature.");
  152. lua_error(state);
  153. break;
  154. }
  155. default:
  156. {
  157. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  158. lua_error(state);
  159. break;
  160. }
  161. }
  162. return 0;
  163. }
  164. int lua_FileSystem_static_getExtension(lua_State* state)
  165. {
  166. // Get the number of parameters.
  167. int paramCount = lua_gettop(state);
  168. // Attempt to match the parameters to a valid binding.
  169. switch (paramCount)
  170. {
  171. case 1:
  172. {
  173. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
  174. {
  175. // Get parameter 1 off the stack.
  176. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  177. std::string result = FileSystem::getExtension(param1);
  178. // Push the return value onto the stack.
  179. lua_pushstring(state, result.c_str());
  180. return 1;
  181. }
  182. lua_pushstring(state, "lua_FileSystem_static_getExtension - Failed to match the given parameters to a valid function signature.");
  183. lua_error(state);
  184. break;
  185. }
  186. default:
  187. {
  188. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  189. lua_error(state);
  190. break;
  191. }
  192. }
  193. return 0;
  194. }
  195. int lua_FileSystem_static_getResourcePath(lua_State* state)
  196. {
  197. // Get the number of parameters.
  198. int paramCount = lua_gettop(state);
  199. // Attempt to match the parameters to a valid binding.
  200. switch (paramCount)
  201. {
  202. case 0:
  203. {
  204. const char* result = FileSystem::getResourcePath();
  205. // Push the return value onto the stack.
  206. lua_pushstring(state, result);
  207. return 1;
  208. break;
  209. }
  210. default:
  211. {
  212. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  213. lua_error(state);
  214. break;
  215. }
  216. }
  217. return 0;
  218. }
  219. int lua_FileSystem_static_isAbsolutePath(lua_State* state)
  220. {
  221. // Get the number of parameters.
  222. int paramCount = lua_gettop(state);
  223. // Attempt to match the parameters to a valid binding.
  224. switch (paramCount)
  225. {
  226. case 1:
  227. {
  228. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
  229. {
  230. // Get parameter 1 off the stack.
  231. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  232. bool result = FileSystem::isAbsolutePath(param1);
  233. // Push the return value onto the stack.
  234. lua_pushboolean(state, result);
  235. return 1;
  236. }
  237. lua_pushstring(state, "lua_FileSystem_static_isAbsolutePath - Failed to match the given parameters to a valid function signature.");
  238. lua_error(state);
  239. break;
  240. }
  241. default:
  242. {
  243. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  244. lua_error(state);
  245. break;
  246. }
  247. }
  248. return 0;
  249. }
  250. int lua_FileSystem_static_loadResourceAliases(lua_State* state)
  251. {
  252. // Get the number of parameters.
  253. int paramCount = lua_gettop(state);
  254. // Attempt to match the parameters to a valid binding.
  255. switch (paramCount)
  256. {
  257. case 1:
  258. {
  259. do
  260. {
  261. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
  262. {
  263. // Get parameter 1 off the stack.
  264. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  265. FileSystem::loadResourceAliases(param1);
  266. return 0;
  267. }
  268. } while (0);
  269. do
  270. {
  271. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL))
  272. {
  273. // Get parameter 1 off the stack.
  274. bool param1Valid;
  275. gameplay::ScriptUtil::LuaArray<Properties> param1 = gameplay::ScriptUtil::getObjectPointer<Properties>(1, "Properties", false, &param1Valid);
  276. if (!param1Valid)
  277. break;
  278. FileSystem::loadResourceAliases(param1);
  279. return 0;
  280. }
  281. } while (0);
  282. lua_pushstring(state, "lua_FileSystem_static_loadResourceAliases - Failed to match the given parameters to a valid function signature.");
  283. lua_error(state);
  284. break;
  285. }
  286. default:
  287. {
  288. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  289. lua_error(state);
  290. break;
  291. }
  292. }
  293. return 0;
  294. }
  295. int lua_FileSystem_static_readAll(lua_State* state)
  296. {
  297. // Get the number of parameters.
  298. int paramCount = lua_gettop(state);
  299. // Attempt to match the parameters to a valid binding.
  300. switch (paramCount)
  301. {
  302. case 1:
  303. {
  304. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
  305. {
  306. // Get parameter 1 off the stack.
  307. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  308. const char* result = FileSystem::readAll(param1);
  309. // Push the return value onto the stack.
  310. lua_pushstring(state, result);
  311. return 1;
  312. }
  313. lua_pushstring(state, "lua_FileSystem_static_readAll - Failed to match the given parameters to a valid function signature.");
  314. lua_error(state);
  315. break;
  316. }
  317. case 2:
  318. {
  319. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  320. (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA))
  321. {
  322. // Get parameter 1 off the stack.
  323. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  324. // Get parameter 2 off the stack.
  325. gameplay::ScriptUtil::LuaArray<int> param2 = gameplay::ScriptUtil::getIntPointer(2);
  326. const char* result = FileSystem::readAll(param1, param2);
  327. // Push the return value onto the stack.
  328. lua_pushstring(state, result);
  329. return 1;
  330. }
  331. lua_pushstring(state, "lua_FileSystem_static_readAll - Failed to match the given parameters to a valid function signature.");
  332. lua_error(state);
  333. break;
  334. }
  335. default:
  336. {
  337. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  338. lua_error(state);
  339. break;
  340. }
  341. }
  342. return 0;
  343. }
  344. int lua_FileSystem_static_resolvePath(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_TSTRING || lua_type(state, 1) == LUA_TNIL))
  354. {
  355. // Get parameter 1 off the stack.
  356. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  357. const char* result = FileSystem::resolvePath(param1);
  358. // Push the return value onto the stack.
  359. lua_pushstring(state, result);
  360. return 1;
  361. }
  362. lua_pushstring(state, "lua_FileSystem_static_resolvePath - Failed to match the given parameters to a valid function signature.");
  363. lua_error(state);
  364. break;
  365. }
  366. default:
  367. {
  368. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  369. lua_error(state);
  370. break;
  371. }
  372. }
  373. return 0;
  374. }
  375. int lua_FileSystem_static_setResourcePath(lua_State* state)
  376. {
  377. // Get the number of parameters.
  378. int paramCount = lua_gettop(state);
  379. // Attempt to match the parameters to a valid binding.
  380. switch (paramCount)
  381. {
  382. case 1:
  383. {
  384. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
  385. {
  386. // Get parameter 1 off the stack.
  387. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  388. FileSystem::setResourcePath(param1);
  389. return 0;
  390. }
  391. lua_pushstring(state, "lua_FileSystem_static_setResourcePath - Failed to match the given parameters to a valid function signature.");
  392. lua_error(state);
  393. break;
  394. }
  395. default:
  396. {
  397. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  398. lua_error(state);
  399. break;
  400. }
  401. }
  402. return 0;
  403. }
  404. }