Nix 2.29.0
Nix, the purely functional package manager: C API (experimental)
Loading...
Searching...
No Matches
Adding primops

Typedefs

typedef struct PrimOp PrimOp
 PrimOp function.
typedef void(* PrimOpFun) (void *user_data, nix_c_context *context, EvalState *state, nix_value **args, nix_value *ret)
 Function pointer for primops.

Functions

PrimOpnix_alloc_primop (nix_c_context *context, PrimOpFun fun, int arity, const char *name, const char **args, const char *doc, void *user_data)
 Allocate a PrimOp.
nix_err nix_register_primop (nix_c_context *context, PrimOp *primOp)
 add a primop to the builtins attribute set

Detailed Description

Typedef Documentation

◆ PrimOp

typedef struct PrimOp PrimOp

PrimOp function.

Owned by the GC

See also
nix_alloc_primop, nix_init_primop

◆ PrimOpFun

typedef void(* PrimOpFun) (void *user_data, nix_c_context *context, EvalState *state, nix_value **args, nix_value *ret)

Function pointer for primops.

When you want to return an error, call nix_set_err_msg(context, NIX_ERR_UNKNOWN, "your error message here").

Parameters
[in]user_dataArbitrary data that was initially supplied to nix_alloc_primop
[out]contextStores error information.
[in]stateEvaluator state
[in]argslist of arguments. Note that these can be thunks and should be forced using nix_value_force before use.
[out]retreturn value
See also
nix_alloc_primop, nix_init_primop

Function Documentation

◆ nix_alloc_primop()

PrimOp * nix_alloc_primop ( nix_c_context * context,
PrimOpFun fun,
int arity,
const char * name,
const char ** args,
const char * doc,
void * user_data )

Allocate a PrimOp.

Owned by the garbage collector. Use nix_gc_decref() when you're done with the returned PrimOp.

Parameters
[out]contextOptional, stores error information
[in]funcallback
[in]arityexpected number of function arguments
[in]namefunction name
[in]argsarray of argument names, NULL-terminated
[in]docoptional, documentation for this primop
[in]user_dataoptional, arbitrary data, passed to the callback when it's called
Returns
primop, or null in case of errors
See also
nix_init_primop

◆ nix_register_primop()

nix_err nix_register_primop ( nix_c_context * context,
PrimOp * primOp )

add a primop to the builtins attribute set

Only applies to States created after this call.

Moves your PrimOp content into the global evaluator registry, meaning your input PrimOp pointer is no longer usable. You are free to remove your references to it, after which it will be garbage collected.

Parameters
[out]contextOptional, stores error information
Returns
primop, or null in case of errors