diff options
author | chai <chaifix@163.com> | 2018-10-23 15:56:01 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-10-23 15:56:01 +0800 |
commit | 6551adeca70d4299a99d45245d4e13dbfdfa87e5 (patch) | |
tree | a766ff9a0cdc52588a6aa62e41d0b134c04c2ba0 /src/lua/modules/filesystem/filesystem.cpp | |
parent | a164919e8eb3409d13bb225cc0e6f0b95446e8e0 (diff) |
*修改lua绑定文件的文件名
Diffstat (limited to 'src/lua/modules/filesystem/filesystem.cpp')
-rw-r--r-- | src/lua/modules/filesystem/filesystem.cpp | 140 |
1 files changed, 0 insertions, 140 deletions
diff --git a/src/lua/modules/filesystem/filesystem.cpp b/src/lua/modules/filesystem/filesystem.cpp deleted file mode 100644 index 7466ce8..0000000 --- a/src/lua/modules/filesystem/filesystem.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#include "lua/modules/luax.h" -#include "libjin/jin.h" -#include <string> - -using namespace JinEngine::Filesystem; - -namespace JinEngine -{ - namespace Lua - { - - static struct - { - AssetDatabase* fs; - } context; - - static int l_init(lua_State* L) - { - context.fs = AssetDatabase::get(); - return 0; - } - - static int l_mount(lua_State* L) - { - const char* path = luax_checkstring(L, 1); - context.fs->mount(path); - return 0; - } - - static 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; - } - - static 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; - } - - static 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; - } - - static 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; - } - - static 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; - } - - static 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; - } - - static const luaL_Reg f[] = { - { "init", l_init }, - { "mount", l_mount }, - { "isDirectory", l_isDir }, - { "isFile", l_isFile }, - { "exist", l_exist }, - { "read", l_read }, - { 0, 0 } - }; - - int luaopen_filesystem(lua_State* L) - { - luax_newlib(L, f); - luax_registersearcher(L, loader, 1); - return 0; - } - - } // namespace Lua -} // namespace JinEngine
\ No newline at end of file |