Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Beazley D.M.SWIG users manual.pdf
Скачиваний:
13
Добавлен:
23.08.2013
Размер:
1.53 Mб
Скачать

SWIG Users Guide SWIG and Perl5 152

 

Function argument typemaps

 

 

char *

%typemap(perl5,in) char * {

 

$target = SvPV($source,na);

 

}

 

 

 

Function return typemaps

 

 

int,

%typemap(perl5,out) int,short,long {

short,

$target = sv_newmortal();

long

sv_setiv($target,(IV) $source);

 

argvi++;

 

}

 

 

float,

%typemap(perl5,out) float, double {

double

$target = sv_newmortal();

 

sv_setiv($target,(double) $source);

 

argvi++;

 

}

 

 

char *

%typemap(perl5,out) char * {

 

$target = sv_newmortal();

 

sv_setpv($target,$source);

 

argvi++;

 

}

 

 

Pointer handling

SWIG pointers are represented as blessed references. The following functions can be used to create and read pointer values.

SWIG Pointer Conversion Functions

void sv_setref_pv(SV *sv, char *type,

Turn the scalar value sv into a

void *ptr)

pointer. type is the type string and

 

ptr is the actual pointer value.

 

 

char *SWIG_GetPtr(SV *sv, void **ptr,

Extract a pointer value from scalar

char *type)

value sv. Performs type-checking

 

and pointer casting if necessary. If

 

type is NULL, any pointer value will

 

be accepted. The result will be

 

stored in ptr and NULL returned. On

 

failure, a pointer to the invalid por-

 

tion of the type string will be

 

returned.

 

 

Return values

Return values are placed on the argument stack of each wrapper function. The current value of the argument stack pointer is contained in a variable argvi. Whenever a new output value is added, it is critical that this value be incremented. For multiple output values, the final value of argvi should be the total number of output values.

Version 1.1, June 24, 1997