about summary refs log tree commit diff
path: root/tvix/eval/src/builtins
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/builtins')
-rw-r--r--tvix/eval/src/builtins/mod.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index f6af16f96f9d..9714c96d05d8 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -131,6 +131,17 @@ fn pure_builtins() -> Vec<Builtin> {
                 }
             }
         }),
+        Builtin::new("getAttr", &[true, true], |args, _| {
+            let k = args[0].to_str()?;
+            let xs = args[1].to_attrs()?;
+
+            match xs.select(k.as_str()) {
+                Some(x) => Ok(x.clone()),
+                None => Err(ErrorKind::AttributeNotFound {
+                    name: k.to_string(),
+                }),
+            }
+        }),
         Builtin::new("length", &[true], |args, _| {
             Ok(Value::Integer(args[0].to_list()?.len() as i64))
         }),