C3nif.Generator (C3nif v0.2.0)
View SourceGenerate C3 NIF entry point code.
This module generates the C3 code needed to register NIFs with the Erlang runtime:
ErlNifFuncarray with function metadatanif_initfunction that returns theErlNifEntry
Generated Code Structure
// === AUTO-GENERATED NIF ENTRY ===
ErlNifFunc[N] __c3nif_funcs__ = {
{ .name = "func1", .arity = 1, .fptr = &func1, .flags = 0 },
{ .name = "func2", .arity = 2, .fptr = &func2, .flags = erl_nif::ERL_NIF_DIRTY_JOB_CPU_BOUND },
};
ErlNifEntry __c3nif_entry__;
fn ErlNifEntry* nif_init() @export("nif_init") {
__c3nif_entry__ = c3nif::make_nif_entry(
"Elixir.MyModule",
&__c3nif_funcs__,
N,
&on_load, // or null
null
);
return &__c3nif_entry__;
}
Summary
Functions
Generate complete C3 source by appending entry point to user code.
Generate C3 entry point code for the given NIFs and callbacks.
Functions
@spec generate_complete( String.t(), String.t(), [C3nif.Parser.NifFunction.t()], C3nif.Parser.Callbacks.t() ) :: String.t()
Generate complete C3 source by appending entry point to user code.
Parameters
user_code- The user's C3 source codemodule_name- The Elixir module namenifs- List ofNifFunctionstructscallbacks-Callbacksstruct
Returns
Complete C3 source code ready for compilation.
@spec generate_entry( String.t(), [C3nif.Parser.NifFunction.t()], C3nif.Parser.Callbacks.t() ) :: String.t()
Generate C3 entry point code for the given NIFs and callbacks.
Parameters
module_name- The Elixir module name (e.g., "Elixir.MyApp.MyNif")nifs- List ofNifFunctionstructscallbacks-Callbacksstruct with on_load/on_unload
Returns
C3 source code string to append to the user's C3 code.