http://qs1969.pair.com?node_id=485783


in reply to Re: XS Modules: Dependencies
in thread XS Modules: Dependencies

Yes, i know that. But XS is actually needed since i want to write a OO interface to a (non trivial) Win32 C API.
(and for sure, i know how to walk! :) )
so for now i have the following code

Foo-Bar/typemap
TYPEMAP PBar T_PTROBJ
Foo-Bar/Bar.xs
typedef struct __Bar { // ... } Bar, *PBar; MODULE = Foo::Bar PACKAGE = Foo::Bar PBar new(class); const char* class PREINIT: PBar retval; CODE: New(0, retval, 1, Bar); RETVAL = retval; OUTPUT: RETVAL
Foo-Bar-Builder/typemap
TYPEMAP PBarBuilder T_PTROBJ PBar T_PTROBJ
Foo-Bar-Builder/Builder.xs
typedef struct __BarBuilder { // ... } BarBuilder, *PBarBuilder; MODULE = Foo::Bar::Builder PACKAGE = Foo::Bar::Builder PBarBuilder new(class); const char* class PREINIT: PBarBuilder retval; CODE: New(0, retval, 1, BarBuilder); RETVAL = retval; OUTPUT: RETVAL MODULE = Foo::Bar::Builder PACKAGE = Foo::Bar::BuilderPtr PBar create(void); PREINIT: PBar retval; CODE: RETVAL = retval; OUTPUT: RETVAL

so, the question is: do i have to call Foo::Bar::new inside Foo::Bar::Builder::create? or do i have to reimplement the new function of Foo::Bar::new inside Foo::Bar::Builder, or what?
so, the Foo::Bar::new is now defined inside the Foo/Bar/Bar.dll, and the C compiler does not know, where to find it. I guess it does not help to link against Foo\Bar\Bar.lib, since the dll just exports
1    0 00001000 _boot_Foo__Bar
2    1 00001000 boot_Foo__Bar
Get the point?

Replies are listed 'Best First'.
Re^3: XS Modules: Dependencies
by diotalevi (Canon) on Aug 23, 2005 at 13:32 UTC

    It looks like you're doing too much in XS and not enough in perl. Why can't you have your C-allocating routines just return a numified pointer and let perl do all of its own OO stuff? I also feel like I'm getting lost somewhere in your confused code. I'd really like to point you at Simon Cozen's Embedding and Extending Perl book. Or Damian Conway's Object Oriented Perl.

    sub new { my ( $class ) = @_; my $c_ptr = Foo::Bar::_new_or_whatever(); return bless \ $c_ptr, $class; }
      just do it. i have both in my book shelf. :)
      and thanks, i will give it a try