Aaron Sherman: # I'm thinking XS thoughts because we're going to need a few # external things at SOME point.... It would be so nice if Perl # 6's XS was part of the language, rather than an external # pre-processor. # # Something like: # # module somesuch; # use External (language=>"C"); # sub chdir(string $path //= $ENV{HOME}) is # external(returns=>'int');
I prefer: module System::FS is version(1.0.0); use Parrot::XS 'load'; sub chdir(string $path //= $ENV{HOME}) is external returns(int); sub curdir() is external returns(string); # 'returns' would be Perl's normal way to declare return # value, not a special thing for external functions only. load module => System::FS, version => 1.0; But that's just the shell around the real XS file: parrot_xs { module = System::FS; pversion = 0.0.8; xsversion = 0.0.1; modversion = 1.0.0; } #include <chdir's_header.h> xsub extern int chdir(char*); xsub char* curdir() { ... } /* Creates a wrapper and argument converter like: Parrot_PMC * Parrot_XS_System__FS_dispatch(Parrot_String func, Parrot_PMC obj, Parrot_PMC retto, Parrot_PMC args) { if(Parrot_string_eq_cstr(func, "chdir")) { Parrot_pmc_set_integer( retto, chdir( Parrot_string_to_cstr( Parrot_pmc_get_string( Parrot_pmc_get_keyed_integer( args, 0 ) ) ) ) ); } else if(Parrot_string_eq_cstr(func, "curdir")) { Parrot_pmc_set_string( retto, curdir() ); } else { Parrot_xs_die(Parrot_sprintf_cstr("Function %S not found!", func)); } } except with all the missing references to 'interpreter'. */ Of course, if you wanted to, you could use something like Inline.pm: module System::FS is version(1.0); use Parrot::XS::Inline; inline C => qq{ #include <chdir's_header.h> }; sub chdir(string $path //= $ENV{HOME} is external('C', 'int', 'char*') returns(int); sub curdir() is external('C', 'char*') returns(string) { /* C code here */ ... } --Brent Dax <[EMAIL PROTECTED]> @roles=map {"Parrot $_"} qw(embedding regexen Configure) "In other words, it's the 'Blow up this Entire Planet and Possibly One or Two Others We Noticed on our Way Out Here' operator." --Damian Conway