On Fri, Dec 4, 2020 at 10:52 PM ToddAndMargo via perl6-users <perl6-us...@perl.org> wrote:
> This is the C way, although it shows deleted printers as well: > > #include <iostream> > #include <cups/cups.h> > > int main() { > cups_dest_t* dests; > int nCount = cupsGetDests2(CUPS_HTTP_DEFAULT, &dests); > > for (int i = 0; i < nCount; i++) { > cups_dest_t dest = dests[i]; > std::cout << dest.name << std::endl; > } > } Roughly translating that into Raku Nativecall (my system has cupsGetDests(), but not cupsGetDests2() -- you'll have to update to that) use NativeCall; class CupsDest is repr('CStruct') { has Str $.name; # This is the first field in the struct -- add more if you need them } sub cupsGetDests(Pointer is rw --> int32) is native('cups') {} my $ptr = Pointer.new; my $nCount = cupsGetDests($ptr); for ^$nCount -> $i { my $dest = nativecast(CupsDest, Pointer.new($ptr + $i * nativesizeof(Pointer))); say $dest.name; }