The great merge
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
6fcc22a1f8
commit
516036631c
1508 changed files with 125983 additions and 44037 deletions
13
SWIG/Examples/mzscheme/multimap/Makefile
Normal file
13
SWIG/Examples/mzscheme/multimap/Makefile
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../swig
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
SWIGOPT =
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' mzscheme
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile mzscheme_clean
|
||||
|
||||
check: all
|
||||
53
SWIG/Examples/mzscheme/multimap/example.c
Normal file
53
SWIG/Examples/mzscheme/multimap/example.c
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/* File : example.c */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/* Compute the greatest common divisor of positive integers */
|
||||
int gcd(int x, int y) {
|
||||
int g;
|
||||
g = y;
|
||||
while (x > 0) {
|
||||
g = x;
|
||||
x = y % x;
|
||||
y = g;
|
||||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
int gcdmain(int argc, char *argv[]) {
|
||||
int x,y;
|
||||
if (argc != 3) {
|
||||
printf("usage: gcd x y\n");
|
||||
return -1;
|
||||
}
|
||||
x = atoi(argv[1]);
|
||||
y = atoi(argv[2]);
|
||||
printf("gcd(%d,%d) = %d\n", x,y,gcd(x,y));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count(char *bytes, int len, char c) {
|
||||
int i;
|
||||
int count = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (bytes[i] == c) count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void capitalize(char *str, int len) {
|
||||
int i;
|
||||
for (i = 0; i < len; i++) {
|
||||
str[i] = toupper(str[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void circle(double x, double y) {
|
||||
double a = x*x + y*y;
|
||||
if (a > 1.0) {
|
||||
printf("Bad points %g, %g\n", x,y);
|
||||
} else {
|
||||
printf("Good points %g, %g\n", x,y);
|
||||
}
|
||||
}
|
||||
81
SWIG/Examples/mzscheme/multimap/example.i
Normal file
81
SWIG/Examples/mzscheme/multimap/example.i
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%include exception.i
|
||||
%include typemaps.i
|
||||
|
||||
extern int gcd(int x, int y);
|
||||
|
||||
%typemap(mzscheme,in) (int argc, char *argv[]) {
|
||||
int i;
|
||||
Scheme_Object **elms;
|
||||
if (!SCHEME_VECTORP($input)) {
|
||||
scheme_wrong_type("$name","vector",$argnum,argc,argv);
|
||||
}
|
||||
$1 = SCHEME_VEC_SIZE($input);
|
||||
elms = SCHEME_VEC_ELS($input);
|
||||
if ($1 == 0) {
|
||||
scheme_wrong_type("$name","vector",$argnum,argc,argv);
|
||||
}
|
||||
$2 = (char **) malloc(($1+1)*sizeof(char *));
|
||||
for (i = 0; i < $1; i++) {
|
||||
if (!SCHEME_STRINGP(elms[i])) {
|
||||
free($2);
|
||||
scheme_wrong_type("$name","vector",$argnum,argc,argv);
|
||||
}
|
||||
$2[i] = SCHEME_STR_VAL(elms[i]);
|
||||
}
|
||||
$2[i] = 0;
|
||||
}
|
||||
|
||||
%typemap(mzscheme,freear) (int argc, char *argv[]) {
|
||||
free($2);
|
||||
}
|
||||
extern int gcdmain(int argc, char *argv[]);
|
||||
|
||||
%typemap(mzscheme,in) (char *bytes, int len) {
|
||||
if (!SCHEME_STRINGP($input)) {
|
||||
scheme_wrong_type("$name","string",1,argc,argv);
|
||||
}
|
||||
$1 = SCHEME_STR_VAL($input);
|
||||
$2 = SCHEME_STRLEN_VAL($input);
|
||||
}
|
||||
|
||||
extern int count(char *bytes, int len, char c);
|
||||
|
||||
|
||||
/* This example shows how to wrap a function that mutates a string */
|
||||
|
||||
%typemap(mzscheme,in) (char *str, int len) {
|
||||
if (!SCHEME_STRINGP($input)) {
|
||||
scheme_wrong_type("$name","string",1,argc,argv);
|
||||
}
|
||||
$2 = SCHEME_STRLEN_VAL($input);
|
||||
$1 = (char *) malloc($2+1);
|
||||
memmove($1,SCHEME_STR_VAL($input),$2);
|
||||
}
|
||||
|
||||
/* Return the mutated string as a new object. */
|
||||
|
||||
%typemap(mzscheme,argout) (char *str, int len) {
|
||||
Scheme_Object *s;
|
||||
s = scheme_make_sized_string($1,$2,1);
|
||||
SWIG_APPEND_VALUE(s);
|
||||
free($1);
|
||||
}
|
||||
|
||||
extern void capitalize(char *str, int len);
|
||||
|
||||
/* A multi-valued constraint. Force two arguments to lie
|
||||
inside the unit circle */
|
||||
|
||||
%typemap(check) (double cx, double cy) {
|
||||
double a = $1*$1 + $2*$2;
|
||||
if (a > 1.0) {
|
||||
SWIG_exception(SWIG_ValueError,"$1_name and $2_name must be in unit circle");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern void circle(double cx, double cy);
|
||||
|
||||
|
||||
27
SWIG/Examples/mzscheme/multimap/example.scm
Normal file
27
SWIG/Examples/mzscheme/multimap/example.scm
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
;; run with mzscheme -r example.scm
|
||||
|
||||
(load-extension "example.so")
|
||||
|
||||
; Call the GCD function
|
||||
|
||||
(define x 42)
|
||||
(define y 105)
|
||||
(define g (gcd x y))
|
||||
|
||||
(display "The gcd of ")
|
||||
(display x)
|
||||
(display " and ")
|
||||
(display y)
|
||||
(display " is ")
|
||||
(display g)
|
||||
(newline)
|
||||
|
||||
; Call the gcdmain() function
|
||||
(gcdmain #("gcdmain" "42" "105"))
|
||||
|
||||
|
||||
(display (count "Hello World" #\l))
|
||||
(newline)
|
||||
|
||||
(display (capitalize "hello world"))
|
||||
(newline)
|
||||
Loading…
Add table
Add a link
Reference in a new issue