aboutsummaryrefslogtreecommitdiff
path: root/src/libjin-lua/modules/filesystem/l_filesystem.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-02-11 11:29:07 +0800
committerchai <chaifix@163.com>2020-02-11 11:29:07 +0800
commit160e1299ef3d95f8e8c48706d7f61dd3dc6c6b60 (patch)
treeabe5ae5242d9cc6caf6edf103e662c44e978fca0 /src/libjin-lua/modules/filesystem/l_filesystem.cpp
parente095043485d1d298571af6d9eca7f0db9009ea7a (diff)
*修改 tab大小HEADmaster
Diffstat (limited to 'src/libjin-lua/modules/filesystem/l_filesystem.cpp')
-rw-r--r--src/libjin-lua/modules/filesystem/l_filesystem.cpp260
1 files changed, 130 insertions, 130 deletions
diff --git a/src/libjin-lua/modules/filesystem/l_filesystem.cpp b/src/libjin-lua/modules/filesystem/l_filesystem.cpp
index b297c8d..88d110c 100644
--- a/src/libjin-lua/modules/filesystem/l_filesystem.cpp
+++ b/src/libjin-lua/modules/filesystem/l_filesystem.cpp
@@ -7,134 +7,134 @@ using namespace JinEngine::Filesystem;
namespace JinEngine
{
- namespace Lua
- {
-
- LUA_IMPLEMENT struct
- {
- AssetDatabase* fs;
- } context;
-
- LUA_IMPLEMENT int l_init(lua_State* L)
- {
- context.fs = AssetDatabase::get();
- return 0;
- }
-
- LUA_IMPLEMENT int l_mount(lua_State* L)
- {
- const char* path = luax_checkstring(L, 1);
- context.fs->mount(path);
- return 0;
- }
-
- LUA_IMPLEMENT int l_exist(lua_State * L)
- {
- const char* path = luax_checkstring(L, 1);
- int r = context.fs->exists(path);
- luax_pushboolean(L, r);
- return 1;
- }
-
- LUA_IMPLEMENT int l_isDir(lua_State* L)
- {
- const char* path = luax_checkstring(L, 1);
- int r = context.fs->isDir(path);
- luax_pushboolean(L, r);
- return 1;
- }
-
- LUA_IMPLEMENT int l_isFile(lua_State* L)
- {
- const char* path = luax_checkstring(L, 1);
- int r = context.fs->isFile(path);
- luax_pushboolean(L, r);
- return 1;
- }
-
- LUA_IMPLEMENT int loadbuffer(lua_State* L)
- {
- const char* filename = lua_tostring(L, -1);
- Buffer bf;
- context.fs->read(filename, bf);
- luax_loadbuffer(L, (const char*)&bf, bf.size(), filename);
- return 1;
- }
-
- LUA_IMPLEMENT int loader(lua_State* L)
- {
- const char * filename = lua_tostring(L, -1);
-
- std::string tmp(filename);
- tmp += ".lua";
-
- int size = tmp.size();
-
- for (int i = 0; i<size - 4; ++i)
- {
- if (tmp[i] == '.')
- {
- tmp[i] = '/';
- }
- }
-
- if (context.fs->exists(tmp.c_str()))
- {
- lua_pop(L, 1);
- lua_pushstring(L, tmp.c_str());
- return loadbuffer(L);
- }
-
- tmp = filename;
- size = tmp.size();
- for (int i = 0; i<size; ++i)
- {
- if (tmp[i] == '.')
- tmp[i] = '/';
- }
-
- if (context.fs->isDir(tmp.c_str()))
- {
- tmp += "/init.lua";
- if (context.fs->exists(tmp.c_str()))
- {
- lua_pop(L, 1);
- lua_pushstring(L, tmp.c_str());
- return loadbuffer(L);
- }
- }
-
- lua_pushfstring(L, "\n\tno file \"%s\" in jin game directories.\n", (tmp + ".lua").c_str());
- return 1;
- }
-
- LUA_IMPLEMENT int l_read(lua_State* L)
- {
- AssetDatabase* fs = context.fs;
- const char* file = luax_checkstring(L, 1);
- unsigned int len;
- Buffer buffer;
- fs->read(file, buffer);
- luax_pushstring(L, (char*)&buffer);
- luax_pushinteger(L, buffer.size());
- return 2;
- }
-
- LUA_EXPORT int luaopen_filesystem(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "init", l_init },
- { "mount", l_mount },
- { "isDirectory", l_isDir },
- { "isFile", l_isFile },
- { "exist", l_exist },
- { "read", l_read },
- { 0, 0 }
- };
- luax_newlib(L, methods);
- luax_registersearcher(L, loader, 1);
- return 0;
- }
-
- } // namespace Lua
+ namespace Lua
+ {
+
+ LUA_IMPLEMENT struct
+ {
+ AssetDatabase* fs;
+ } context;
+
+ LUA_IMPLEMENT int l_init(lua_State* L)
+ {
+ context.fs = AssetDatabase::get();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_mount(lua_State* L)
+ {
+ const char* path = luax_checkstring(L, 1);
+ context.fs->mount(path);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_exist(lua_State * L)
+ {
+ const char* path = luax_checkstring(L, 1);
+ int r = context.fs->exists(path);
+ luax_pushboolean(L, r);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_isDir(lua_State* L)
+ {
+ const char* path = luax_checkstring(L, 1);
+ int r = context.fs->isDir(path);
+ luax_pushboolean(L, r);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_isFile(lua_State* L)
+ {
+ const char* path = luax_checkstring(L, 1);
+ int r = context.fs->isFile(path);
+ luax_pushboolean(L, r);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int loadbuffer(lua_State* L)
+ {
+ const char* filename = lua_tostring(L, -1);
+ Buffer bf;
+ context.fs->read(filename, bf);
+ luax_loadbuffer(L, (const char*)&bf, bf.size(), filename);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int loader(lua_State* L)
+ {
+ const char * filename = lua_tostring(L, -1);
+
+ std::string tmp(filename);
+ tmp += ".lua";
+
+ int size = tmp.size();
+
+ for (int i = 0; i<size - 4; ++i)
+ {
+ if (tmp[i] == '.')
+ {
+ tmp[i] = '/';
+ }
+ }
+
+ if (context.fs->exists(tmp.c_str()))
+ {
+ lua_pop(L, 1);
+ lua_pushstring(L, tmp.c_str());
+ return loadbuffer(L);
+ }
+
+ tmp = filename;
+ size = tmp.size();
+ for (int i = 0; i<size; ++i)
+ {
+ if (tmp[i] == '.')
+ tmp[i] = '/';
+ }
+
+ if (context.fs->isDir(tmp.c_str()))
+ {
+ tmp += "/init.lua";
+ if (context.fs->exists(tmp.c_str()))
+ {
+ lua_pop(L, 1);
+ lua_pushstring(L, tmp.c_str());
+ return loadbuffer(L);
+ }
+ }
+
+ lua_pushfstring(L, "\n\tno file \"%s\" in jin game directories.\n", (tmp + ".lua").c_str());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_read(lua_State* L)
+ {
+ AssetDatabase* fs = context.fs;
+ const char* file = luax_checkstring(L, 1);
+ unsigned int len;
+ Buffer buffer;
+ fs->read(file, buffer);
+ luax_pushstring(L, (char*)&buffer);
+ luax_pushinteger(L, buffer.size());
+ return 2;
+ }
+
+ LUA_EXPORT int luaopen_filesystem(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "init", l_init },
+ { "mount", l_mount },
+ { "isDirectory", l_isDir },
+ { "isFile", l_isFile },
+ { "exist", l_exist },
+ { "read", l_read },
+ { 0, 0 }
+ };
+ luax_newlib(L, methods);
+ luax_registersearcher(L, loader, 1);
+ return 0;
+ }
+
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file