Nix 2.17.0
Nix, the purely functional package manager; stable external interfaces
Loading...
Searching...
No Matches
Manipulating values

Functions to inspect and change nix Value's. More...

Typedefs

typedef struct BindingsBuilder BindingsBuilder
 Stores an under-construction set of bindings. More...
 

Functions

BindingsBuildernix_make_bindings_builder (nix_c_context *context, State *state, size_t capacity)
 Create a bindings builder. More...
 
nix_err nix_bindings_builder_insert (nix_c_context *context, BindingsBuilder *builder, const char *name, Value *value)
 Insert bindings into a builder. More...
 
void nix_bindings_builder_free (BindingsBuilder *builder)
 Free a bindings builder. More...
 

Getters

ValueType nix_get_type (nix_c_context *context, const Value *value)
 Get value type. More...
 
const char * nix_get_typename (nix_c_context *context, const Value *value)
 Get type name of value. More...
 
bool nix_get_bool (nix_c_context *context, const Value *value)
 Get boolean value. More...
 
const char * nix_get_string (nix_c_context *context, const Value *value)
 Get string. More...
 
const char * nix_get_path_string (nix_c_context *context, const Value *value)
 Get path as string. More...
 
unsigned int nix_get_list_size (nix_c_context *context, const Value *value)
 Get the length of a list. More...
 
unsigned int nix_get_attrs_size (nix_c_context *context, const Value *value)
 Get the element count of an attrset. More...
 
double nix_get_float (nix_c_context *context, const Value *value)
 Get float value in 64 bits. More...
 
int64_t nix_get_int (nix_c_context *context, const Value *value)
 Get int value. More...
 
ExternalValuenix_get_external (nix_c_context *context, Value *)
 Get external reference. More...
 
Valuenix_get_list_byidx (nix_c_context *context, const Value *value, State *state, unsigned int ix)
 Get the ix'th element of a list. More...
 
Valuenix_get_attr_byname (nix_c_context *context, const Value *value, State *state, const char *name)
 Get an attr by name. More...
 
bool nix_has_attr_byname (nix_c_context *context, const Value *value, State *state, const char *name)
 Check if an attribute name exists on a value. More...
 
Valuenix_get_attr_byidx (nix_c_context *context, const Value *value, State *state, unsigned int i, const char **name)
 Get an attribute by index in the sorted bindings. More...
 
const char * nix_get_attr_name_byidx (nix_c_context *context, const Value *value, State *state, unsigned int i)
 Get an attribute name by index in the sorted bindings. More...
 

Setters

nix_err nix_set_bool (nix_c_context *context, Value *value, bool b)
 Set boolean value. More...
 
nix_err nix_set_string (nix_c_context *context, Value *value, const char *str)
 Set a string. More...
 
nix_err nix_set_path_string (nix_c_context *context, Value *value, const char *str)
 Set a path. More...
 
nix_err nix_set_float (nix_c_context *context, Value *value, double d)
 Set a float. More...
 
nix_err nix_set_int (nix_c_context *context, Value *value, int64_t i)
 Set an int. More...
 
nix_err nix_set_null (nix_c_context *context, Value *value)
 Set null. More...
 
nix_err nix_set_external (nix_c_context *context, Value *value, ExternalValue *val)
 Set an external value. More...
 
nix_err nix_make_list (nix_c_context *context, State *s, Value *value, unsigned int size)
 Allocate a list. More...
 
nix_err nix_set_list_byidx (nix_c_context *context, Value *value, unsigned int ix, Value *elem)
 Manipulate a list by index. More...
 
nix_err nix_make_attrs (nix_c_context *context, Value *value, BindingsBuilder *b)
 Create an attribute set from a bindings builder. More...
 
nix_err nix_set_primop (nix_c_context *context, Value *value, PrimOp *op)
 Set primop. More...
 
nix_err nix_copy_value (nix_c_context *context, Value *value, Value *source)
 Copy from another value. More...
 

Detailed Description

Functions to inspect and change nix Value's.

Typedef Documentation

◆ BindingsBuilder

Stores an under-construction set of bindings.

Do not reuse.

See also
nix_make_bindings_builder, nix_bindings_builder_free, nix_make_attrs
nix_bindings_builder_insert

Function Documentation

◆ nix_bindings_builder_free()

void nix_bindings_builder_free ( BindingsBuilder builder)

Free a bindings builder.

Does not fail.

Parameters
[in]builderthe builder to free

◆ nix_bindings_builder_insert()

nix_err nix_bindings_builder_insert ( nix_c_context context,
BindingsBuilder builder,
const char *  name,
Value value 
)

Insert bindings into a builder.

Parameters
[out]contextOptional, stores error information
[in]builderBindingsBuilder to insert into
[in]nameattribute name, copied into the symbol store
[in]valuevalue to give the binding
Returns
error code, NIX_OK on success.

◆ nix_copy_value()

nix_err nix_copy_value ( nix_c_context context,
Value value,
Value source 
)

Copy from another value.

Parameters
[out]contextOptional, stores error information
[out]valueNix value to modify
[in]sourcevalue to copy from
Returns
error code, NIX_OK on success.

◆ nix_get_attr_byidx()

Value * nix_get_attr_byidx ( nix_c_context context,
const Value value,
State state,
unsigned int  i,
const char **  name 
)

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

Parameters
[out]contextOptional, stores error information
[in]valueNix value to inspect
[in]statenix evaluator state
[in]iattribute index
[out]namewill store a pointer to the attribute name
Returns
value, NULL in case of errors

◆ nix_get_attr_byname()

Value * nix_get_attr_byname ( nix_c_context context,
const Value value,
State state,
const char *  name 
)

Get an attr by name.

Owned by the GC. Use nix_gc_decref when you're done with the pointer

Parameters
[out]contextOptional, stores error information
[in]valueNix value to inspect
[in]statenix evaluator state
[in]nameattribute name
Returns
value, NULL in case of errors

◆ nix_get_attr_name_byidx()

const char * nix_get_attr_name_byidx ( nix_c_context context,
const Value value,
State state,
unsigned int  i 
)

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

Parameters
[out]contextOptional, stores error information
[in]valueNix value to inspect
[in]statenix evaluator state
[in]iattribute index
Returns
name, NULL in case of errors

◆ nix_get_attrs_size()

unsigned int nix_get_attrs_size ( nix_c_context context,
const Value value 
)

Get the element count of an attrset.

Parameters
[out]contextOptional, stores error information
[in]valueNix value to inspect
Returns
attrset element count, error info via context

◆ nix_get_bool()

bool nix_get_bool ( nix_c_context context,
const Value value 
)

Get boolean value.

Parameters
[out]contextOptional, stores error information
[in]valueNix value to inspect
Returns
true or false, error info via context

◆ nix_get_external()

ExternalValue * nix_get_external ( nix_c_context context,
Value  
)

Get external reference.

Parameters
[out]contextOptional, stores error information
[in]valueNix value to inspect
Returns
reference to external, NULL in case of error

◆ nix_get_float()

double nix_get_float ( nix_c_context context,
const Value value 
)

Get float value in 64 bits.

Parameters
[out]contextOptional, stores error information
[in]valueNix value to inspect
Returns
float contents, error info via context

◆ nix_get_int()

int64_t nix_get_int ( nix_c_context context,
const Value value 
)

Get int value.

Parameters
[out]contextOptional, stores error information
[in]valueNix value to inspect
Returns
int contents, error info via context

◆ nix_get_list_byidx()

Value * nix_get_list_byidx ( nix_c_context context,
const Value value,
State state,
unsigned int  ix 
)

Get the ix'th element of a list.

Owned by the GC. Use nix_gc_decref when you're done with the pointer

Parameters
[out]contextOptional, stores error information
[in]valueNix value to inspect
[in]statenix evaluator state
[in]ixlist element to get
Returns
value, NULL in case of errors

◆ nix_get_list_size()

unsigned int nix_get_list_size ( nix_c_context context,
const Value value 
)

Get the length of a list.

Parameters
[out]contextOptional, stores error information
[in]valueNix value to inspect
Returns
length of list, error info via context

◆ nix_get_path_string()

const char * nix_get_path_string ( nix_c_context context,
const Value value 
)

Get path as string.

Parameters
[out]contextOptional, stores error information
[in]valueNix value to inspect
Returns
string
NULL in case of error.

◆ nix_get_string()

const char * nix_get_string ( nix_c_context context,
const Value value 
)

Get string.

Parameters
[out]contextOptional, stores error information
[in]valueNix value to inspect
Returns
string
NULL in case of error.

◆ nix_get_type()

ValueType nix_get_type ( nix_c_context context,
const Value value 
)

Get value type.

Parameters
[out]contextOptional, stores error information
[in]valueNix value to inspect
Returns
type of nix value

◆ nix_get_typename()

const char * nix_get_typename ( nix_c_context context,
const Value value 
)

Get type name of value.

Parameters
[out]contextOptional, stores error information
[in]valueNix value to inspect
Returns
type name, owned string
Todo:
way to free the result

◆ nix_has_attr_byname()

bool nix_has_attr_byname ( nix_c_context context,
const Value value,
State state,
const char *  name 
)

Check if an attribute name exists on a value.

Parameters
[out]contextOptional, stores error information
[in]valueNix value to inspect
[in]statenix evaluator state
[in]nameattribute name
Returns
value, error info via context

◆ nix_make_attrs()

nix_err nix_make_attrs ( nix_c_context context,
Value value,
BindingsBuilder b 
)

Create an attribute set from a bindings builder.

Parameters
[out]contextOptional, stores error information
[out]valueNix value to modify
[in]bbindings builder to use. Make sure to unref this afterwards.
Returns
error code, NIX_OK on success.

◆ nix_make_bindings_builder()

BindingsBuilder * nix_make_bindings_builder ( nix_c_context context,
State state,
size_t  capacity 
)

Create a bindings builder.

Parameters
[out]contextOptional, stores error information
[in]statenix evaluator state
[in]capacityhow many bindings you'll add. Don't exceed.
Returns
owned reference to a bindings builder. Make sure to unref when you're done.

◆ nix_make_list()

nix_err nix_make_list ( nix_c_context context,
State s,
Value value,
unsigned int  size 
)

Allocate a list.

Parameters
[out]contextOptional, stores error information
[out]valueNix value to modify
[in]sizesize of list
Returns
error code, NIX_OK on success.

◆ nix_set_bool()

nix_err nix_set_bool ( nix_c_context context,
Value value,
bool  b 
)

Set boolean value.

Parameters
[out]contextOptional, stores error information
[out]valueNix value to modify
[in]bthe boolean value
Returns
error code, NIX_OK on success.

◆ nix_set_external()

nix_err nix_set_external ( nix_c_context context,
Value value,
ExternalValue val 
)

Set an external value.

Parameters
[out]contextOptional, stores error information
[out]valueNix value to modify
[in]valthe external value to set. Will be GC-referenced by the value.
Returns
error code, NIX_OK on success.

◆ nix_set_float()

nix_err nix_set_float ( nix_c_context context,
Value value,
double  d 
)

Set a float.

Parameters
[out]contextOptional, stores error information
[out]valueNix value to modify
[in]dthe float, 64-bits
Returns
error code, NIX_OK on success.

◆ nix_set_int()

nix_err nix_set_int ( nix_c_context context,
Value value,
int64_t  i 
)

Set an int.

Parameters
[out]contextOptional, stores error information
[out]valueNix value to modify
[in]ithe int
Returns
error code, NIX_OK on success.

◆ nix_set_list_byidx()

nix_err nix_set_list_byidx ( nix_c_context context,
Value value,
unsigned int  ix,
Value elem 
)

Manipulate a list by index.

Don't do this mid-computation.

Precondition
your list should be at least 'ix+1' items long
Parameters
[out]contextOptional, stores error information
[out]valueNix value to modify
[in]ixindex to manipulate
[in]elemthe value to set, will be gc-referenced by the value
Returns
error code, NIX_OK on success.

◆ nix_set_null()

nix_err nix_set_null ( nix_c_context context,
Value value 
)

Set null.

Parameters
[out]contextOptional, stores error information
[out]valueNix value to modify
Returns
error code, NIX_OK on success.

◆ nix_set_path_string()

nix_err nix_set_path_string ( nix_c_context context,
Value value,
const char *  str 
)

Set a path.

Parameters
[out]contextOptional, stores error information
[out]valueNix value to modify
[in]strthe path string, copied
Returns
error code, NIX_OK on success.

◆ nix_set_primop()

nix_err nix_set_primop ( nix_c_context context,
Value value,
PrimOp op 
)

Set primop.

Parameters
[out]contextOptional, stores error information
[out]valueNix value to modify
[in]opprimop, will be gc-referenced by the value
See also
nix_alloc_primop
Returns
error code, NIX_OK on success.

◆ nix_set_string()

nix_err nix_set_string ( nix_c_context context,
Value value,
const char *  str 
)

Set a string.

Parameters
[out]contextOptional, stores error information
[out]valueNix value to modify
[in]strthe string, copied
Returns
error code, NIX_OK on success.