Dz
Djazair
v1.0.5
🔍

Embedding Djazair in C/C++

Djazair is designed to be easily embedded into C/C++ applications via a single header djazair.h.

Minimal Example

#include "djazair.h"
#include <stdio.h>

int main() {
    // Create a new VM instance
    djazair_vm* vm = djazair_new_vm();
    
    // Execute a script file
    djazair_execute_file(vm, "script.dz");
    
    // Execute inline code
    djazair_execute_string(vm, "print('Hello from C!')");
    
    // Cleanup
    djazair_free_vm(vm);
    return 0;
}

Multiple VM Instances

You can create multiple isolated VM instances concurrently:

djazair_vm* vm1 = djazair_new_vm();
djazair_vm* vm2 = djazair_new_vm();

// Each VM has its own state
djazair_execute_string(vm1, "let x = 42");
djazair_execute_string(vm2, "let x = 100"); // independent

Callback Registration

Register C functions callable from Djazair:

void my_log(djazair_vm* vm, djazair_args* args) {
    const char* msg = djazair_get_arg_string(args, 0);
    printf("[Djazair Log] %s\n", msg);
}

// Register the callback
djazair_register_function(vm, "logMessage", my_log);

Then call from Djazair:

logMessage("Hello from Djazair!") # calls C callback

API Functions

  • djazair_new_vm() - Create a new VM instance.
  • djazair_free_vm(vm) - Destroy VM and free resources.
  • djazair_execute_file(vm, path) - Execute a script file.
  • djazair_execute_string(vm, code) - Execute inline code.
  • djazair_register_function(vm, name, callback) - Register C callback.
  • djazair_get_arg_string(args, index) - Get string argument.
  • djazair_get_arg_number(args, index) - Get number argument.
  • djazair_set_std_lib_path(vm, path) - Set standard library path.
© 2026 Harizi Riyadh. Released under the MIT License.
Official Website for Djazair.