diff options
author | Steve Bennett <steveb@workware.net.au> | 2011-07-08 14:57:05 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2011-11-24 23:37:04 +1000 |
commit | 1f9fa4a5329c6ac9bb09bffee53d071d17179c34 (patch) | |
tree | fd630aa25a0e36a56cfe10c770637c3d71c7300d /examples.ext | |
parent | 7a8c0428cc8ec8098c2bb4a9ba2d6a2d597405e3 (diff) | |
download | jimtcl-1f9fa4a5329c6ac9bb09bffee53d071d17179c34.zip jimtcl-1f9fa4a5329c6ac9bb09bffee53d071d17179c34.tar.gz jimtcl-1f9fa4a5329c6ac9bb09bffee53d071d17179c34.tar.bz2 |
Create build-jim-ext for building extensions
Simplifies the process of building loadable extensions
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'examples.ext')
-rw-r--r-- | examples.ext/Makefile | 29 | ||||
-rw-r--r-- | examples.ext/README | 7 | ||||
-rw-r--r-- | examples.ext/helloworld.c | 24 |
3 files changed, 60 insertions, 0 deletions
diff --git a/examples.ext/Makefile b/examples.ext/Makefile new file mode 100644 index 0000000..fa5cfc6 --- /dev/null +++ b/examples.ext/Makefile @@ -0,0 +1,29 @@ +# Note that if cross compiling, build with: +# +# make NOTEST=1 +# +# to avoid trying to load the resulting module. +# Also note that you will need a build-host version of jimsh in the +# PATH in order to build the extension. + +# Prefer jimsh in the PATH because it is more likely to be built +# for the build-host rather than the target. + +ifdef NOTEST +BUILDOPTS := --notest +endif + +export PATH := $(PATH):.. + +all: helloworld.so + +helloworld.so: helloworld.c + ../build-jim-ext -I.. -L.. $(BUILDOPTS) $^ + +# Note: Currently we don't attempt to set LD_LIBRARY_PATH or equivalent + +test: + JIMLIB=. ../jimsh -e 'package require helloworld; hello' + +clean: + rm -f *.o *.so diff --git a/examples.ext/README b/examples.ext/README new file mode 100644 index 0000000..2317481 --- /dev/null +++ b/examples.ext/README @@ -0,0 +1,7 @@ +This directory contains examples of C extensions for Jim. + +In general, do: + + build-jim-ext extsource.c + +See the Makefile diff --git a/examples.ext/helloworld.c b/examples.ext/helloworld.c new file mode 100644 index 0000000..371a23d --- /dev/null +++ b/examples.ext/helloworld.c @@ -0,0 +1,24 @@ +/* + * hello.c -- A minimal Jim C extension. + */ +#include <jim.h> + +static int +Hello_Cmd(Jim_Interp *interp, int objc, Jim_Obj *const objv[]) +{ + Jim_SetResultString(interp, "Hello, World!", -1); + return JIM_OK; +} + +/* + * Jim_helloworldInit -- Called when Jim loads your extension. + * + * Note that the name *must* correspond exactly to the name of the extension: + * Jim_<extname>Init + */ +int +Jim_helloworldInit(Jim_Interp *interp) +{ + Jim_CreateCommand(interp, "hello", Hello_Cmd, NULL, NULL); + return JIM_OK; +} |