Skip to content

Commit

Permalink
移除对emscripten的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Apr 12, 2024
1 parent b038ca5 commit ab4994b
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 316 deletions.
104 changes: 1 addition & 103 deletions binding/lua_filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,72 +17,6 @@
# include <bee/platform/win/wtf8.h>
#endif

#if defined(__EMSCRIPTEN__)
# include <emscripten.h>
namespace bee::lua_filesystem {
fs::path wasm_current_path() {
char* cwd = (char*)EM_ASM_PTR({
var cwd = FS.cwd();
var cwdLengthInBytes = lengthBytesUTF8(cwd) + 1;
var cwdOnWasmHeap = _malloc(cwdLengthInBytes);
stringToUTF8(cwd, cwdOnWasmHeap, cwdLengthInBytes);
return cwdOnWasmHeap;
});
fs::path r(cwd);
free(cwd);
return r;
}
int wasm_remove(const fs::path& path) {
return EM_ASM_INT(
{
try {
var path = UTF8ToString($0);
var st = FS.lstat(path);
if (st.isDirectory()) {
FS.rmdir(path);
}
else {
FS.unlink(path);
}
return 0;
} catch (e) {
return e.errno;
}
},
path.c_str()
);
}
uintmax_t wasm_remove_all(const fs::path& path, std::error_code& ec) {
const auto npos = static_cast<uintmax_t>(-1);
auto st = fs::symlink_status(path, ec);
if (ec) {
return npos;
}
uintmax_t count = 0;
if (fs::is_directory(st)) {
for (fs::directory_iterator it(path, ec); !ec && it != fs::directory_iterator(); it.increment(ec)) {
auto other_count = wasm_remove_all(it->path(), ec);
if (ec) {
return npos;
}
count += other_count;
}
}
int err = wasm_remove(path);
if (err) {
if (err != ENOENT && err != ENOTDIR) {
ec.assign(err, std::generic_category());
return npos;
}
}
else {
count += 1;
}
return count;
}
}
#endif

namespace bee::lua_filesystem {
static std::string tostring(const fs::path& path) {
#if defined(_WIN32)
Expand Down Expand Up @@ -657,62 +591,33 @@ namespace bee::lua_filesystem {

static lua::cxx::status remove(lua_State* L) {
auto p = getpathptr(L, 1);
#if defined(__EMSCRIPTEN__)
int err = wasm_remove(p);
if (err) {
if (err == ENOENT || err == ENOTDIR) {
lua_pushboolean(L, 0);
return 1;
}
return pusherror(L, "remove", std::make_error_code((std::errc)err), p);
}
lua_pushboolean(L, 1);
return 1;
#else
std::error_code ec;
auto r = fs::remove(p, ec);
if (ec) {
return pusherror(L, "remove", ec, p);
}
lua_pushboolean(L, r);
return 1;
#endif
}

static lua::cxx::status remove_all(lua_State* L) {
auto p = getpathptr(L, 1);
std::error_code ec;
#if defined(__EMSCRIPTEN__)
uintmax_t r = wasm_remove_all(p, ec);
if (ec) {
if (ec == std::errc::no_such_file_or_directory) {
lua_pushinteger(L, 0);
return 1;
}
return pusherror(L, "remove_all", ec, p);
}
return bee::lua::narrow_pushinteger(L, r);
#else
auto r = fs::remove_all(p, ec);
if (ec) {
return pusherror(L, "remove_all", ec, p);
}
return lua::narrow_pushinteger(L, r);
#endif
}

static lua::cxx::status current_path(lua_State* L) {
std::error_code ec;
if (lua_gettop(L) == 0) {
#if defined(__EMSCRIPTEN__)
path::push(L, wasm_current_path());
#else
fs::path r = fs::current_path(ec);
if (ec) {
return pusherror(L, "current_path()", ec);
}
path::push(L, r);
#endif
return 1;
}
auto p = getpathptr(L, 1);
Expand Down Expand Up @@ -782,11 +687,7 @@ namespace bee::lua_filesystem {
static lua::cxx::status absolute(lua_State* L) {
auto p = getpathptr(L, 1);
std::error_code ec;
#if defined(__EMSCRIPTEN__)
auto r = wasm_current_path() / p;
#else
auto r = fs::absolute(p, ec);
#endif
if (ec) {
return pusherror(L, "absolute", ec, p);
}
Expand Down Expand Up @@ -1005,7 +906,7 @@ namespace bee::lua_filesystem {
path::push(L, r.value());
return 1;
}
#if !defined(__EMSCRIPTEN__)

static int filelock(lua_State* L) {
auto self = getpathptr(L, 1);
auto fd = file_handle::lock(self);
Expand Down Expand Up @@ -1043,7 +944,6 @@ namespace bee::lua_filesystem {
path::push(L, *fullpath);
return 1;
}
#endif

static int luaopen(lua_State* L) {
static luaL_Reg lib[] = {
Expand Down Expand Up @@ -1074,10 +974,8 @@ namespace bee::lua_filesystem {
{ "pairs", lua::cxx::cfunc<pairs> },
{ "exe_path", exe_path },
{ "dll_path", dll_path },
#if !defined(__EMSCRIPTEN__)
{ "filelock", filelock },
{ "fullpath", fullpath },
#endif
{ "copy_options", NULL },
{ "perm_options", NULL },
{ NULL, NULL },
Expand Down
21 changes: 0 additions & 21 deletions binding/lua_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,6 @@
# endif
#endif

#if defined(__EMSCRIPTEN__)
# include <emscripten.h>
namespace bee::lua_platform {
int wasm_posix_host() {
return EM_ASM_INT({
if (NODEFS.isWindows) {
return 0;
}
return 1;
});
}
}
#endif

namespace bee::lua_platform {
static int luaopen(lua_State* L) {
lua_createtable(L, 0, 16);
Expand All @@ -52,18 +38,11 @@ namespace bee::lua_platform {
lua_pushstring(L, "ios");
#elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
lua_pushstring(L, "macos");
#elif defined(__EMSCRIPTEN__)
lua_pushstring(L, "emscripten");
#else
lua_pushstring(L, "unknown");
#endif
lua_setfield(L, -2, "os");

#if defined(__EMSCRIPTEN__)
lua_pushboolean(L, wasm_posix_host());
lua_setfield(L, -2, "wasm_posix_host");
#endif

#if defined(__clang__)
// clang defines __GNUC__ or _MSC_VER
lua_pushstring(L, "clang");
Expand Down
84 changes: 0 additions & 84 deletions compile/emcc.lua

This file was deleted.

5 changes: 0 additions & 5 deletions make.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
local lm = require "luamake"

if lm.compiler == "emcc" then
lm:import 'compile/emcc.lua'
return
end

lm.compile_commands = "$builddir"

if lm.EXE == "lua" then
Expand Down
Loading

0 comments on commit ab4994b

Please sign in to comment.