Hi David,
> How do the features here compare to what you get for structs from h2xs
> or swig? Are these a superset of features they provide?
>From what I can tell, h2xs does a lot more than what I do. It uses C::Scan
to actually preprocess the code and pull out tons of info about #defines,
enums, and so on. I only deal with structs{}. Inline::* will only bind to
those things with typemap-able types.
Obviously, structs aren't typemapped, so Inline::Struct is basically an
add-on module to Inline::C and C++, so that they can bind functions with
prototypes that use Structs. As a bonus, it allows you to interrogate the
structs themselves directly.
Right now, Inline::Struct definitely provides only a subset of features
available in h2xs and swig. But it'll get better, and fast.
> I just went
> through the process of learning about h2xs, swig, and inline, then
> choosing inline for the module I'm working on. However, there were
> some nice things in h2xs & swig that aren't obvious to me how to do
> with inline. #defines, enums, etc.
Currently enums, #defines, and so on are definitely not supported. I can
add enums without much work, but it may want to go into another module,
Inline::Enum. RFC, anyone?
Remember, the main point of Inline is to facilitate putting _subroutines_
from other languages into Perl. It was never designed to do things like
import a C variable directly into the Perl namespace. Why not use a
function?
But #define'd constants would be a useful feature, and will probably work
their way into Inline::* some day soon.
> One bug I found in h2xs was handling a typedef'd enum embedded in a
> struct. Chokes trying to generate the typemap unless the embedded enum
> is anonymous. Is there any provision for enums in Inline::Struct?
No. But you've made me curious. Maybe there will be one by the type
Inline::Struct goes public :)
> On that topic, how about an 'h2inline'? Would be extremely handy for
> writing perl modules to wrap C libraries - parse a header, and emit a
> <module>.pm file full of Inline::c and Inline::Struct, plus lots of
> boilerplate POD. Optionally expose functions, structs, enums,
> #defines, constants, etc.
This is interesting. I never thought of that. I've always been thinking of
someone sitting in Perl, wanting to get out. I never considered the poor
souls in C, wanting to get in.
Later,
Neil