aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2021-02-06 11:14:25 -0500
committerXavier Claessens <xclaesse@gmail.com>2021-03-16 20:50:16 -0400
commita45f939092cc2c60d49040bdb0147758a1403f61 (patch)
tree76db6837f0ca5cf9a0546f80a8a88dc7a79d24bb /docs
parent6415453f17f85e16d1d2ca3553325b769d0f124d (diff)
downloadmeson-a45f939092cc2c60d49040bdb0147758a1403f61.zip
meson-a45f939092cc2c60d49040bdb0147758a1403f61.tar.gz
meson-a45f939092cc2c60d49040bdb0147758a1403f61.tar.bz2
Add range() function
Fixes: #5026.
Diffstat (limited to 'docs')
-rw-r--r--docs/markdown/Reference-manual.md30
-rw-r--r--docs/markdown/snippets/range.md28
2 files changed, 58 insertions, 0 deletions
diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md
index 3af00c4..a70c94b 100644
--- a/docs/markdown/Reference-manual.md
+++ b/docs/markdown/Reference-manual.md
@@ -1861,6 +1861,36 @@ which to build the targets.
If you desire more specific behavior than what this command provides,
you should use `custom_target`.
+### range()
+
+``` meson
+ rangeobject range(stop)
+ rangeobject range(start, stop[, step])
+```
+
+*Since 0.58.0*
+
+Return an opaque object that can be only be used in `foreach` statements.
+- `start` must be integer greater or equal to 0. Defaults to 0.
+- `stop` must be integer greater or equal to `start`.
+- `step` must be integer greater or equal to 1. Defaults to 1.
+
+It cause the `foreach` loop to be called with the value from `start` included
+to `stop` excluded with an increment of `step` after each loop.
+
+```meson
+# Loop 15 times with i from 0 to 14 included.
+foreach i : range(15)
+ ...
+endforeach
+```
+
+The range object can also be assigned to a variable and indexed.
+```meson
+r = range(5, 10, 2)
+assert(r[2] == 9)
+```
+
## Built-in objects
These are built-in objects that are always available.
diff --git a/docs/markdown/snippets/range.md b/docs/markdown/snippets/range.md
new file mode 100644
index 0000000..77635d6
--- /dev/null
+++ b/docs/markdown/snippets/range.md
@@ -0,0 +1,28 @@
+## New `range()` function
+
+``` meson
+ rangeobject range(stop)
+ rangeobject range(start, stop[, step])
+```
+
+Return an opaque object that can be only be used in `foreach` statements.
+- `start` must be integer greater or equal to 0. Defaults to 0.
+- `stop` must be integer greater or equal to `start`.
+- `step` must be integer greater or equal to 1. Defaults to 1.
+
+It cause the `foreach` loop to be called with the value from `start` included
+to `stop` excluded with an increment of `step` after each loop.
+
+```meson
+# Loop 15 times with i from 0 to 14 included.
+foreach i : range(15)
+ ...
+endforeach
+```
+
+The range object can also be assigned to a variable and indexed.
+```meson
+r = range(5, 10, 2)
+assert(r[2] == 9)
+```
+