if (hc != NULL) {
lua_newtable (L);
- if (hc->images) {
+ if (hc->images && hc->images->len > 0) {
for (i = 0; i < hc->images->len; i ++) {
img = g_ptr_array_index (hc->images, i);
lua_html_push_image (L, img);
lua_rawseti (L, -2, i + 1);
}
}
+ else {
+ lua_pushnil (L);
+ }
}
else {
lua_pushnil (L);
if (hc != NULL) {
lua_newtable (L);
- if (hc->blocks) {
+ if (hc->blocks && hc->blocks->len > 0) {
for (i = 0; i < hc->blocks->len; i ++) {
bl = g_ptr_array_index (hc->blocks, i);
lua_rawseti (L, -2, i + 1);
}
}
+ else {
+ lua_pushnil (L);
+ }
}
else {
lua_pushnil (L);
if (task) {
cur = task->images;
- lua_newtable (L);
+ if (cur) {
+ lua_newtable (L);
- while (cur) {
- pimg = lua_newuserdata (L, sizeof (struct rspamd_image *));
- rspamd_lua_setclass (L, "rspamd{image}", -1);
- *pimg = cur->data;
- lua_rawseti (L, -2, i++);
- cur = g_list_next (cur);
+ while (cur) {
+ pimg = lua_newuserdata (L, sizeof (struct rspamd_image *));
+ rspamd_lua_setclass (L, "rspamd{image}", -1);
+ *pimg = cur->data;
+ lua_rawseti (L, -2, i++);
+ cur = g_list_next (cur);
+ }
+ }
+ else {
+ /* Return nil if there are no images to preserve compatibility */
+ lua_pushnil (L);
}
}
else {