|
|
|
@ -38,22 +38,22 @@ auto check_file_entry(lua_State* L, int stack_pos) -> lua::FileEntry* { |
|
|
|
|
return entry; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto check_file_iterator(lua_State* L, int stack_pos) -> lua::FileIterator* { |
|
|
|
|
lua::FileIterator* it = *reinterpret_cast<lua::FileIterator**>( |
|
|
|
|
auto check_file_iterator(lua_State* L, int stack_pos) -> lua::FileIteratorSorted* { |
|
|
|
|
lua::FileIteratorSorted* it = *reinterpret_cast<lua::FileIteratorSorted**>( |
|
|
|
|
luaL_checkudata(L, stack_pos, kFileIteratorMetatable)); |
|
|
|
|
return it; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static auto push_iterator(lua_State* state, const lua::FileIterator& it) |
|
|
|
|
static auto push_iterator(lua_State* state, const lua::FileIteratorSorted& it) |
|
|
|
|
-> void { |
|
|
|
|
lua::FileIterator** data = reinterpret_cast<lua::FileIterator**>( |
|
|
|
|
lua::FileIteratorSorted** data = reinterpret_cast<lua::FileIteratorSorted**>( |
|
|
|
|
lua_newuserdata(state, sizeof(uintptr_t))); |
|
|
|
|
*data = new lua::FileIterator(it); |
|
|
|
|
*data = new lua::FileIteratorSorted(it); |
|
|
|
|
luaL_setmetatable(state, kFileIteratorMetatable); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static auto fs_iterate_prev(lua_State* state) -> int { |
|
|
|
|
lua::FileIterator* it = check_file_iterator(state, 1); |
|
|
|
|
lua::FileIteratorSorted* it = check_file_iterator(state, 1); |
|
|
|
|
it->prev(); |
|
|
|
|
std::optional<lua::FileEntry> res = it->value(); |
|
|
|
|
|
|
|
|
@ -67,7 +67,7 @@ static auto fs_iterate_prev(lua_State* state) -> int { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static auto fs_iterate(lua_State* state) -> int { |
|
|
|
|
lua::FileIterator* it = check_file_iterator(state, 1); |
|
|
|
|
lua::FileIteratorSorted* it = check_file_iterator(state, 1); |
|
|
|
|
it->next(); |
|
|
|
|
std::optional<lua::FileEntry> res = it->value(); |
|
|
|
|
|
|
|
|
@ -81,13 +81,13 @@ static auto fs_iterate(lua_State* state) -> int { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static auto fs_iterator_clone(lua_State* state) -> int { |
|
|
|
|
lua::FileIterator* it = check_file_iterator(state, 1); |
|
|
|
|
lua::FileIteratorSorted* it = check_file_iterator(state, 1); |
|
|
|
|
push_iterator(state, *it); |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static auto fs_iterator_value(lua_State* state) -> int { |
|
|
|
|
lua::FileIterator* it = check_file_iterator(state, 1); |
|
|
|
|
lua::FileIteratorSorted* it = check_file_iterator(state, 1); |
|
|
|
|
std::optional<lua::FileEntry> res = it->value(); |
|
|
|
|
|
|
|
|
|
if (res) { |
|
|
|
@ -100,7 +100,7 @@ static auto fs_iterator_value(lua_State* state) -> int { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static auto fs_iterator_gc(lua_State* state) -> int { |
|
|
|
|
lua::FileIterator* it = check_file_iterator(state, 1); |
|
|
|
|
lua::FileIteratorSorted* it = check_file_iterator(state, 1); |
|
|
|
|
delete it; |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
@ -155,7 +155,7 @@ 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); |
|
|
|
|
lua::FileIterator iter(filepath, false); |
|
|
|
|
lua::FileIteratorSorted iter(filepath, false); |
|
|
|
|
push_iterator(state, iter); |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|