On Thu, 2002-09-12 at 21:10, Brent Dax wrote: > Aaron Sherman: > # I'm thinking XS thoughts
> # 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. I like "returns" as a property. Much cleaner, and I really like the ability to specify a return type generally. You do need to be able to specify the target language, though. > load module => System::FS, version => 1.0; I would think that this version number and the one in the module statement before would always be the same (since they're in the same file, and the XS is generated by this file). What's more, this whole statement could be considered "implied" by the use of C<Parrot::XS>. > #include <chdir's_header.h> Too magical. You need to have some way to specify an arbitrary string in your module that will be exported to the target language ala my "PREP" parameter. That C<#include> statement would go in the string along with any glue functions required. So, to re-write both of our suggestions as one: module System::FS is version(1.0.0); use Parrot::XS language => 'C', prep => q{ #include <unistd.h> }; sub chdir(string $path //= $ENV{HOME}) is external returns(class int); sub curdir() is external returns(class string); I stuck the "class" keyword in with the returns property because otherwise I think it's ambiguous. However, that was my simple example. Here again (and slightly re-written based on your suggestions) is my more complex example: module getpw is version(1.0.0); use Parrot::XS language => 'C', prep => q{ #include<pwd.h> #include<sys/types.h> }; class uid_t := class real; # Proposed class alias syntax (see below) class gid_t := class real; class passwd { my string $.pw_name; # Proposed pseudo-classes "string" and "real" my string $.pw_passwd; # are required to determine how to convert my int $.pw_uid; # the value to C my int $.pw_gid; my string $.pw_gecos; my string $.pw_dir; my string $.pw_shell; method storage { # storage returns a string name of the C type # or a listref to the field names if it's a # struct. If it's a scalar type in C, then # this class must contain a $.internal of the # appropriate Perl pseudo-class type (string, # int or real). return [qw{ pw_name pw_passwd pw_uid pw_gid pw_gecos pw_dir pw_shell }] } } sub getpwuid(uid_t $uid //= $_) is external returns(class passwd); -- Aaron Sherman <[EMAIL PROTECTED]> http://www.ajs.com/~ajs