diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/if_lua.c | 31 | ||||
-rw-r--r-- | src/testdir/test_lua.vim | 26 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 50 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; } diff --git a/src/testdir/test_lua.vim b/src/testdir/test_lua.vim index 9d5ad6864..e1ad5004b 100644 --- a/src/testdir/test_lua.vim +++ b/src/testdir/test_lua.vim @@ -353,6 +353,32 @@ func Test_lua_list_table() call assert_fails('lua vim.list(true)', '[string "vim chunk"]:1: table expected, got boolean') endfunc +func Test_lua_list_table_insert_remove() + let luaver = split(split(luaeval('_VERSION'), ' ')[1], '\.') + let major = str2nr(luaver[0]) + let minor = str2nr(luaver[1]) + + if major < 5 || (major == 5 && minor < 3) + throw 'Skipped: Lua version < 5.3' + endif + + let l = [1, 2] + lua t = vim.eval('l') + lua table.insert(t, 10) + lua t[#t + 1] = 20 + lua table.insert(t, 2, 30) + call assert_equal(l, [1, 30, 2, 10, 20]) + lua table.remove(t, 2) + call assert_equal(l, [1, 2, 10, 20]) + lua t[3] = nil + call assert_equal(l, [1, 2, 20]) + lua removed_value = table.remove(t, 3) + call assert_equal(luaeval('removed_value'), 20) + lua t = nil + lua removed_value = nil + unlet l +endfunc + " Test l() i.e. iterator on list func Test_lua_list_iter() lua l = vim.list():add('foo'):add('bar') diff --git a/src/version.c b/src/version.c index 0c24515bc..69c89ff44 100644 --- a/src/version.c +++ b/src/version.c @@ -755,6 +755,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1081, +/**/ 1080, /**/ 1079, |