Binding C into Isis

This document explains how to bind C values and functions into the default environment of your personal Isis interpreter. Here are the step-by-step instructions:

  1. If you have not already done so, build a private Isis interpreter for yourself.

  2. It is best to keep your C functions in a file separate from the main interpreter source file. Copy the C function source code template and the C function header file template to the folder where your personal interpreter resides and name them appropriately. Follow these 2 conventions if possible:

  3. If you have changed the name of the header file, edit the #include statement at the top of the source file to reflect the new name.

  4. Write the C functions you want to bind into Isis at the bottom of the new .c file that you just created. Here are the instructions for writing Isis C functions and manipulating Isis values.

  5. Put declarations of your C functions at the top of the source file (before the definition of bind_cool_library()).

  6. Edit bind_cool_library() so that it will bind your C functions into Isis when it is called.

    For each function, call bindCfunc with 4 arguments:

    In the following example, the C function cool_func is bound to the name cool-function in Isis, and will be passed 0 as its call_data when it is called:

    bindCfunc(script, "cool-function", cool_func, 0);
  7. If there are any other values or constants you want to bind, do so here using these helper function.

  8. Change the name of bind_cool_library() to something more appropriate, and make sure to change the name in the declaration in the header file as well.

  9. In your interpreter's main.c, include the new header file at the top, and call bind_cool_library() (or whatever you've called it) in main() after opening a script but before processing any expressions. The interpreter's source code template indicates where to add these items. Here is an example:
    ... /**** Include any external Isis library header files here ****/ #include "isis_cfunc_template.h" main(int argc, char **argv) { ... /**** Add calls to bind external functions, libraries, etc., here ****/ bind_cool_library(script); ... }

  10. Add the new source filename to the Makefile on the SRCS line.

  11. Type make to make the new interpreter !