#include "Base.h" #include "ScriptController.h" #include "FileSystem.h" #include "lua_FileSystem.h" #include "lua_Global.h" namespace gameplay { void luaRegister_FileSystem() { ScriptController* sc = ScriptController::getInstance(); const luaL_Reg lua_members[] = { {NULL, NULL} }; const luaL_Reg lua_statics[] = { {"fileExists", lua_FileSystem_static_fileExists}, {"getResourcePath", lua_FileSystem_static_getResourcePath}, {"loadResourceAliases", lua_FileSystem_static_loadResourceAliases}, {"readAll", lua_FileSystem_static_readAll}, {"resolvePath", lua_FileSystem_static_resolvePath}, {"setResourcePath", lua_FileSystem_static_setResourcePath}, {NULL, NULL} }; std::vector scopePath; sc->registerClass("FileSystem", lua_members, NULL, lua_FileSystem__gc, lua_statics, scopePath); } static FileSystem* getInstance(lua_State* state) { void* userdata = luaL_checkudata(state, 1, "FileSystem"); luaL_argcheck(state, userdata != NULL, 1, "'FileSystem' expected."); return (FileSystem*)((ScriptController::LuaObject*)userdata)->instance; } int lua_FileSystem__gc(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TUSERDATA)) { void* userdata = luaL_checkudata(state, 1, "FileSystem"); luaL_argcheck(state, userdata != NULL, 1, "'FileSystem' expected."); ScriptController::LuaObject* object = (ScriptController::LuaObject*)userdata; if (object->owns) { FileSystem* instance = (FileSystem*)object->instance; SAFE_DELETE(instance); } return 0; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; } int lua_FileSystem_static_fileExists(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL)) { // Get parameter 1 off the stack. const char* param1 = ScriptController::getInstance()->getString(1, false); bool result = FileSystem::fileExists(param1); // Push the return value onto the stack. lua_pushboolean(state, result); return 1; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; } int lua_FileSystem_static_getResourcePath(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 0: { const char* result = FileSystem::getResourcePath(); // Push the return value onto the stack. lua_pushstring(state, result); return 1; break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 0)."); lua_error(state); break; } } return 0; } int lua_FileSystem_static_loadResourceAliases(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL)) { // Get parameter 1 off the stack. const char* param1 = ScriptController::getInstance()->getString(1, false); FileSystem::loadResourceAliases(param1); return 0; } else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL)) { // Get parameter 1 off the stack. Properties* param1 = ScriptController::getInstance()->getObjectPointer(1, "Properties", false); FileSystem::loadResourceAliases(param1); return 0; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; } int lua_FileSystem_static_readAll(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL)) { // Get parameter 1 off the stack. const char* param1 = ScriptController::getInstance()->getString(1, false); const char* result = FileSystem::readAll(param1); // Push the return value onto the stack. lua_pushstring(state, result); return 1; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } case 2: { if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) && (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA)) { // Get parameter 1 off the stack. const char* param1 = ScriptController::getInstance()->getString(1, false); // Get parameter 2 off the stack. int* param2 = ScriptController::getInstance()->getIntPointer(2); const char* result = FileSystem::readAll(param1, param2); // Push the return value onto the stack. lua_pushstring(state, result); return 1; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1 or 2)."); lua_error(state); break; } } return 0; } int lua_FileSystem_static_resolvePath(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL)) { // Get parameter 1 off the stack. const char* param1 = ScriptController::getInstance()->getString(1, false); const char* result = FileSystem::resolvePath(param1); // Push the return value onto the stack. lua_pushstring(state, result); return 1; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; } int lua_FileSystem_static_setResourcePath(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL)) { // Get parameter 1 off the stack. const char* param1 = ScriptController::getInstance()->getString(1, false); FileSystem::setResourcePath(param1); return 0; } else { lua_pushstring(state, "Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; } }