next up previous contents index
Next: 4.1 Compilation Up: Contents Previous: 3.4 Language differences   Contents   Index


4. The libonyx library

The libonyx library implements an embeddable Onyx interpreter. libonyx is designed to allow multiple interpreter instances in the same program, though since Onyx is a multi-threaded language, in most cases it makes more sense to use a single interpreter instance with multiple threads.

The Onyx language is described elsewhere in this manual, so this chapter documents the C API with as little information about the Onyx language as possible.

A minimal program that runs the Onyx interpreter interactively looks like:

#include <libonyx/libonyx.h>

int
main(int argc, char **argv, char **envp)
{
    cw_nx_t nx;
    cw_nxo_t thread, *nxo;

    /* Initialize libonyx and the Onyx interpreter. */
    libonyx_init(argc, argv, envp);
    nx_new(&nx, NULL);

    /* Create a thread. */
    nxo_thread_new(&thread, &nx);

    /* Set up stdin for evaluation. */
    nxo = nxo_stack_push(nxo_thread_ostack_get(&thread));
    nxo_dup(nxo, nxo_thread_stdin_get(&thread));
    nxo_attr_set(nxo, NXOA_EXECUTABLE);

    /* Start the thread. */
    nxo_thread_start(&thread);

    /* Clean up. */
    nx_delete(&nx);
    libonyx_shutdown();
    return 0;
}

In many cases, an application will need to implement additional Onyx operators or handles (and make them accessible from within the Onyx interpreter) in order to make the application accessible/controllable from the Onyx interpreter. If the application user interface is to be interaction with the Onyx interpreter, then little else needs to be done. Note that Onyx supports loadable modules, so it is usually possible to extend Onyx via modules, though embedding libonyx directly into the application also works.



Subsections
next up previous contents index
Next: 4.1 Compilation Up: Contents Previous: 3.4 Language differences   Contents   Index
Jason Evans 2005-03-16