diff options
author | sterni <sternenseemann@systemli.org> | 2022-09-21T20·30+0200 |
---|---|---|
committer | sterni <sternenseemann@systemli.org> | 2022-09-22T23·12+0000 |
commit | bd9cda2af7d9fd8064b719e9135b3a48cf13c36a (patch) | |
tree | 5336390df5974d4009ef48b0f56121e0eea36bad /tvix/eval/src/builtins | |
parent | 64d3efcc2ce055ffe45034ed169569ece961f04d (diff) |
feat(tvix/eval): add builtins.stringLength r/4961
Fairly straightforward, only thing of note is that we coerce (weakly) to string here as well. Change-Id: I03b427e657e402f1f9eb0f795b689bbf5092aba1 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6745 Tested-by: BuildkiteCI Reviewed-by: wpcarro <wpcarro@gmail.com> Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix/eval/src/builtins')
-rw-r--r-- | tvix/eval/src/builtins/mod.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index 1a6155a82352..872033648aff 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -234,6 +234,11 @@ fn pure_builtins() -> Vec<Builtin> { .collect::<Vec<Value>>(); Ok(Value::List(NixList::construct(parts.len(), parts))) }), + Builtin::new("stringLength", &[false], |args, vm| { + // also forces the value + let s = args[0].coerce_to_string(CoercionKind::Weak, vm)?; + Ok(Value::Integer(s.as_str().len() as i64)) + }), Builtin::new( "sub", &[false, false], |