summaryrefslogtreecommitdiff
path: root/src/lua
diff options
context:
space:
mode:
authorailurux <ailuruxx@gmail.com>2024-04-19 02:06:37 +0000
committercooljqln <cooljqln@noreply.codeberg.org>2024-04-19 02:06:37 +0000
commit7f630cebddcf6d0b8a31632af7ed617f4173a6e1 (patch)
tree617537d644ebbbe8315ab0f89ccef368ef5d78ab /src/lua
parentb17f8a3dcc36ec2479412f603c7b5e77003b80a2 (diff)
downloadtangara-fw-7f630cebddcf6d0b8a31632af7ed617f4173a6e1.tar.gz
daniel/recycler-list (#66)
@cooljqln should be good to merge to main, give it a look over though please? :) Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/66 Co-authored-by: ailurux <ailuruxx@gmail.com> Co-committed-by: ailurux <ailuruxx@gmail.com>
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_database.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/lua/lua_database.cpp b/src/lua/lua_database.cpp
index 57cefbbc..d0612fdd 100644
--- a/src/lua/lua_database.cpp
+++ b/src/lua/lua_database.cpp
@@ -160,6 +160,19 @@ static auto push_iterator(lua_State* state, const database::Iterator& it)
luaL_setmetatable(state, kDbIteratorMetatable);
}
+static auto db_iterate_prev(lua_State* state) -> int {
+ database::Iterator* it = db_check_iterator(state, 1);
+ std::optional<database::Record> res = (*it)--;
+
+ if (res) {
+ push_lua_record(state, *res);
+ } else {
+ lua_pushnil(state);
+ }
+
+ return 1;
+}
+
static auto db_iterate(lua_State* state) -> int {
database::Iterator* it = db_check_iterator(state, 1);
std::optional<database::Record> res = (*it)++;
@@ -186,6 +199,7 @@ static auto db_iterator_gc(lua_State* state) -> int {
}
static const struct luaL_Reg kDbIteratorFuncs[] = {{"next", db_iterate},
+ {"prev", db_iterate_prev},
{"clone", db_iterator_clone},
{"__call", db_iterate},
{"__gc", db_iterator_gc},