Re: Transparent packed C arrays




"Ilya Zakharevich" > wrote ...
>I was under impression that there was a Perl module which allowed
> "transparent" (via overloading) access to vectors represented as C
> arrays, e.g., to
>
> $array = pack('L*',@vec);
>
> so that r/w access, arithmetic operations etc. work without explicit
> unpack()ing. However, I could not find it quickly via CPAN search.
>
> Any hints?
>
> Thanks,
> Ilya

(useless semantic point:
a "hint" is a little prod towards the light from someone who already knows the answer.
In this case, it isn't me. )

Just a couple of comments:

--if you mean "bit-vectors", then it's not a module, it's just the 3rd member
of the "low-level string conversions", - "pack()", - "unpack()", ---and "vec()".

Other than that, on windows at least, there's the "Win32::API::Struct",
imported automatically by "Win32::API".

I don't know anything about it yet, so i can't say if it's what you want,
-but the top of its "DESCRIPTION" sounds promising: ....

[quoting from that: ....]
--------------------------------------------

Win32::API::Struct->typedef( NAME, TYPE, MEMBER, TYPE, MEMBER, ...)

This method defines a structure named NAME.
The definition consists of types and member names, just like in C.
In fact, most of the times you can cut the C definition for a structure
and paste it verbatim to your script, enclosing it in a qw() block.
The function takes care of removing the semicolon after the member name.

The synopsis example could be written like this:
Win32::API::Struct->typedef('POINT', 'LONG', 'x', 'LONG', 'y');
But it could also be written like this (note the indirect object syntax), which is pretty cool:
typedef Win32::API::Struct POINT =>
qw{
LONG x;
LONG y;
};

Also note that typedef automatically defines an 'LPNAME' type,
which holds a pointer to your structure. In the example above, 'LPPOINT'
is also defined and can be used in a call to a Win32::API
(in fact, this is what you're really going to use when doing API calls).

.....etc
------------------------------------------

~greg


.