New range variant.
This commit is contained in:
parent
0555069de0
commit
a12401a1fe
@ -16,6 +16,7 @@ Enhancements
|
||||
|
||||
* `switch` cases can now include multiple values separated by `|`.
|
||||
* `EvalContext::eval_expression_tree_raw` and `Expression::eval_with_context_raw` are added to allow for not rewinding the `Scope` at the end of a statements block.
|
||||
* A new `range` function variant that takes an exclusive range with a step.
|
||||
|
||||
|
||||
Version 1.8.0
|
||||
|
@ -287,7 +287,7 @@ macro_rules! reg_range {
|
||||
"/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`.",
|
||||
"/// The value `to` is never included.",
|
||||
"///",
|
||||
"/// If `from` > `to` and `step` < 0, the iteration goes backwards.",
|
||||
"/// If `from` > `to` and `step` < 0, iteration goes backwards.",
|
||||
"///",
|
||||
"/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned.",
|
||||
"///",
|
||||
@ -305,6 +305,35 @@ macro_rules! reg_range {
|
||||
"/// }",
|
||||
"/// ```"
|
||||
]);
|
||||
|
||||
let _hash = $lib.set_native_fn($x, |range: std::ops::Range<$y>, step: $y| StepRange::new(range.start, range.end, step, $add));
|
||||
|
||||
#[cfg(feature = "metadata")]
|
||||
$lib.update_fn_metadata_with_comments(_hash, [
|
||||
concat!("range: Range<", stringify!($y), ">"),
|
||||
concat!("step: ", stringify!($y)),
|
||||
concat!("Iterator<Item=", stringify!($y), ">")
|
||||
], [
|
||||
"/// Return an iterator over an exclusive range, each iteration increasing by `step`.",
|
||||
"///",
|
||||
"/// If `range` is reversed and `step` < 0, iteration goes backwards.",
|
||||
"///",
|
||||
"/// Otherwise, if `range` is empty, an empty iterator is returned.",
|
||||
"///",
|
||||
"/// # Example",
|
||||
"///",
|
||||
"/// ```rhai",
|
||||
"/// // prints all values from 8 to 17 in steps of 3",
|
||||
"/// for n in range(8..18, 3) {",
|
||||
"/// print(n);",
|
||||
"/// }",
|
||||
"///",
|
||||
"/// // prints all values down from 18 to 9 in steps of -3",
|
||||
"/// for n in range(18..8, -3) {",
|
||||
"/// print(n);",
|
||||
"/// }",
|
||||
"/// ```"
|
||||
]);
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user