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(); nx_new(&nx, NULL, argc, argv, envp); /* 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 most cases, an application will need to implement additional Onyx operators (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.