commit 0646180c6783e78fa6f037ae02020639156fb525
parent 7ad515d7a439b10c896198c8baf67235926bd157
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date: Tue, 2 Sep 2025 17:55:10 +0000
Emptiness checks of tables with index are corrected
Diffstat:
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/natsbot.go b/natsbot.go
@@ -70,7 +70,7 @@ func Loop(cb NatsBot, mainScript string, capacity int) {
runTimers(L, timer)
- if tableIsEmpty(stateConnTable(L)) && tableIsEmpty(stateTimerTable(L)) {
+ if tableWithIndexIsEmpty(stateConnTable(L)) && tableIsEmpty(stateTimerTable(L)) {
break
}
}
@@ -621,3 +621,13 @@ func tableIsEmpty(t *lua.LTable) bool {
key, _ := t.Next(lua.LNil)
return key == lua.LNil
}
+
+func tableWithIndexIsEmpty(t *lua.LTable) bool {
+ key, _ := t.Next(lua.LNil)
+
+ if n, ok := key.(lua.LNumber); ok && n == lua.LNumber(keyIndex) {
+ key, _ = t.Next(key)
+ }
+
+ return key == lua.LNil
+}