lua_FileSystem.cpp 13 KB

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