diff --git a/src/libexpr/nix_api_value.cc b/src/libexpr/nix_api_value.cc index ceff036c9..dae50352b 100644 --- a/src/libexpr/nix_api_value.cc +++ b/src/libexpr/nix_api_value.cc @@ -3,6 +3,7 @@ #include "eval.hh" #include "gc/gc.h" #include "globals.hh" +#include "primops.hh" #include "value.hh" #include "nix_api_expr.h" @@ -55,6 +56,15 @@ PrimOp *nix_alloc_primop(nix_c_context *context, PrimOpFun fun, int arity, NIXC_CATCH_ERRS_NULL } +nix_err nix_register_primop(nix_c_context *context, PrimOp *primOp) { + if (context) + context->last_err_code = NIX_OK; + try { + nix::RegisterPrimOp r(std::move(*((nix::PrimOp *)primOp))); + } + NIXC_CATCH_ERRS +} + Value *nix_alloc_value(nix_c_context *context, State *state) { if (context) context->last_err_code = NIX_OK; diff --git a/src/libexpr/nix_api_value.h b/src/libexpr/nix_api_value.h index 08eb34fc5..af1d211a3 100644 --- a/src/libexpr/nix_api_value.h +++ b/src/libexpr/nix_api_value.h @@ -88,6 +88,20 @@ typedef void (*PrimOpFun)(State *state, int pos, Value **args, Value *v); */ PrimOp *nix_alloc_primop(nix_c_context *context, PrimOpFun fun, int arity, const char *name, const char **args, const char *doc); + +/** @brief 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). + * + * @param[out] context Optional, stores error information + * @return primop, or null in case of errors + * + */ +nix_err nix_register_primop(nix_c_context *context, PrimOp *primOp); /** @} */ // Function prototypes