From 302d3cfb96d7f0c856262e1a4252d058e3300c8b Mon Sep 17 00:00:00 2001 From: Mathias Fußenegger Date: Sat, 10 Jun 2023 20:33:23 +0200 Subject: feat(lua): use callable table as iterator in vim.iter (#23957) A table passed to `vim.iter` can be a class instance with a `__call` implementation for the iterator protocol. --- runtime/doc/lua.txt | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'runtime/doc') diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index 91d18bbe85..44682d40e5 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -2999,6 +2999,8 @@ pipeline depend on the type passed to this function: • Non-list tables pass both the key and value of each element • Function iterators pass all of the values returned by their respective function +• Tables with a metatable implementing __call are treated as function + iterators Examples: >lua @@ -3032,6 +3034,12 @@ Examples: >lua end) -- true + local rb = vim.ringbuf(3) + rb:push("a") + rb:push("b") + vim.iter(rb):totable() + -- { "a", "b" } + < In addition to the |vim.iter()| function, the |vim.iter| module provides -- cgit