gsize remain = len, r;
gboolean first = TRUE;
gconstpointer self = NULL;
- gint i, tpos;
+ gint i, tpos, last_seq = -1;
if (!lua_istable (L, pos) || remain == 0) {
return 0;
break;
}
+ last_seq = i;
+
if (!first) {
r = rspamd_snprintf (d, remain + 1, ", ");
MOVE_BUF(d, remain, r);
/* 'key' is at index -2 and 'value' is at index -1 */
if (lua_type (L, -2) == LUA_TNUMBER) {
- continue;
+ if (last_seq > 0) {
+ lua_pushvalue (L, -2);
+
+ if (lua_tonumber (L, -1) <= last_seq + 1) {
+ lua_pop (L, 1);
+ /* Already seen */
+ continue;
+ }
+
+ lua_pop (L, 1);
+ }
}
if (!first) {
MOVE_BUF(d, remain, r);
}
+ /* Preserve key */
+ lua_pushvalue (L, -2);
r = rspamd_snprintf (d, remain + 1, "[%s] = ",
- lua_tostring (L, -2));
+ lua_tostring (L, -1));
+ lua_pop (L, 1); /* Remove key */
MOVE_BUF(d, remain, r);
tpos = lua_gettop (L);