diff options
Diffstat (limited to 'src/if_lua.c')
-rw-r--r-- | src/if_lua.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/if_lua.c b/src/if_lua.c index 2d02f7c58..c5fc68321 100644 --- a/src/if_lua.c +++ b/src/if_lua.c @@ -913,19 +913,32 @@ luaV_list_newindex(lua_State *L) if (l->lv_lock) luaL_error(L, "list is locked"); li = list_find(l, n); - if (li == NULL) return 0; - if (lua_isnil(L, 3)) // remove? + if (li == NULL) { - vimlist_remove(l, li, li); - listitem_free(l, li); + if (!lua_isnil(L, 3)) + { + typval_T v; + luaV_checktypval(L, 3, &v, "inserting list item"); + if (list_insert_tv(l, &v, li) == FAIL) + luaL_error(L, "failed to add item to list"); + clear_tv(&v); + } } else { - typval_T v; - luaV_checktypval(L, 3, &v, "setting list item"); - clear_tv(&li->li_tv); - copy_tv(&v, &li->li_tv); - clear_tv(&v); + if (lua_isnil(L, 3)) // remove? + { + vimlist_remove(l, li, li); + listitem_free(l, li); + } + else + { + typval_T v; + luaV_checktypval(L, 3, &v, "setting list item"); + clear_tv(&li->li_tv); + copy_tv(&v, &li->li_tv); + clear_tv(&v); + } } return 0; } |