On 2020-12-04 20:28, Curt Tilmes wrote:
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;
}




Hi Curt,

What am I doing wrong?

#!/usr/bin/env raku

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;
}

$ ListPrinters.pl6
Cannot locate native library 'libcups.so': libcups.so: cannot open shared object file: No such file or directory in method setup at /opt/rakudo-pkg/share/perl6/core/sources/947BDAB9F96E0E5FCCB383124F923A6BF6F8D76B (NativeCall) line 298 in block cupsGetDests at /opt/rakudo-pkg/share/perl6/core/sources/947BDAB9F96E0E5FCCB383124F923A6BF6F8D76B (NativeCall) line 587


$ locate libcups.so
/usr/lib/libcups.so.2
/usr/lib64/libcups.so.2


-T

Reply via email to