Next: 3.1 Compilation Up: Contents Previous: 2.3 Language differences Contents Index

#
3. 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();
        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.

Subsections

- 3.1 Compilation
- 3.2 Types
- 3.3 Global variables
- 3.4 Threads
- 3.5 Garbage collection
- 3.6 Exceptions
- 3.7 Integration issues
  - 3.7.1 Thread creation
  - 3.7.2 Restarted interrupted system calls
- 3.8 Guidelines for writing extensions
- 3.9 API
- 3.10 Classes
  - 3.10.1 ch
    - 3.10.1.1 API
  - 3.10.2 cnd
    - 3.10.2.1 API
  - 3.10.3 dch
    - 3.10.3.1 API
  - 3.10.4 mb
    - 3.10.4.1 API
  - 3.10.5 mem
    - 3.10.5.1 API
  - 3.10.6 mq
    - 3.10.6.1 API
  - 3.10.7 mtx
    - 3.10.7.1 API
  - 3.10.8 nx
    - 3.10.8.1 API
  - 3.10.9 nxa
    - 3.10.9.1 API
  - 3.10.10 nxn
    - 3.10.10.1 API
  - 3.10.11 nxo
    - 3.10.11.1 API
  - 3.10.12 nxo_array
    - 3.10.12.1 API
  - 3.10.13 nxo_boolean
    - 3.10.13.1 API
  - 3.10.14 nxo_condition
    - 3.10.14.1 API
  - 3.10.15 nxo_dict
    - 3.10.15.1 API
  - 3.10.16 nxo_file
    - 3.10.16.1 API
  - 3.10.17 nxo_fino
    - 3.10.17.1 API
  - 3.10.18 nxo_hook
    - 3.10.18.1 API
  - 3.10.19 nxo_integer
    - 3.10.19.1 API
  - 3.10.20 nxo_mark
    - 3.10.20.1 API
  - 3.10.21 nxo_mutex
    - 3.10.21.1 API
  - 3.10.22 nxo_name
    - 3.10.22.1 API
  - 3.10.23 nxo_no
    - 3.10.23.1 API
  - 3.10.24 nxo_null
    - 3.10.24.1 API
  - 3.10.25 nxo_operator
    - 3.10.25.1 API
  - 3.10.26 nxo_pmark
    - 3.10.26.1 API
  - 3.10.27 nxo_real
    - 3.10.27.1 API
  - 3.10.28 nxo_stack
    - 3.10.28.1 API
  - 3.10.29 nxo_string
    - 3.10.29.1 API
  - 3.10.30 nxo_thread
    - 3.10.30.1 API
  - 3.10.31 ql
    - 3.10.31.1 API
  - 3.10.32 qr
    - 3.10.32.1 API
  - 3.10.33 qs
    - 3.10.33.1 API
  - 3.10.34 thd
    - 3.10.34.1 API
  - 3.10.35 tsd
    - 3.10.35.1 API
  - 3.10.36 xep
    - 3.10.36.1 API
- 3.11 Dictionaries
  - 3.11.1 gcdict
    - 3.11.1.1 API
  - 3.11.2 systemdict
    - 3.11.2.1 API