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

Create your own primops. More...

Typedefs

typedef struct PrimOp PrimOp
 PrimOp function. More...
 
typedef void(* PrimOpFun) (State *state, int pos, Value **args, Value *v)
 Function pointer for primops. More...
 

Functions

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

Detailed Description

Create your own primops.

Typedef Documentation

◆ PrimOp

typedef struct PrimOp PrimOp

PrimOp function.

Owned by the GC

See also
nix_alloc_primop, nix_set_primop

◆ PrimOpFun

typedef void(* PrimOpFun) (State *state, int pos, Value **args, Value *v)

Function pointer for primops.

Parameters
[in]stateEvaluator state
[in]posposition of function call
[in]argslist of arguments
[out]vreturn value
See also
nix_alloc_primop, nix_set_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 
)

Allocate a primop.

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

Parameters
[out]contextOptional, stores error information
[in]funcallback
[in]arityexpected amount of function arguments
[in]namefunction name
[in]argsarray of argument names
[in]docoptional, documentation for this primop
Returns
primop, or null in case of errors
See also
nix_set_primop

◆ nix_register_primop()

nix_err nix_register_primop ( nix_c_context context,
PrimOp primOp 
)

add a primop to builtins

Only applies to new States.

Moves your primop into the global registry, meaning your input primOp is no longer usable (but still possibly subject to garbage collection).

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