Added support for the D programming languge.
It is still a bit rough around some edges, particularly with regard to multi-threading and operator overloading, and there are some documentation bits missing, but it should be fine for basic use. The test-suite should build and run fine with the current versions of DMD, LDC and Tango (at least) on Linux x86_64 and Mac OS X 10.6. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12299 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
a355d2d46a
commit
03aefbc6e9
176 changed files with 16449 additions and 29 deletions
28
Examples/d/variables/Makefile
Normal file
28
Examples/d/variables/Makefile
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
ifeq (2,$(D_VERSION))
|
||||
WORKING_DIR = d2/
|
||||
else
|
||||
WORKING_DIR = d1/
|
||||
endif
|
||||
|
||||
TOP = ../../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
EXTRA_CFLAGS = -I../ ../example.c example_wrap.c
|
||||
EXTRA_LDFLAGS = example.o example_wrap.o
|
||||
TARGET = example_wrap
|
||||
SWIGOPT =
|
||||
DSRCS = *.d
|
||||
DFLAGS = -ofrunme
|
||||
|
||||
|
||||
all:: d
|
||||
|
||||
d::
|
||||
cd $(WORKING_DIR); \
|
||||
$(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \
|
||||
$(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
|
||||
|
||||
clean::
|
||||
cd $(WORKING_DIR); \
|
||||
$(MAKE) -f $(TOP)/Makefile d_clean
|
||||
|
||||
check: all
|
||||
71
Examples/d/variables/d1/runme.d
Normal file
71
Examples/d/variables/d1/runme.d
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
// This example illustrates global variable access from C#.
|
||||
module runme;
|
||||
|
||||
import tango.io.Stdout;
|
||||
static import example;
|
||||
|
||||
void main() {
|
||||
// Try to set the values of some global variables
|
||||
example.ivar = 42;
|
||||
example.svar = -31000;
|
||||
example.lvar = 65537;
|
||||
example.uivar = 123456;
|
||||
example.usvar = 61000;
|
||||
example.ulvar = 654321;
|
||||
example.scvar = -13;
|
||||
example.ucvar = 251;
|
||||
example.cvar = 'S';
|
||||
example.fvar = 3.14159f;
|
||||
example.dvar = 2.1828;
|
||||
example.strvar = "Hello World";
|
||||
example.iptrvar = example.new_int(37);
|
||||
example.ptptr = example.new_Point(37,42);
|
||||
example.name = "Bill";
|
||||
|
||||
// Now print out the values of the variables
|
||||
Stdout.formatln( "Variables (printed from D):" );
|
||||
Stdout.formatln( "ivar = {}", example.ivar );
|
||||
Stdout.formatln( "svar = {}", example.svar );
|
||||
Stdout.formatln( "lvar = {}", example.lvar );
|
||||
Stdout.formatln( "uivar = {}", example.uivar );
|
||||
Stdout.formatln( "usvar = {}", example.usvar );
|
||||
Stdout.formatln( "ulvar = {}", example.ulvar );
|
||||
Stdout.formatln( "scvar = {}", example.scvar );
|
||||
Stdout.formatln( "ucvar = {}", example.ucvar );
|
||||
Stdout.formatln( "fvar = {}", example.fvar );
|
||||
Stdout.formatln( "dvar = {}", example.dvar );
|
||||
Stdout.formatln( "cvar = {}", example.cvar );
|
||||
Stdout.formatln( "strvar = {}", example.strvar );
|
||||
Stdout.formatln( "cstrvar = {}", example.cstrvar );
|
||||
Stdout.formatln( "iptrvar = {}", example.iptrvar );
|
||||
Stdout.formatln( "name = {}", example.name );
|
||||
Stdout.formatln( "ptptr = {} {}", example.ptptr, example.Point_print(example.ptptr) );
|
||||
Stdout.formatln( "pt = {} {}", example.pt, example.Point_print(example.pt) );
|
||||
Stdout.formatln( "status = {}", example.status );
|
||||
|
||||
Stdout.formatln( "\nVariables (printed from the C library):" );
|
||||
example.print_vars();
|
||||
|
||||
Stdout.formatln( "\nNow I'm going to try and modify some read only variables:" );
|
||||
Stdout.formatln( "Checking that the read only variables are readonly..." );
|
||||
|
||||
Stdout( " 'path'..." );
|
||||
static if ( is( typeof( example.path = "a" ) ) )
|
||||
Stdout.formatln("Oh dear, this variable is not read only!");
|
||||
else
|
||||
Stdout.formatln("Good.");
|
||||
|
||||
Stdout( " 'status'..." );
|
||||
static if ( is( typeof( example.status = 2 ) ) )
|
||||
Stdout.formatln("Oh dear, this variable is not read only!");
|
||||
else
|
||||
Stdout.formatln("Good.");
|
||||
|
||||
Stdout.formatln( "\nI'm going to try and update a structure variable:" );
|
||||
|
||||
example.pt = example.ptptr;
|
||||
|
||||
Stdout( "The new value is " ).flush;
|
||||
example.pt_print();
|
||||
Stdout.formatln( "You should see the value {}", example.Point_print(example.ptptr) );
|
||||
}
|
||||
71
Examples/d/variables/d2/runme.d
Normal file
71
Examples/d/variables/d2/runme.d
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
// This example illustrates global variable access from C#.
|
||||
module runme;
|
||||
|
||||
import std.stdio;
|
||||
static import example;
|
||||
|
||||
void main() {
|
||||
// Try to set the values of some global variables
|
||||
example.ivar = 42;
|
||||
example.svar = -31000;
|
||||
example.lvar = 65537;
|
||||
example.uivar = 123456;
|
||||
example.usvar = 61000;
|
||||
example.ulvar = 654321;
|
||||
example.scvar = -13;
|
||||
example.ucvar = 251;
|
||||
example.cvar = 'S';
|
||||
example.fvar = 3.14159f;
|
||||
example.dvar = 2.1828;
|
||||
example.strvar = "Hello World";
|
||||
example.iptrvar = example.new_int(37);
|
||||
example.ptptr = example.new_Point(37,42);
|
||||
example.name = "Bill";
|
||||
|
||||
// Now print out the values of the variables
|
||||
writefln( "Variables (printed from D):" );
|
||||
writefln( "ivar = %s", example.ivar );
|
||||
writefln( "svar = %s", example.svar );
|
||||
writefln( "lvar = %s", example.lvar );
|
||||
writefln( "uivar = %s", example.uivar );
|
||||
writefln( "usvar = %s", example.usvar );
|
||||
writefln( "ulvar = %s", example.ulvar );
|
||||
writefln( "scvar = %s", example.scvar );
|
||||
writefln( "ucvar = %s", example.ucvar );
|
||||
writefln( "fvar = %s", example.fvar );
|
||||
writefln( "dvar = %s", example.dvar );
|
||||
writefln( "cvar = %s", example.cvar );
|
||||
writefln( "strvar = %s", example.strvar );
|
||||
writefln( "cstrvar = %s", example.cstrvar );
|
||||
writefln( "iptrvar = %s", example.iptrvar );
|
||||
writefln( "name = %s", example.name );
|
||||
writefln( "ptptr = %s %s", example.ptptr, example.Point_print(example.ptptr) );
|
||||
writefln( "pt = %s %s", example.pt, example.Point_print(example.pt) );
|
||||
writefln( "status = %s", example.status );
|
||||
|
||||
writefln( "\nVariables (printed from the C library):" );
|
||||
example.print_vars();
|
||||
|
||||
writefln( "\nNow I'm going to try and modify some read only variables:" );
|
||||
writefln( "Checking that the read only variables are readonly..." );
|
||||
|
||||
writeln( " 'path'..." );
|
||||
static if ( is( typeof( example.path = "a" ) ) )
|
||||
writefln("Oh dear, this variable is not read only!");
|
||||
else
|
||||
writefln("Good.");
|
||||
|
||||
writeln( " 'status'..." );
|
||||
static if ( is( typeof( example.status = 2 ) ) )
|
||||
writefln("Oh dear, this variable is not read only!");
|
||||
else
|
||||
writefln("Good.");
|
||||
|
||||
writefln( "\nI'm going to try and update a structure variable:" );
|
||||
|
||||
example.pt = example.ptptr;
|
||||
|
||||
write( "The new value is " );
|
||||
example.pt_print();
|
||||
writefln( "You should see the value %s", example.Point_print(example.ptptr) );
|
||||
}
|
||||
91
Examples/d/variables/example.c
Normal file
91
Examples/d/variables/example.c
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/* 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 "example.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;
|
||||
const char cstrvar[] = "Goodbye";
|
||||
int *iptrvar = 0;
|
||||
char name[256] = "Dave";
|
||||
char path[256] = "/home/beazley";
|
||||
|
||||
|
||||
/* Global variables involving a structure */
|
||||
Point *ptptr = 0;
|
||||
Point pt = { 10, 20 };
|
||||
|
||||
/* A variable that we will make read-only in the interface */
|
||||
int status = 1;
|
||||
|
||||
/* A debugging function to print out their values */
|
||||
|
||||
void print_vars() {
|
||||
printf("ivar = %d\n", ivar);
|
||||
printf("svar = %d\n", svar);
|
||||
printf("lvar = %ld\n", lvar);
|
||||
printf("uivar = %u\n", uivar);
|
||||
printf("usvar = %u\n", usvar);
|
||||
printf("ulvar = %lu\n", ulvar);
|
||||
printf("scvar = %d\n", scvar);
|
||||
printf("ucvar = %u\n", ucvar);
|
||||
printf("fvar = %g\n", fvar);
|
||||
printf("dvar = %g\n", dvar);
|
||||
printf("cvar = %c\n", cvar);
|
||||
printf("strvar = %s\n", strvar ? strvar : "(null)");
|
||||
printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)");
|
||||
printf("iptrvar = %p\n", iptrvar);
|
||||
printf("name = %s\n", name);
|
||||
printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0);
|
||||
printf("pt = (%d, %d)\n", pt.x, pt.y);
|
||||
printf("status = %d\n", status);
|
||||
}
|
||||
|
||||
/* A function to create an integer (to test iptrvar) */
|
||||
|
||||
int *new_int(int value) {
|
||||
int *ip = (int *) malloc(sizeof(int));
|
||||
*ip = value;
|
||||
return ip;
|
||||
}
|
||||
|
||||
/* A function to create a point */
|
||||
|
||||
Point *new_Point(int x, int y) {
|
||||
Point *p = (Point *) malloc(sizeof(Point));
|
||||
p->x = x;
|
||||
p->y = y;
|
||||
return p;
|
||||
}
|
||||
|
||||
char * Point_print(Point *p) {
|
||||
static char buffer[256];
|
||||
if (p) {
|
||||
sprintf(buffer,"(%d, %d)", p->x,p->y);
|
||||
} else {
|
||||
sprintf(buffer,"null");
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void pt_print() {
|
||||
printf("(%d, %d)\n", pt.x, pt.y);
|
||||
}
|
||||
6
Examples/d/variables/example.h
Normal file
6
Examples/d/variables/example.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
/* File: example.h */
|
||||
|
||||
typedef struct {
|
||||
int x,y;
|
||||
} Point;
|
||||
|
||||
49
Examples/d/variables/example.i
Normal file
49
Examples/d/variables/example.i
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
/* 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;
|
||||
extern const char cstrvar[];
|
||||
extern int *iptrvar;
|
||||
extern char name[256];
|
||||
|
||||
extern Point *ptptr;
|
||||
extern Point pt;
|
||||
%}
|
||||
|
||||
|
||||
/* Some read-only variables */
|
||||
|
||||
%immutable;
|
||||
|
||||
%inline %{
|
||||
extern int status;
|
||||
extern char path[256];
|
||||
%}
|
||||
|
||||
%mutable;
|
||||
|
||||
/* Some helper functions to make it easier to test */
|
||||
%inline %{
|
||||
extern void print_vars();
|
||||
extern int *new_int(int value);
|
||||
extern Point *new_Point(int x, int y);
|
||||
extern char *Point_print(Point *p);
|
||||
extern void pt_print();
|
||||
%}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue