add support for constants
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@11251 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
25f17ae463
commit
4e9cbd8a7c
15 changed files with 470 additions and 142 deletions
|
|
@ -1135,3 +1135,28 @@ r_clean:
|
|||
rm -f *.@OBJEXT@ *@SO@ NAMESPACE
|
||||
rm -f $(RRSRC) runme.Rout .RData
|
||||
|
||||
##################################################################
|
||||
##### SCILAB ######
|
||||
##################################################################
|
||||
|
||||
# Make sure these locate your Octave installation
|
||||
SCILAB_INCLUDE= $(DEFS) @SCILABINCLUDE@
|
||||
SCILAB_LIB = @SCILABLIB@
|
||||
SCILAB = @SCILAB@
|
||||
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# Build a C dynamically loadable module
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
scilab: $(SRCS)
|
||||
$(SWIG) -scilab $(SWIGOPT) $(INTERFACEPATH)
|
||||
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
# Cleaning the scilab examples
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
scilab_clean:
|
||||
rm -f *_wrap*
|
||||
|
||||
|
|
|
|||
27
Examples/scilab/constants/example.i
Normal file
27
Examples/scilab/constants/example.i
Normal file
|
|
@ -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;
|
||||
|
||||
|
||||
15
Examples/scilab/constants/makefile
Normal file
15
Examples/scilab/constants/makefile
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SRCS = example.i
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile scilab_clean
|
||||
rm -f *.sce *.so lib*lib.c
|
||||
|
||||
check: all
|
||||
32
Examples/scilab/constants/runme.sci
Normal file
32
Examples/scilab/constants/runme.sci
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// builder the *.so
|
||||
exec builder.sce;
|
||||
|
||||
//loader the *.so
|
||||
exec loader.sce;
|
||||
|
||||
printf("ICONST = %i (should be 42)\n", ICONST());
|
||||
printf("FCONST = %f (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 = %f (should be 48.5484)\n", EXPR());
|
||||
printf("iconst = %i (should be 37)\n", iconst());
|
||||
printf("fconst = %f (should be 3.14)\n", fconst());
|
||||
|
||||
try
|
||||
printf("EXTERN = %s (Arg! This should not printf(anything)\n", EXTERN());
|
||||
catch
|
||||
printf("EXTERN is not defined (good)\n");
|
||||
|
||||
try
|
||||
printf("FOO = %i (Arg! This should not printf(anything)\n", FOO());
|
||||
catch
|
||||
printf("FOO is not defined (good)\n");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
15
Examples/scilab/simple/makefile
Normal file
15
Examples/scilab/simple/makefile
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile scilab_clean
|
||||
rm -f *.sce *.so lib*lib.c
|
||||
|
||||
check: all
|
||||
|
|
@ -5,6 +5,7 @@ exec builder.sce;
|
|||
exec loader.sce;
|
||||
|
||||
// Call our gcd() function
|
||||
|
||||
x = 42;
|
||||
y = 105;
|
||||
g = gcd(x,y);
|
||||
|
|
@ -16,8 +17,8 @@ printf("The gcd of %d and %d is %d\n",x,y,g);
|
|||
Foo_get()
|
||||
|
||||
// Change its value
|
||||
Foo_set = 3.1415926
|
||||
Foo_set(3.1415926)
|
||||
|
||||
//See if the change took effect
|
||||
Foo_get
|
||||
Foo_get()
|
||||
|
||||
|
|
|
|||
46
Examples/scilab/variables/example.c
Normal file
46
Examples/scilab/variables/example.c
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/* File : example.c */
|
||||
|
||||
/* I'm a file containing some C global variables */
|
||||
|
||||
/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
|
||||
#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
|
||||
# define _CRT_SECURE_NO_DEPRECATE
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "sciprint.h"
|
||||
|
||||
int ivar = 0;
|
||||
short svar = 0;
|
||||
long lvar = 0;
|
||||
unsigned int uivar = 0;
|
||||
unsigned short usvar = 0;
|
||||
unsigned long ulvar = 0;
|
||||
signed char scvar = 0;
|
||||
unsigned char ucvar = 0;
|
||||
char cvar = 0;
|
||||
float fvar = 0;
|
||||
double dvar = 0;
|
||||
char *strvar=0;
|
||||
|
||||
|
||||
/* A debugging function to print out their values */
|
||||
|
||||
void print_vars() {
|
||||
sciprint("ivar = %d\n", ivar);
|
||||
sciprint("svar = %d\n", svar);
|
||||
sciprint("lvar = %ld\n", lvar);
|
||||
sciprint("uivar = %u\n", uivar);
|
||||
sciprint("usvar = %u\n", usvar);
|
||||
sciprint("ulvar = %lu\n", ulvar);
|
||||
sciprint("scvar = %d\n", scvar);
|
||||
sciprint("ucvar = %u\n", ucvar);
|
||||
sciprint("fvar = %g\n", fvar);
|
||||
sciprint("dvar = %g\n", dvar);
|
||||
sciprint("cvar = %c\n", cvar);
|
||||
sciprint("strvar = %s\n",strvar);
|
||||
}
|
||||
|
||||
|
||||
|
||||
27
Examples/scilab/variables/example.i
Normal file
27
Examples/scilab/variables/example.i
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
#pragma SWIG nowarn=SWIGWARN_TYPEMAP_SWIGTYPELEAK
|
||||
|
||||
/* Some global variable declarations */
|
||||
%inline %{
|
||||
extern int ivar;
|
||||
extern short svar;
|
||||
extern long lvar;
|
||||
extern unsigned int uivar;
|
||||
extern unsigned short usvar;
|
||||
extern unsigned long ulvar;
|
||||
extern signed char scvar;
|
||||
extern unsigned char ucvar;
|
||||
extern char cvar;
|
||||
extern float fvar;
|
||||
extern double dvar;
|
||||
extern char *strvar;
|
||||
%}
|
||||
|
||||
|
||||
/* Some helper functions to make it easier to test */
|
||||
%inline %{
|
||||
extern void print_vars();
|
||||
%}
|
||||
|
||||
15
Examples/scilab/variables/makefile
Normal file
15
Examples/scilab/variables/makefile
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile scilab_clean
|
||||
rm -f *.sce *.so lib*lib.c
|
||||
|
||||
check: all
|
||||
45
Examples/scilab/variables/runme.sci
Normal file
45
Examples/scilab/variables/runme.sci
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// builder the *.so
|
||||
exec builder.sce
|
||||
|
||||
//loader the *.so
|
||||
exec loader.sce
|
||||
|
||||
// Try to set the values of some global variables
|
||||
|
||||
ivar_set (42);
|
||||
svar_set (31000);
|
||||
lvar_set (65537);
|
||||
uivar_set (123456);
|
||||
usvar_set (61000);
|
||||
ulvar_set (654321);
|
||||
scvar_set (-13);
|
||||
ucvar_set (251);
|
||||
cvar_set ("S");
|
||||
fvar_set (3.14159);
|
||||
dvar_set (2.1828);
|
||||
strvar_set("Hello World");
|
||||
|
||||
// Now print out the values of the variables
|
||||
|
||||
printf("Variables (values printed from Scilab)\n");
|
||||
|
||||
printf("ivar = %i\n", ivar_get());
|
||||
printf("svar = %i\n", svar_get());
|
||||
printf("lvar = %i\n", lvar_get());
|
||||
printf("uivar = %i\n", uivar_get());
|
||||
printf("usvar = %i\n", usvar_get());
|
||||
printf("ulvar = %i\n", ulvar_get());
|
||||
printf("scvar = %i\n", scvar_get());
|
||||
printf("ucvar = %i\n", ucvar_get());
|
||||
printf("fvar = %f\n", fvar_get());
|
||||
printf("dvar = %f\n", dvar_get());
|
||||
printf("cvar = %s\n", cvar_get());
|
||||
printf("strvar = %s\n", strvar_get());
|
||||
|
||||
printf("\nVariables (values printed from C)\n");
|
||||
|
||||
print_vars()
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue