From 39bab12d2ca85c023495e84fdd8100231bb2585d Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Fri, 30 Aug 2013 16:41:42 +0200 Subject: [PATCH] Scilab: add %scilabconst in enum example --- Examples/scilab/enum/example.c | 13 +++++++++ Examples/scilab/enum/example.i | 8 +++--- Examples/scilab/enum/runme.sci | 31 ++++++++++++++-------- Examples/scilab/enum/scilabconst_example.h | 3 +++ 4 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 Examples/scilab/enum/scilabconst_example.h diff --git a/Examples/scilab/enum/example.c b/Examples/scilab/enum/example.c index 6df9203ce..0dbe4cda7 100644 --- a/Examples/scilab/enum/example.c +++ b/Examples/scilab/enum/example.c @@ -1,6 +1,7 @@ /* File : example.c */ #include "example.h" +#include "scilabconst_example.h" #include void enum_test(color c) { @@ -14,3 +15,15 @@ void enum_test(color c) { printf("color = Unknown color!\n"); } } + +void scilabconst_enum_test(fruit f) { + if (f == APPLE) { + printf("fruit = APPLE\n"); + } else if (f == ORANGE) { + printf("fruit = ORANGE\n"); + } else if (f == LEMON) { + printf("fruit = LEMON\n"); + } else { + printf("fruit = Unknown fruit!\n"); + } +} diff --git a/Examples/scilab/enum/example.i b/Examples/scilab/enum/example.i index 634352b03..6a471fde0 100644 --- a/Examples/scilab/enum/example.i +++ b/Examples/scilab/enum/example.i @@ -1,13 +1,13 @@ /* File : example.i */ %module example -%scilabconst(1); - %{ #include "example.h" +#include "scilabconst_example.h" %} -/* Let's just grab the original header file here */ - %include "example.h" +%scilabconst(1); + +%include "scilabconst_example.h" diff --git a/Examples/scilab/enum/runme.sci b/Examples/scilab/enum/runme.sci index e03fac505..182fa0c61 100644 --- a/Examples/scilab/enum/runme.sci +++ b/Examples/scilab/enum/runme.sci @@ -2,19 +2,28 @@ lines(0); exec loader.sce; SWIG_Init(); -// Print out the value of some enums +printf("\nTesting use of enums wrapped as Scilab functions\n"); + printf("*** color ***\n"); -printf(" RED = %i\n", RED); -printf(" BLUE = %i\n", BLUE); -printf(" GREEN = %i\n", GREEN); +printf(" RED = %i\n", RED_get()); +printf(" BLUE = %i\n", BLUE_get()); +printf(" GREEN = %i\n", GREEN_get()); - -printf("\nTesting use of enums with functions\n"); - -enum_test(RED); -enum_test(BLUE); -enum_test(GREEN); +enum_test(RED_get()); +enum_test(BLUE_get()); +enum_test(GREEN_get()); enum_test(int32(1234)); -exit +printf("\nTesting use of enums wrapped as Scilab variables\n"); +printf("*** fruit ***\n"); +printf(" APPLE = %i\n", APPLE); +printf(" ORANGE = %i\n", ORANGE); +printf(" LEMON = %i\n", LEMON); + +scilabconst_enum_test(APPLE); +scilabconst_enum_test(ORANGE); +scilabconst_enum_test(LEMON); +scilabconst_enum_test(int32(1234)); + +exit diff --git a/Examples/scilab/enum/scilabconst_example.h b/Examples/scilab/enum/scilabconst_example.h new file mode 100644 index 000000000..92dcaaf61 --- /dev/null +++ b/Examples/scilab/enum/scilabconst_example.h @@ -0,0 +1,3 @@ +typedef enum { APPLE, ORANGE, LEMON } fruit; + +void scilabconst_enum_test(fruit f);