|
From: Sri <w2...@ya...> - 2009-12-04 13:18:29
|
Hello,
I am trying to map C array into perl a string and pass it as an *argument* to a perl subroutine (not as a "return value"). I tried a few things with typemaps (see below), however, unable to figureout how to accomplish this.
My situation is like this.
- One of the members in a C structure is a char array
typedef char NAME[100];
typedef struct { .... NAME name; ...} MyStruct;
- To pass the structure to Perl, I convert the entire C structure & push into the perl stack (right before invoking the perl subroutine). Using the SWIG_NewPointerObj is very conveient as I dont have to bother with the individual data members in the structure.
XPUSHs(SWIG_NewPointerObj(SWIG_as_voidptr(p_data), SWIGTYPE_p_tMyStruct, SWIG_SHADOW));
- The perl-sub uses a swig accessor function to retrieve the name field.
($arg) = @_;
$t_rname = myModule::tMyStruct::swig_name_get($arg);
When I print this, perl prints a "p_unsigned_char=SCALAR(0x8428ad0)".
I'm not sure how to now influence/change NewPointerObj so it can "typemap" this field so, Perl will automatically interpret it as a null terminated string?
I suspected it may not work, but tried adding an "out" typemap like this, but that doesnt work : as I understand, this typemap only modified the behavior of the accessor methods returning this type (NAME), but not how the structure is converted into the Perl object.
%typemap(out) (NAME) {
$result = newSVpv($1, strlen($1));
}
result..
SV = NULL(0x0) at 0x837a210
REFCNT = 1
FLAGS = ()
Is there a way to accomplish this with typemaps or some other SWIG feature?
Thanks
%typemap(out) (NAME) {
$result = newSVpv($1, strlen($1));
}
|