From 6551adeca70d4299a99d45245d4e13dbfdfa87e5 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 23 Oct 2018 15:56:01 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9lua=E7=BB=91=E5=AE=9A=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E6=96=87=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lua/modules/filesystem/filesystem.cpp | 140 ------------------------------ 1 file changed, 140 deletions(-) delete mode 100644 src/lua/modules/filesystem/filesystem.cpp (limited to 'src/lua/modules/filesystem/filesystem.cpp') 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 - -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; iexists(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; iisDir(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 -- cgit v1.1-26-g67d0