From 98c9825c49a1674f59eafb3253829ca7d5cac3c1 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 14 Jan 2019 16:40:14 +0800 Subject: *rename source file --- .../modules/filesystem/je_lua_filesystem.cpp | 140 --------------------- .../modules/filesystem/je_lua_filesystem.h | 14 --- src/libjin-lua/modules/filesystem/l_filesystem.cpp | 140 +++++++++++++++++++++ src/libjin-lua/modules/filesystem/l_filesystem.h | 14 +++ 4 files changed, 154 insertions(+), 154 deletions(-) delete mode 100644 src/libjin-lua/modules/filesystem/je_lua_filesystem.cpp delete mode 100644 src/libjin-lua/modules/filesystem/je_lua_filesystem.h create mode 100644 src/libjin-lua/modules/filesystem/l_filesystem.cpp create mode 100644 src/libjin-lua/modules/filesystem/l_filesystem.h (limited to 'src/libjin-lua/modules/filesystem') diff --git a/src/libjin-lua/modules/filesystem/je_lua_filesystem.cpp b/src/libjin-lua/modules/filesystem/je_lua_filesystem.cpp deleted file mode 100644 index e73d1ad..0000000 --- a/src/libjin-lua/modules/filesystem/je_lua_filesystem.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#include "common/je_lua_common.h" -#include "common/je_lua.h" -#include "libjin/jin.h" -#include - -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; 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; - } - - 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 diff --git a/src/libjin-lua/modules/filesystem/je_lua_filesystem.h b/src/libjin-lua/modules/filesystem/je_lua_filesystem.h deleted file mode 100644 index 1e1ff23..0000000 --- a/src/libjin-lua/modules/filesystem/je_lua_filesystem.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __JE_LUA_FILESYSTEM_H__ -#define __JE_LUA_FILESYSTEM_H__ - -namespace JinEngine -{ - namespace Lua - { - - int luaopen_filesystem(lua_State* L); - - } -} - -#endif \ No newline at end of file diff --git a/src/libjin-lua/modules/filesystem/l_filesystem.cpp b/src/libjin-lua/modules/filesystem/l_filesystem.cpp new file mode 100644 index 0000000..b297c8d --- /dev/null +++ b/src/libjin-lua/modules/filesystem/l_filesystem.cpp @@ -0,0 +1,140 @@ +#include "common/l_common.h" +#include "common/je_lua.h" +#include "libjin/jin.h" +#include + +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; 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; + } + + 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 diff --git a/src/libjin-lua/modules/filesystem/l_filesystem.h b/src/libjin-lua/modules/filesystem/l_filesystem.h new file mode 100644 index 0000000..1e1ff23 --- /dev/null +++ b/src/libjin-lua/modules/filesystem/l_filesystem.h @@ -0,0 +1,14 @@ +#ifndef __JE_LUA_FILESYSTEM_H__ +#define __JE_LUA_FILESYSTEM_H__ + +namespace JinEngine +{ + namespace Lua + { + + int luaopen_filesystem(lua_State* L); + + } +} + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0