feat(nix/eval): Implement builtins.functionArgs
Now that we're tracking formals on Lambda this ends up being quite easy; we just pull them off of the Lambda for the argument closure and use them to construct the result attribute set. Change-Id: I811cb61ec34c6bef123a4043000b18c0e4ea0125 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7003 Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
This commit is contained in:
parent
2a3d498104
commit
0063e7e913
4 changed files with 100 additions and 0 deletions
|
@ -273,6 +273,21 @@ fn pure_builtins() -> Vec<Builtin> {
|
|||
Ok(res)
|
||||
},
|
||||
),
|
||||
Builtin::new("functionArgs", &[true], |args: Vec<Value>, _: &mut VM| {
|
||||
let lambda = args[0].to_closure()?.lambda();
|
||||
let formals = if let Some(formals) = &lambda.formals {
|
||||
formals
|
||||
} else {
|
||||
return Ok(Value::attrs(NixAttrs::empty()));
|
||||
};
|
||||
Ok(Value::attrs(NixAttrs::from_map(
|
||||
formals
|
||||
.arguments
|
||||
.iter()
|
||||
.map(|(k, v)| (k.clone(), (*v).into()))
|
||||
.collect(),
|
||||
)))
|
||||
}),
|
||||
Builtin::new("fromJSON", &[true], |args: Vec<Value>, _: &mut VM| {
|
||||
let json_str = args[0].to_str()?;
|
||||
let json: serde_json::Value = serde_json::from_str(&json_str)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue