Cicada ---> Online Help Docs ---> Example: neural networks in Cicada

Rules for embedding C/C++ code

There are two ways to merge C or C++ with Cicada. 1) We can embed our own C functions inside Cicada, as shown above. 2) Alternatively (or additionally), we can embed the Cicada inside of a larger C or C++ program.

Start with procedure (2) since it is very simple. In order for a C/C++ source file to run Cicada, it needs to include Cicada’s ccmain.h header file. The actual function call takes the form:


    errCode = runCicada(argc, argv);
   

With no arguments (argc = 0) Cicada will run the start.cicada script. If we set argc to 1 and pass the name of a script file in argv[0], then Cicada will load and run that script file instead.

Procedure (1) for embedding external C or C++ functions into Cicada involves three steps. First, one declares the C/C++ routine in a particular way and writes the code accordingly; this is easy because Cicada-embedded functions look just like the main() function of a stand-alone program. In the second step the author introduces his routine to Cicada by changing a couple of lines in Cicada’s userfn.c file. The final, optional step is to write a wrapper in Cicada’s scripting language that allocates storage for the C/C++ function and provides it with a smooth interface.


Prev: The Anagrambler    Next: C function declaration


Last update: May 8, 2024