mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2025-01-19 17:46:46 +02:00
nix_api_value: add nix_get_attr_name_byidx get attr names without forcing
This commit is contained in:
parent
9cccb8bae0
commit
e891aac2e4
2 changed files with 28 additions and 0 deletions
|
@ -266,6 +266,18 @@ Value *nix_get_attr_byidx(nix_c_context *context, const Value *value,
|
|||
NIXC_CATCH_ERRS_NULL
|
||||
}
|
||||
|
||||
const char *nix_get_attr_name_byidx(nix_c_context *context, const Value *value,
|
||||
State *state, unsigned int i) {
|
||||
if (context)
|
||||
context->last_err_code = NIX_OK;
|
||||
try {
|
||||
auto &v = check_value_not_null(value);
|
||||
const nix::Attr &a = (*v.attrs)[i];
|
||||
return ((const std::string &)(state->state.symbols[a.name])).c_str();
|
||||
}
|
||||
NIXC_CATCH_ERRS_NULL
|
||||
}
|
||||
|
||||
nix_err nix_set_bool(nix_c_context *context, Value *value, bool b) {
|
||||
if (context)
|
||||
context->last_err_code = NIX_OK;
|
||||
|
|
|
@ -207,6 +207,8 @@ bool nix_has_attr_byname(nix_c_context *context, const Value *value,
|
|||
State *state, const char *name);
|
||||
|
||||
/** @brief Get an attribute by index in the sorted bindings
|
||||
*
|
||||
* Also gives you the name.
|
||||
*
|
||||
* Owned by the GC. Use nix_gc_decref when you're done with the pointer
|
||||
* @param[out] context Optional, stores error information
|
||||
|
@ -218,6 +220,20 @@ bool nix_has_attr_byname(nix_c_context *context, const Value *value,
|
|||
*/
|
||||
Value *nix_get_attr_byidx(nix_c_context *context, const Value *value,
|
||||
State *state, unsigned int i, const char **name);
|
||||
|
||||
/** @brief Get an attribute name by index in the sorted bindings
|
||||
*
|
||||
* Useful when you want the name but want to avoid evaluation.
|
||||
*
|
||||
* Owned by the nix State
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @param[in] state nix evaluator state
|
||||
* @param[in] i attribute index
|
||||
* @return name, NULL in case of errors
|
||||
*/
|
||||
const char *nix_get_attr_name_byidx(nix_c_context *context, const Value *value,
|
||||
State *state, unsigned int i);
|
||||
/**@}*/
|
||||
/** @name Setters
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue