lua_FileSystem.cpp 12 KB

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