aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/filesystem/filesystem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules/filesystem/filesystem.cpp')
-rw-r--r--src/lua/modules/filesystem/filesystem.cpp60
1 files changed, 31 insertions, 29 deletions
diff --git a/src/lua/modules/filesystem/filesystem.cpp b/src/lua/modules/filesystem/filesystem.cpp
index 55f4c06..e1d496e 100644
--- a/src/lua/modules/filesystem/filesystem.cpp
+++ b/src/lua/modules/filesystem/filesystem.cpp
@@ -20,10 +20,6 @@ namespace lua
return 0;
}
- /**
- * set current game root, like
- * C:/jin/games/tank/
- */
static int l_mount(lua_State* L)
{
const char* path = luax_checkstring(L, 1);
@@ -31,38 +27,31 @@ namespace lua
return 0;
}
- /**
- *
- */
- static int l_isDir(lua_State *L)
+ static int l_exist(lua_State * L)
{
const char* path = luax_checkstring(L, 1);
- int r = context.fs->isDir(path);
- luax_pushboolean(L, r);
- return 1;
+ int r = context.fs->exists(path);
+ luax_pushboolean(L, r);
+ return 1;
}
- /**
- *
- */
- static int l_exist(lua_State * L)
+ static int l_isDir(lua_State* L)
{
const char* path = luax_checkstring(L, 1);
- int r = context.fs->exists(path);
+ int r = context.fs->isDir(path);
luax_pushboolean(L, r);
return 1;
}
- static int l_isdir(lua_State* L)
+ static int l_isFile(lua_State* L)
{
const char* path = luax_checkstring(L, 1);
- int r = context.fs->isDir(path);
+ int r = context.fs->isFile(path);
luax_pushboolean(L, r);
return 1;
}
- // load but dont run it
- static int loadf(lua_State* L)
+ static int loadbuffer(lua_State* L)
{
const char* filename = lua_tostring(L, -1);
Buffer bf;
@@ -92,7 +81,7 @@ namespace lua
{
lua_pop(L, 1);
lua_pushstring(L, tmp.c_str());
- return loadf(L);
+ return loadbuffer(L);
}
tmp = filename;
@@ -110,7 +99,7 @@ namespace lua
{
lua_pop(L, 1);
lua_pushstring(L, tmp.c_str());
- return loadf(L);
+ return loadbuffer(L);
}
}
@@ -118,12 +107,25 @@ namespace lua
return 1;
}
+ static int l_read(lua_State* L)
+ {
+ Filesystem* fs = context.fs;
+ const char* file = luax_checkstring(L, 1);
+ unsigned int len;
+ char* data = (char*)fs->read(file, &len);
+ luax_pushstring(L, data);
+ luax_pushinteger(L, len);
+ return 2;
+ }
+
static const luaL_Reg f[] = {
- { "init", l_init },
- { "mount", l_mount },
- { "isdir", l_isDir },
- { "exist", l_exist },
- { 0, 0 }
+ { "init", l_init },
+ { "mount", l_mount },
+ { "isDir", l_isDir },
+ { "isFile", l_isFile },
+ { "exist", l_exist },
+ { "read", l_read },
+ { 0, 0 }
};
int luaopen_filesystem(lua_State* L)
@@ -133,5 +135,5 @@ namespace lua
return 0;
}
-}
-} \ No newline at end of file
+} // filesystem
+} // jin \ No newline at end of file