lua_FileSystem.cpp 12 KB

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