Home | History | Annotate | Download | only in perl5
      1 
      2 /* Export the SWIG initialization function */
      3 %header %{
      4 #ifdef __cplusplus
      5 extern "C"
      6 #endif
      7 #ifndef PERL_OBJECT
      8 #ifndef MULTIPLICITY
      9 SWIGEXPORT void SWIG_init (CV* cv);
     10 #else
     11 SWIGEXPORT void SWIG_init (pTHXo_ CV* cv);
     12 #endif
     13 #else
     14 SWIGEXPORT void SWIG_init (CV *cv, CPerlObj *);
     15 #endif
     16 %}
     17 
     18 /* Module initialization function */
     19 
     20 %insert(init) "swiginit.swg"
     21 
     22 %init %{
     23 
     24 #ifdef __cplusplus
     25 extern "C"
     26 #endif
     27 
     28 XS(SWIG_init) {
     29     dXSARGS;
     30     int i;
     31 
     32     SWIG_InitializeModule(0);
     33 
     34     /* Install commands */
     35     for (i = 0; swig_commands[i].name; i++) {
     36       /* Casts only needed for Perl < 5.10. */
     37 #ifdef __cplusplus
     38       newXS(const_cast<char*>(swig_commands[i].name), swig_commands[i].wrapper, const_cast<char*>(__FILE__));
     39 #else
     40       newXS((char*)swig_commands[i].name, swig_commands[i].wrapper, (char*)__FILE__);
     41 #endif
     42     }
     43 
     44     /* Install variables */
     45     for (i = 0; swig_variables[i].name; i++) {
     46       SV *sv;
     47       sv = get_sv(swig_variables[i].name, TRUE | 0x2 | GV_ADDMULTI);
     48       if (swig_variables[i].type) {
     49 	SWIG_MakePtr(sv,(void *)1, *swig_variables[i].type,0);
     50       } else {
     51 	sv_setiv(sv,(IV) 0);
     52       }
     53       swig_create_magic(sv, swig_variables[i].name, swig_variables[i].set, swig_variables[i].get); 
     54     }
     55 
     56     /* Install constant */
     57     for (i = 0; swig_constants[i].type; i++) {
     58       SV *sv;
     59       sv = get_sv(swig_constants[i].name, TRUE | 0x2 | GV_ADDMULTI);
     60       switch(swig_constants[i].type) {
     61       case SWIG_INT:
     62 	sv_setiv(sv, (IV) swig_constants[i].lvalue);
     63 	break;
     64       case SWIG_FLOAT:
     65 	sv_setnv(sv, (double) swig_constants[i].dvalue);
     66 	break;
     67       case SWIG_STRING:
     68 	sv_setpv(sv, (const char *) swig_constants[i].pvalue);
     69 	break;
     70       case SWIG_POINTER:
     71 	SWIG_MakePtr(sv, swig_constants[i].pvalue, *(swig_constants[i].ptype),0);
     72 	break;
     73       case SWIG_BINARY:
     74 	SWIG_MakePackedObj(sv, swig_constants[i].pvalue, swig_constants[i].lvalue, *(swig_constants[i].ptype));
     75 	break;
     76       default:
     77 	break;
     78       }
     79       SvREADONLY_on(sv);
     80     }
     81 %}
     82