diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-06-28 22:41:26 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-06-28 22:41:26 +0200 |
commit | a1f9f8666ed3a462eb8a518e78418c57dc41bbd4 (patch) | |
tree | de92931b3cc7d3a9399c872447789c753f005d33 /runtime | |
parent | b7a78f7a6713f07d2fcad0b27dea22925c7b1cdf (diff) | |
download | vim-git-a1f9f8666ed3a462eb8a518e78418c57dc41bbd4.tar.gz |
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()v8.2.1081
Problem: Lua: cannot use table.insert() and table.remove().
Solution: Add the list functions. (Prabir Shrestha, closes #6353)
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/if_lua.txt | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/runtime/doc/if_lua.txt b/runtime/doc/if_lua.txt index f32be7c37..214179641 100644 --- a/runtime/doc/if_lua.txt +++ b/runtime/doc/if_lua.txt @@ -227,8 +227,17 @@ Properties in Vim. o "l[k]" returns the k-th item in "l"; "l" is one-indexed, as in Lua. To modify the k-th item, simply do "l[k] = newitem"; in - particular, "l[k] = nil" removes the k-th item from "l". + particular, "l[k] = nil" removes the k-th item from "l". Item can + be added to the end of the list by "l[#l + 1] = newitem" o "l()" returns an iterator for "l". + o "table.insert(l, newitem)" inserts an item at the end of the list. + (only Lua 5.3 and later) + o "table.insert(l, position, newitem)" inserts an item at the + specified position. "position" is one-indexed. (only Lua 5.3 and + later) + o "table.remove(l, position)" removes an item at the specified + position. "position" is one-indexed. + Methods ------- @@ -246,8 +255,11 @@ Examples: :lua l[1] = nil -- remove first item :lua l:insert(true, 1) :lua print(l, #l, l[1], l[2]) + :lua l[#l + 1] = 'value' + :lua table.insert(l, 100) + :lua table.insert(l, 2, 200) + :lua table.remove(l, 1) :lua for item in l() do print(item) end -< ============================================================================== 4. Dict userdata *lua-dict* |