From a1f9f8666ed3a462eb8a518e78418c57dc41bbd4 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sun, 28 Jun 2020 22:41:26 +0200 Subject: 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 #6353) --- runtime/doc/if_lua.txt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/if_lua.txt b/runtime/doc/if_lua.txt index f32be7c379..214179641d 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* -- cgit v1.2.3