Mercurial > vim
diff src/if_lua.c @ 21060:89aba7895bb2 v8.2.1081
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Commit: https://github.com/vim/vim/commit/a1f9f8666ed3a462eb8a518e78418c57dc41bbd4
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 28 22:41:26 2020 +0200
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Problem: Lua: cannot use table.insert() and table.remove().
Solution: Add the list functions. (Prabir Shrestha, closes https://github.com/vim/vim/issues/6353)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 28 Jun 2020 22:45:04 +0200 |
parents | 08e284594211 |
children | 43e82e8133b9 |
line wrap: on
line diff
--- 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; }