diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2020-01-11 20:35:56 +0100 |
---|---|---|
committer | Albert Krewinkel <albert@zeitkraut.de> | 2020-01-11 21:31:20 +0100 |
commit | 4ede11a75f37bb35d384fc9ce95231671e18acf3 (patch) | |
tree | 3cea18e0917625473d95ce9c02847a9bcbc93078 /doc | |
parent | 23d81081d0d69c59ee3861bb4b7fb132efa03d6b (diff) | |
download | pandoc-4ede11a75f37bb35d384fc9ce95231671e18acf3.tar.gz |
Lua: add methods `insert`, `remove`, and `sort` to pandoc.List
The functions `table.insert`, `table.remove`, and `table.sort` are added
to pandoc.List elements. They can be used as methods, e.g.
local numbers = pandoc.List {2, 3, 1}
numbers:sort() -- numbers is now {1, 2, 3}
Diffstat (limited to 'doc')
-rw-r--r-- | doc/lua-filters.md | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/doc/lua-filters.md b/doc/lua-filters.md index 3c4f1f0c8..729d12f86 100644 --- a/doc/lua-filters.md +++ b/doc/lua-filters.md @@ -2734,6 +2734,22 @@ methods and convenience functions. Returns: true if a list item is equal to the needle, false otherwise +[`pandoc.List:insert ([pos], value)`]{#pandoc.list:insert} + +: Inserts element `value` at position `pos` in list, shifting + elements to the next-greater indix if necessary. + + This function is identical to + [`table.insert`](https://www.lua.org/manual/5.3/manual.html#6.6). + + Parameters: + + `pos`: + : index of the new value; defaults to length of the list + 1 + + `value`: + : value to insert into the list + [`pandoc.List:map (fn)`]{#pandoc.list:map} : Returns a copy of the current list by applying the given @@ -2757,6 +2773,49 @@ methods and convenience functions. Returns: the updated input value +[`pandoc.List:remove ([pos])`]{#pandoc.list:remove} + +: Removes the element at position `pos`, returning the value + of the removed element. + + This function is identical to + [`table.remove`](https://www.lua.org/manual/5.3/manual.html#6.6). + + Parameters: + + `pos`: + : position of the list value that will be remove; defaults + to the index of the last element + + Returns: the removed element + +[`pandoc.List:sort ([comp])`]{#pandoc.list:sort} + +: Sorts list elements in a given order, in-place. If `comp` is + given, then it must be a function that receives two list + elements and returns true when the first element must come + before the second in the final order (so that, after the + sort, `i < j` implies `not comp(list[j],list[i]))`. If comp + is not given, then the standard Lua operator `<` is used + instead. + + Note that the comp function must define a strict partial + order over the elements in the list; that is, it must be + asymmetric and transitive. Otherwise, no valid sort may be + possible. + + The sort algorithm is not stable: elements considered equal + by the given order may have their relative positions changed + by the sort. + + This function is identical to + [`table.sort`](https://www.lua.org/manual/5.3/manual.html#6.6). + + Parameters: + + `comp`: + : Comparison function as described above. + # Module pandoc.system Access to system information and functionality. |