diff options
Diffstat (limited to 'Examples/octave/constants')
| -rw-r--r-- | Examples/octave/constants/Makefile | 21 | ||||
| -rw-r--r-- | Examples/octave/constants/example.i | 27 | ||||
| -rw-r--r-- | Examples/octave/constants/runme.m | 29 |
3 files changed, 77 insertions, 0 deletions
diff --git a/Examples/octave/constants/Makefile b/Examples/octave/constants/Makefile new file mode 100644 index 0000000..4d80c6f --- /dev/null +++ b/Examples/octave/constants/Makefile @@ -0,0 +1,21 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = +TARGET = example +INTERFACE = example.i +LIBS = -lm +SWIGOPT = + +all:: + $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp + +static:: + $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static + +clean:: + $(MAKE) -f $(TOP)/Makefile octave_clean + rm -f $(TARGET).py + +check: all diff --git a/Examples/octave/constants/example.i b/Examples/octave/constants/example.i new file mode 100644 index 0000000..4f7b1a4 --- /dev/null +++ b/Examples/octave/constants/example.i @@ -0,0 +1,27 @@ +/* File : example.i */ +%module example + +/* A few preprocessor macros */ + +#define ICONST 42 +#define FCONST 2.1828 +#define CCONST 'x' +#define CCONST2 '\n' +#define SCONST "Hello World" +#define SCONST2 "\"Hello World\"" + +/* This should work just fine */ +#define EXPR ICONST + 3*(FCONST) + +/* This shouldn't do anything */ +#define EXTERN extern + +/* Neither should this (BAR isn't defined) */ +#define FOO (ICONST + BAR) + +/* The following directives also produce constants */ + +%constant int iconst = 37; +%constant double fconst = 3.14; + + diff --git a/Examples/octave/constants/runme.m b/Examples/octave/constants/runme.m new file mode 100644 index 0000000..3228587 --- /dev/null +++ b/Examples/octave/constants/runme.m @@ -0,0 +1,29 @@ +# file: runme.m + +example + +printf("ICONST = %i (should be 42)\n", example.ICONST); +printf("FCONST = %f (should be 2.1828)\n", example.FCONST); +printf("CCONST = %s (should be 'x')\n", example.CCONST); +printf("CCONST2 = %s (this should be on a new line)\n", example.CCONST2); +printf("SCONST = %s (should be 'Hello World')\n", example.SCONST); +printf("SCONST2 = %s (should be '\"Hello World\"')\n", example.SCONST2); +printf("EXPR = %f (should be 48.5484)\n", example.EXPR); +printf("iconst = %i (should be 37)\n", example.iconst); +printf("fconst = %f (should be 3.14)\n", example.fconst); + +try + printf("EXTERN = %s (Arg! This shouldn't printf(anything)\n", example.EXTERN); +catch + printf("EXTERN isn't defined (good)\n"); +end_try_catch + +try + printf("FOO = %i (Arg! This shouldn't printf(anything)\n", example.FOO); +catch + printf("FOO isn't defined (good)\n"); +end_try_catch + + + + |
