Minor fixes before PR

custom
ailurux 12 months ago
parent 0062eb9a9e
commit e06610f3a6
  1. 4
      src/tangara/lua/file_iterator.cpp
  2. 4
      src/tangara/lua/file_iterator.hpp
  3. 30
      src/tangara/lua/lua_filesystem.cpp
  4. 2
      src/tangara/lua/lua_filesystem.hpp

@ -11,7 +11,7 @@
#include "ff.h"
#include "drivers/spi.hpp"
namespace database {
namespace lua {
[[maybe_unused]] static const char* kTag = "FileIterator";
@ -84,4 +84,4 @@ auto FileIterator::iterate(bool reverse) -> bool {
return true;
}
} // namespace database
} // namespace lua

@ -11,7 +11,7 @@
#include "ff.h"
namespace database {
namespace lua {
// Note for when reading FILINFO, that we are in LFN mode:
// http://elm-chan.org/fsw/ff/doc/sfileinfo.html
@ -42,4 +42,4 @@ class FileIterator {
auto iterate(bool reverse = false) -> bool;
};
} // namespace database
} // namespace lua

@ -28,7 +28,7 @@ struct LuaFileEntry {
static_assert(std::is_trivially_destructible<LuaFileEntry>());
static_assert(std::is_trivially_copy_assignable<LuaFileEntry>());
static auto push_lua_file_entry(lua_State* L, const database::FileEntry& r) -> void {
static auto push_lua_file_entry(lua_State* L, const lua::FileEntry& r) -> void {
// Create and init the userdata.
LuaFileEntry* file_entry = reinterpret_cast<LuaFileEntry*>(
lua_newuserdata(L, sizeof(LuaFileEntry) + r.filepath.size()));
@ -46,24 +46,24 @@ static auto push_lua_file_entry(lua_State* L, const database::FileEntry& r) -> v
std::memcpy(file_entry->path, r.filepath.data(), r.filepath.size());
}
auto check_file_iterator(lua_State* L, int stack_pos) -> database::FileIterator* {
database::FileIterator* it = *reinterpret_cast<database::FileIterator**>(
auto check_file_iterator(lua_State* L, int stack_pos) -> lua::FileIterator* {
lua::FileIterator* it = *reinterpret_cast<lua::FileIterator**>(
luaL_checkudata(L, stack_pos, kFileIteratorMetatable));
return it;
}
static auto push_iterator(lua_State* state, const database::FileIterator& it)
static auto push_iterator(lua_State* state, const lua::FileIterator& it)
-> void {
database::FileIterator** data = reinterpret_cast<database::FileIterator**>(
lua::FileIterator** data = reinterpret_cast<lua::FileIterator**>(
lua_newuserdata(state, sizeof(uintptr_t)));
*data = new database::FileIterator(it); // TODO...
*data = new lua::FileIterator(it); // TODO...
luaL_setmetatable(state, kFileIteratorMetatable);
}
static auto fs_iterate_prev(lua_State* state) -> int {
database::FileIterator* it = check_file_iterator(state, 1);
lua::FileIterator* it = check_file_iterator(state, 1);
it->prev();
std::optional<database::FileEntry> res = it->value();
std::optional<lua::FileEntry> res = it->value();
if (res) {
push_lua_file_entry(state, *res);
@ -75,9 +75,9 @@ static auto fs_iterate_prev(lua_State* state) -> int {
}
static auto fs_iterate(lua_State* state) -> int {
database::FileIterator* it = check_file_iterator(state, 1);
lua::FileIterator* it = check_file_iterator(state, 1);
it->next();
std::optional<database::FileEntry> res = it->value();
std::optional<lua::FileEntry> res = it->value();
if (res) {
push_lua_file_entry(state, *res);
@ -89,13 +89,13 @@ static auto fs_iterate(lua_State* state) -> int {
}
static auto fs_iterator_clone(lua_State* state) -> int {
database::FileIterator* it = check_file_iterator(state, 1);
lua::FileIterator* it = check_file_iterator(state, 1);
push_iterator(state, *it);
return 1;
}
static auto fs_iterator_gc(lua_State* state) -> int {
database::FileIterator* it = check_file_iterator(state, 1);
lua::FileIterator* it = check_file_iterator(state, 1);
delete it;
return 0;
}
@ -146,12 +146,12 @@ static auto fs_new_iterator(lua_State* state) -> int {
// Takes a filepath as a string and returns a new FileIterator
// on that directory
std::string filepath = luaL_checkstring(state, -1);
database::FileIterator iter(filepath);
lua::FileIterator iter(filepath);
push_iterator(state, iter);
return 1;
}
static const struct luaL_Reg kDatabaseFuncs[] = {{"iterator", fs_new_iterator},
static const struct luaL_Reg kFilesystemFuncs[] = {{"iterator", fs_new_iterator},
{NULL, NULL}};
static auto lua_filesystem(lua_State* state) -> int {
@ -167,7 +167,7 @@ static auto lua_filesystem(lua_State* state) -> int {
lua_settable(state, -3); // metatable.__index = metatable
luaL_setfuncs(state, kFileEntryFuncs, 0);
luaL_newlib(state, kDatabaseFuncs);
luaL_newlib(state, kFilesystemFuncs);
return 1;
}

@ -10,7 +10,7 @@
namespace lua {
auto check_file_iterator(lua_State*, int stack_pos) -> database::FileIterator*;
auto check_file_iterator(lua_State*, int stack_pos) -> lua::FileIterator*;
auto RegisterFileSystemModule(lua_State*) -> void;

Loading…
Cancel
Save