I am playing around with SWING building a Python module using the no brainer
example in http://www.swig.org/tutorial.html. With that first example,
/* File : example.c */
#include <time.h>
double My_variable = 3.0;
int fact(int n) {
if (n <= 1) return 1;
else return n*fact(n-1);
}
int my_mod(int x, int y) {
return (x%y);
}
char *get_time()
{
time_t ltime;
time(<ime);
return ctime(<ime);
}
and using the swig file of:
/* example.i */
%module example
%{
/* Put header files here (optional) */
%}
extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
I was able to execute this Python script:
[color=blue][color=green][color=darkred]
>>> import example
>>> example.fact(5)[/color][/color][/color]
120[color=blue][color=green][color=darkred]
>>> example.my_mod( 7,3)[/color][/color][/color]
1[color=blue][color=green][color=darkred]
>>> example.get_tim e()[/color][/color][/color]
'Sun Feb 11 23:01:07 1996'[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
However, when I try to access the gloabl variable My_variable by doing:
print example.cvar
I get a blank (rather then a value of 3.0).
Why?
--
It's me
example in http://www.swig.org/tutorial.html. With that first example,
/* File : example.c */
#include <time.h>
double My_variable = 3.0;
int fact(int n) {
if (n <= 1) return 1;
else return n*fact(n-1);
}
int my_mod(int x, int y) {
return (x%y);
}
char *get_time()
{
time_t ltime;
time(<ime);
return ctime(<ime);
}
and using the swig file of:
/* example.i */
%module example
%{
/* Put header files here (optional) */
%}
extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
I was able to execute this Python script:
[color=blue][color=green][color=darkred]
>>> import example
>>> example.fact(5)[/color][/color][/color]
120[color=blue][color=green][color=darkred]
>>> example.my_mod( 7,3)[/color][/color][/color]
1[color=blue][color=green][color=darkred]
>>> example.get_tim e()[/color][/color][/color]
'Sun Feb 11 23:01:07 1996'[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
However, when I try to access the gloabl variable My_variable by doing:
print example.cvar
I get a blank (rather then a value of 3.0).
Why?
--
It's me
Comment