Skip to content

Commit

Permalink
add directory_entry::file_size
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Oct 18, 2023
1 parent a61d923 commit 86300b3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions binding/lua_filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,18 @@ namespace bee::lua_filesystem {
return 1;
}

static lua::cxx::status file_size(lua_State* L) {
using namespace std::chrono;
const auto& entry = to(L, 1);
std::error_code ec;
auto size = entry.file_size(ec);
if (ec) {
return pusherror(L, "directory_entry::file_size", ec);
}
lua_pushinteger(L, static_cast<lua_Integer>(size));
return 1;
}

static void metatable(lua_State* L) {
static luaL_Reg lib[] = {
{ "path", path },
Expand All @@ -588,6 +600,7 @@ namespace bee::lua_filesystem {
{ "is_directory", is_directory },
{ "is_regular_file", is_regular_file },
{ "last_write_time", lua::cxx::cfunc<last_write_time> },
{ "file_size", lua::cxx::cfunc<file_size> },
{ NULL, NULL },
};
luaL_newlibtable(L, lib);
Expand Down

0 comments on commit 86300b3

Please sign in to comment.