lua_FileSystem.cpp 12 KB

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