Download SWIG Manual
Transcript
SWIG Users Guide
Extending SWIG
276
void MYLANG::create_function(char *name, char *iname, DataType *d, ParmList *l) {
fprintf(f_wrappers,”\nwrap_%s() { }\n\n”, name);
create_command(name,iname);
}
// --------------------------------------------------------------------// MYLANG::link_variable(char *name, char *iname, DataType *t)
//
// Create a link to a C variable.
//
name = Name of C variable
//
iname = Name of variable in scripting language
//
t = Datatype of the variable
// --------------------------------------------------------------------void MYLANG::link_variable(char *name, char *iname, DataType *t) {
fprintf(f_init,”\t Linking variable : %s\n”, iname);
}
// --------------------------------------------------------------------// MYLANG::declare_const(char *name, char *iname, DataType *type, char *value)
//
// Makes a constant.
//
name = Name of the constant
//
iname = Scripting language name of constant
//
type = Datatype of the constant
//
value = Constant value (as a string)
// --------------------------------------------------------------------void MYLANG::declare_const(char *name, char *iname, DataType *type, char *value) {
fprintf(f_init,”\t Creating constant : %s = %s\n”, name, value);
}
To compile our new language, we write a main program (as described previously) and do this :
% g++ main.cxx mylang.cxx -I/usr/local/include -L/usr/local/lib -lswig -o myswig
Now, try running this new version of SWIG on a few interface files to see what happens. The various printf() statements will show you where output appears and how it is structured. For
example, if we run this module on the following interface file :
/* File : example.i */
%module example
%{
/* Put headers and other declarations here */
%}
// A function
extern double foo(double a, double b);
// A variable
extern int bar;
// A constant
#define SPAM 42
We get the following output :
/*
Version 1.1, June 24, 1997