Scilab: constants example consistent with other languages

This commit is contained in:
Simon Marchetto 2013-09-06 15:33:58 +02:00
commit 06617dbd0b
2 changed files with 13 additions and 34 deletions

View file

@ -1,7 +1,8 @@
/* File : example.i */
%module example
/* A few preprocessor macros */
/* Forces to wrap constants as Scilab variables (instead of functions) */
%scilabconst(1);
#define ICONST 42
#define FCONST 2.1828
@ -24,17 +25,5 @@
%constant int iconst = 37;
%constant double fconst = 3.14;
/* Now constants are wrapped to Scilab variables */
%scilabconst(1);
#define ICONST2 12
#define FCONST2 4.60
#define CCONST3 'a'
#define CCONST4 '\n'
#define SCONST3 "Hello World"
#define SCONST4 "\"Hello World\""
%constant int iconst2 = 73;
%constant double fconst2 = 6.28;

View file

@ -3,35 +3,25 @@ exec loader.sce;
SWIG_Init();
printf("\nConstants are wrapped by functions:\n");
printf("ICONST_get() = %i (should be 42)\n", ICONST_get());
printf("FCONST_get() = %5.4f (should be 2.1828)\n", FCONST_get());
printf("CCONST_get() = ''%c'' (should be ''x'')\n", CCONST_get());
printf("CCONST2_get() = %s (this should be on a new line)\n", CCONST2_get());
printf("SCONST_get() = ''%s'' (should be ''Hello World'')\n", SCONST_get());
printf("SCONST2_get() = ''%s'' (should be "'""Hello World"""')\n", SCONST2_get());
printf("EXPR_get() = %5.4f (should be 48.5484)\n", EXPR_get());
printf("iconst_get() = %i (should be 37)\n", iconst_get());
printf("fconst_get() = %3.2f (should be 3.14)\n", fconst_get());
printf("ICONST = %i (should be 42)\n", ICONST);
printf("FCONST = %5.4f (should be 2.1828)\n", FCONST);
printf("CCONST = ''%c'' (should be ''x'')\n", CCONST);
printf("CCONST2 = %s (this should be on a new line)\n", CCONST2);
printf("SCONST = ''%s'' (should be ''Hello World'')\n", SCONST);
printf("SCONST2 = ''%s'' (should be "'""Hello World"""')\n", SCONST2);
printf("EXPR = %5.4f (should be 48.5484)\n", EXPR);
printf("iconst = %i (should be 37)\n", iconst);
printf("fconst = %3.2f (should be 3.14)\n", fconst);
try
printf("EXTERN = %s (Arg! This should not printf(anything)\n", EXTERN_get());
printf("EXTERN = %s (Arg! This should not printf(anything)\n", EXTERN);
catch
printf("EXTERN is not defined (good)\n");
end
try
printf("FOO = %i (Arg! This should not printf(anything)\n", FOO_get());
printf("FOO = %i (Arg! This should not printf(anything)\n", FOO);
catch
printf("FOO is not defined (good)\n");
end
printf("\nNow constants are wrapped by Scilab variables (feature scilab:const):\n");
printf("ICONST2 = %i (should be 12)\n", ICONST2);
printf("FCONST2 = %3.2f (should be 4.60)\n", FCONST2);
printf("CCONST3 = ''%c'' (should be ''a'')\n", CCONST3);
printf("CCONST4 = %s (this should be on a new line)\n", CCONST4);
printf("SCONST3 = ''%s'' (should be ''Hello World'')\n", SCONST3);
printf("SCONST4 = ''%s'' (should be "'""Hello World"""')\n", SCONST4);
printf("iconst2 = %i (should be 73)\n", iconst2);
printf("fconst2 = %3.2f (should be 6.28)\n", fconst2);
exit