1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-04 15:31:47 +02:00

Add EvalState::getBuiltins

This commit is contained in:
Robert Hensing 2024-11-19 18:23:05 +01:00
parent a58e38dab7
commit 8a36d2d8a7
4 changed files with 43 additions and 2 deletions

View file

@ -523,13 +523,19 @@ Value * EvalState::addPrimOp(PrimOp && primOp)
}
Value & EvalState::getBuiltins()
{
return *baseEnv.values[0];
}
Value & EvalState::getBuiltin(const std::string & name)
{
auto it = baseEnv.values[0]->attrs()->get(symbols.create(name));
if (it)
return *it->value;
else
throw EvalError("builtin '%1%' not found", name);
error<EvalError>("builtin '%1%' not found", name).debugThrow();
}

View file

@ -630,6 +630,12 @@ public:
*/
Value & getBuiltin(const std::string & name);
/**
* Retrieve the `builtins` attrset, equivalent to evaluating the reference `builtins`.
* Always returns an attribute set value.
*/
Value & getBuiltins();
struct Doc
{
Pos pos;