Next: 4.1 Compilation Up: Contents Previous: 3.3 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();
        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

- 4.1 Compilation
- 4.2 Types
- 4.3 Global variables
- 4.4 Threads
- 4.5 Garbage collection
- 4.6 Exceptions
- 4.7 Integration issues
  - 4.7.1 Thread creation
  - 4.7.2 Restarted interrupted system calls
  - 4.7.3 Signals
- 4.8 Guidelines for writing extensions
- 4.9 API
- 4.10 Classes
  - 4.10.1 ch
    - 4.10.1.1 API
  - 4.10.2 cnd
    - 4.10.2.1 API
  - 4.10.3 dch
    - 4.10.3.1 API
  - 4.10.4 mb
    - 4.10.4.1 API
  - 4.10.5 mem
    - 4.10.5.1 API
  - 4.10.6 mq
    - 4.10.6.1 API
  - 4.10.7 mtx
    - 4.10.7.1 API
  - 4.10.8 nx
    - 4.10.8.1 API
  - 4.10.9 nxa
    - 4.10.9.1 API
  - 4.10.10 nxn
    - 4.10.10.1 API
  - 4.10.11 nxo
    - 4.10.11.1 API
  - 4.10.12 nxo_array
    - 4.10.12.1 API
  - 4.10.13 nxo_boolean
    - 4.10.13.1 API
  - 4.10.14 nxo_condition
    - 4.10.14.1 API
  - 4.10.15 nxo_dict
    - 4.10.15.1 API
  - 4.10.16 nxo_file
    - 4.10.16.1 API
  - 4.10.17 nxo_fino
    - 4.10.17.1 API
  - 4.10.18 nxo_hook
    - 4.10.18.1 API
  - 4.10.19 nxo_integer
    - 4.10.19.1 API
  - 4.10.20 nxo_mark
    - 4.10.20.1 API
  - 4.10.21 nxo_mutex
    - 4.10.21.1 API
  - 4.10.22 nxo_name
    - 4.10.22.1 API
  - 4.10.23 nxo_no
    - 4.10.23.1 API
  - 4.10.24 nxo_null
    - 4.10.24.1 API
  - 4.10.25 nxo_operator
    - 4.10.25.1 API
  - 4.10.26 nxo_pmark
    - 4.10.26.1 API
  - 4.10.27 nxo_real
    - 4.10.27.1 API
  - 4.10.28 nxo_stack
    - 4.10.28.1 API
  - 4.10.29 nxo_string
    - 4.10.29.1 API
  - 4.10.30 nxo_thread
    - 4.10.30.1 API
  - 4.10.31 ql
    - 4.10.31.1 API
  - 4.10.32 qr
    - 4.10.32.1 API
  - 4.10.33 qs
    - 4.10.33.1 API
  - 4.10.34 thd
    - 4.10.34.1 API
  - 4.10.35 tsd
    - 4.10.35.1 API
  - 4.10.36 xep
    - 4.10.36.1 API
- 4.11 Dictionaries
  - 4.11.1 gcdict
    - 4.11.1.1 API
  - 4.11.2 systemdict
    - 4.11.2.1 API