summaryrefslogtreecommitdiff
path: root/src/tangara/lua/lua_database.cpp
diff options
context:
space:
mode:
authorailurux <ailuruxx@gmail.com>2025-02-11 11:02:04 +1100
committerailurux <ailuruxx@gmail.com>2025-02-11 11:02:04 +1100
commitfff980a979aa6be6ad5697f73017a2da6649de86 (patch)
treee456a352e2ed126371921143589c56491607bbef /src/tangara/lua/lua_database.cpp
parent90b302a9f4677502935564be51c060fb98cc765b (diff)
downloadtangara-fw-fff980a979aa6be6ad5697f73017a2da6649de86.tar.gz
Fix bug in infinite list causing items to be removed (#253)
Diffstat (limited to 'src/tangara/lua/lua_database.cpp')
-rw-r--r--src/tangara/lua/lua_database.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/tangara/lua/lua_database.cpp b/src/tangara/lua/lua_database.cpp
index 928dbc39..a49f3d07 100644
--- a/src/tangara/lua/lua_database.cpp
+++ b/src/tangara/lua/lua_database.cpp
@@ -250,6 +250,19 @@ static auto db_iterate(lua_State* state) -> int {
return 1;
}
+static auto db_iterator_value(lua_State* state) -> int {
+ database::Iterator* it = db_check_iterator(state, 1);
+ std::optional<database::Record> res = it->value();
+
+ if (res) {
+ push_lua_record(state, *res);
+ } else {
+ lua_pushnil(state);
+ }
+
+ return 1;
+}
+
static auto db_iterator_clone(lua_State* state) -> int {
database::Iterator* it = db_check_iterator(state, 1);
push_iterator(state, *it);
@@ -265,7 +278,8 @@ 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}, {NULL, NULL}};
+ {"__gc", db_iterator_gc}, {"value", db_iterator_value},
+ {NULL, NULL}};
static auto record_text(lua_State* state) -> int {
database::Record* rec = db_check_record(state, 1);