jsish
Extension
Not logged in

C-extensions can either be statically compiled in, or dynamically loaded as shared libraries using the load command.

Built-Ins

Jsi comes standard with a number of extensions:

All but MySql are by default statically compiled-in. To build-in it in use:

make mysql

Static Extension

jsish can be made to compile in an extension without modifying source, as in the following example:

cp c-demos/dyn.c .
make EXTNAME=dyn

This builds in the demo dyn.c.

Similarly, a standalone using Jsi_Lite might use:

cd c-demos/
cc -g cmd.c dyn.c -o cmds -lz -lm -ldl -lpthread -DJSI_USER_EXTENSION=Jsi_Initdyn -I..

Other static approaches require editing the Makefile and/or source files.

Dynamic Extensions

A dynamic extension requires a C entry function to handle load-time initialization:

int Jsi_InitFoo(Jsi_Interp *interp) {
    // Do initialization
    return JSI_OK
}

This is compiled with:

cc -g -Wall -DJSI_USE_STUBS -I. -shared -fpic foo.c -o libfoo.so

and loaded with:

load('foo.so');

For an example see ../c-demos/dyn.c.

Modules

A shared library can be loaded on-demand using Modules. In particular see Module Generation.

libjsi.so

Jsi can be built as the shared library libjsi.so (libjsi.dll on Windows), for linking into applications with -ljsi.

This will require installation into your Operating System, and so is primarily of interest to system integrators.

On Linux this goes something like:

make shared
make jsishs
sudo cp jsishs /usr/local/bin/jsish
sudo cp libjsi.so /usr/local/lib/
sudo cp jsi.h /usr/local/include/
sudo ldconfig -v

Stubs

If using the shared library libjsi.so, and backward compatibility is of concern, it may be desirable to use stubs support.

For an simple stubs example see ../c-demos/prime.c.

For a complex, multi-level example see the stubs directory.

Command Specs

Although we can define extension commands one at a time, this can clutter the toplevel namespace.

Alternatively, we can define command-objects, eg.

Cmd.add(1,2,3);
Cmd.diff(17,9);

For an example see ../c-demos/cmds.c and the Jsi source.

Option Specs

Jsi provides an easy way for C extension commands parse an option object.

For more details see ./c-options.wiki and the Jsi source.

Glue Language

Jsi is designed for use as a glue language in a number of ways: