summaryrefslogtreecommitdiff
path: root/examples.ext
diff options
context:
space:
mode:
Diffstat (limited to 'examples.ext')
-rw-r--r--examples.ext/Makefile29
-rw-r--r--examples.ext/README7
-rw-r--r--examples.ext/helloworld.c24
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;
+}