aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorAlbert Krewinkel <[email protected]>2024-09-21 08:54:05 +0200
committerAlbert Krewinkel <[email protected]>2024-09-21 10:10:35 +0200
commit05aa18420ff83ccdd03d9956b0ff65e659198826 (patch)
treebeaaf131ed5793d0522676ee6102aa43d2804d48 /doc
parent5ccf380dadec2a4b9323b2a2d2aa6efd8e7b0b03 (diff)
Lua: update List module
The module now comes with a method `:at(index[, def])` that allows to access indices, accepts negative indices to count from the end, and will return the `def` value as a default if the list has no item at the given position. Furthermore, the list constructor `pandoc.List` now accepts iterators. E.g., `pandoc.List(text:gmatch '%S+')` returns the list of words in `text`. Closes: #9835
Diffstat (limited to 'doc')
-rw-r--r--doc/lua-filters.md25
1 files changed, 25 insertions, 0 deletions
diff --git a/doc/lua-filters.md b/doc/lua-filters.md
index 9de10cfbf..f445f6327 100644
--- a/doc/lua-filters.md
+++ b/doc/lua-filters.md
@@ -4578,6 +4578,28 @@ Returns:
## Methods
+### `pandoc.List:at` {#pandoc.list:at}
+
+`:at (index[, default])`
+
+Returns the element at the given index, or `default` if the list
+contains no item at the given position.
+
+Negative integers count back from the last item in the list.
+
+Parameters:
+
+`index`
+: element position (integer)
+
+`default`
+: the default value that is returned if the index is out of
+ range (any)
+
+Returns:
+
+- the list item at `index`, or `default`.
+
### `pandoc.List:clone ()` {#pandoc.list:clone}
Returns a (shallow) copy of the list. (To get a deep copy
@@ -4683,6 +4705,9 @@ Parameters:
Create a new List. If the optional argument `table` is given,
set the metatable of that value to `pandoc.List`.
+The function also accepts an iterator, in which case it creates a
+new list from the return values of the iterator function.
+
Parameters:
`table`