Nix 2.17.0
Nix, the purely functional package manager; stable external interfaces
Loading...
Searching...
No Matches
nix_api_value.h
Go to the documentation of this file.
1#ifndef NIX_API_VALUE_H
2#define NIX_API_VALUE_H
3
11#include "nix_api_util.h"
12#include "stdbool.h"
13#include "stddef.h"
14#include "stdint.h"
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19// cffi start
20
21// Type definitions
22typedef enum {
23 NIX_TYPE_THUNK,
24 NIX_TYPE_INT,
25 NIX_TYPE_FLOAT,
26 NIX_TYPE_BOOL,
27 NIX_TYPE_STRING,
28 NIX_TYPE_PATH,
29 NIX_TYPE_NULL,
30 NIX_TYPE_ATTRS,
31 NIX_TYPE_LIST,
32 NIX_TYPE_FUNCTION,
33 NIX_TYPE_EXTERNAL
34} ValueType;
35
36// forward declarations
37typedef void Value;
38typedef struct State State;
39// type defs
48
55typedef struct PrimOp PrimOp;
62
74typedef void (*PrimOpFun)(State *state, int pos, Value **args, Value *v);
75
90 const char *name, const char **args, const char *doc);
91
107// Function prototypes
108
130ValueType nix_get_type(nix_c_context *context, const Value *value);
137const char *nix_get_typename(nix_c_context *context, const Value *value);
138
144bool nix_get_bool(nix_c_context *context, const Value *value);
151const char *nix_get_string(nix_c_context *context, const Value *value);
158const char *nix_get_path_string(nix_c_context *context, const Value *value);
164unsigned int nix_get_list_size(nix_c_context *context, const Value *value);
170unsigned int nix_get_attrs_size(nix_c_context *context, const Value *value);
176double nix_get_float(nix_c_context *context, const Value *value);
182int64_t nix_get_int(nix_c_context *context, const Value *value);
189
200 State *state, unsigned int ix);
211 State *state, const char *name);
212
220bool nix_has_attr_byname(nix_c_context *context, const Value *value,
221 State *state, const char *name);
222
236 State *state, unsigned int i, const char **name);
237
249const char *nix_get_attr_name_byidx(nix_c_context *context, const Value *value,
250 State *state, unsigned int i);
261nix_err nix_set_bool(nix_c_context *context, Value *value, bool b);
268nix_err nix_set_string(nix_c_context *context, Value *value, const char *str);
276 const char *str);
283nix_err nix_set_float(nix_c_context *context, Value *value, double d);
290nix_err nix_set_int(nix_c_context *context, Value *value, int64_t i);
304 ExternalValue *val);
312 unsigned int size);
324 unsigned int ix, Value *elem);
332 BindingsBuilder *b);
347nix_err nix_copy_value(nix_c_context *context, Value *value, Value *source);
359 size_t capacity);
368 BindingsBuilder *builder, const char *name,
369 Value *value);
378// cffi end
379#ifdef __cplusplus
380}
381#endif
382
384#endif // NIX_API_VALUE_H
struct ExternalValue ExternalValue
External Value.
Definition: nix_api_value.h:61
int nix_err
Type for error codes in the NIX system.
Definition: nix_api_util.h:59
Value * nix_alloc_value(nix_c_context *context, State *state)
Allocate a Nix value.
struct PrimOp PrimOp
PrimOp function.
Definition: nix_api_value.h:55
nix_err nix_register_primop(nix_c_context *context, PrimOp *primOp)
add a primop to builtins
void(* PrimOpFun)(State *state, int pos, Value **args, Value *v)
Function pointer for primops.
Definition: nix_api_value.h:74
PrimOp * nix_alloc_primop(nix_c_context *context, PrimOpFun fun, int arity, const char *name, const char **args, const char *doc)
Allocate a primop.
struct BindingsBuilder BindingsBuilder
Stores an under-construction set of bindings.
Definition: nix_api_value.h:47
nix_err nix_copy_value(nix_c_context *context, Value *value, Value *source)
Copy from another value.
ValueType nix_get_type(nix_c_context *context, const Value *value)
Get value type.
double nix_get_float(nix_c_context *context, const Value *value)
Get float value in 64 bits.
ExternalValue * nix_get_external(nix_c_context *context, Value *)
Get external reference.
nix_err nix_make_attrs(nix_c_context *context, Value *value, BindingsBuilder *b)
Create an attribute set from a bindings builder.
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.
const char * nix_get_path_string(nix_c_context *context, const Value *value)
Get path as string.
nix_err nix_set_path_string(nix_c_context *context, Value *value, const char *str)
Set a path.
nix_err nix_set_external(nix_c_context *context, Value *value, ExternalValue *val)
Set an external value.
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.
BindingsBuilder * nix_make_bindings_builder(nix_c_context *context, State *state, size_t capacity)
Create a bindings builder.
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.
int64_t nix_get_int(nix_c_context *context, const Value *value)
Get int value.
nix_err nix_set_string(nix_c_context *context, Value *value, const char *str)
Set a string.
nix_err nix_bindings_builder_insert(nix_c_context *context, BindingsBuilder *builder, const char *name, Value *value)
Insert bindings into a builder.
nix_err nix_set_null(nix_c_context *context, Value *value)
Set null.
nix_err nix_set_int(nix_c_context *context, Value *value, int64_t i)
Set an int.
nix_err nix_make_list(nix_c_context *context, State *s, Value *value, unsigned int size)
Allocate a list.
nix_err nix_set_bool(nix_c_context *context, Value *value, bool b)
Set boolean value.
Value * nix_get_attr_byname(nix_c_context *context, const Value *value, State *state, const char *name)
Get an attr by name.
nix_err nix_set_primop(nix_c_context *context, Value *value, PrimOp *op)
Set primop.
bool nix_get_bool(nix_c_context *context, const Value *value)
Get boolean value.
const char * nix_get_typename(nix_c_context *context, const Value *value)
Get type name of value.
nix_err nix_set_list_byidx(nix_c_context *context, Value *value, unsigned int ix, Value *elem)
Manipulate a list by index.
unsigned int nix_get_list_size(nix_c_context *context, const Value *value)
Get the length of a list.
const char * nix_get_string(nix_c_context *context, const Value *value)
Get string.
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.
unsigned int nix_get_attrs_size(nix_c_context *context, const Value *value)
Get the element count of an attrset.
nix_err nix_set_float(nix_c_context *context, Value *value, double d)
Set a float.
void nix_bindings_builder_free(BindingsBuilder *builder)
Free a bindings builder.
Main entry for the libutil C bindings.
Represents a nix evaluator state.
Represents a nix value.
This object stores error state.