Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation improvement for NativeCall #6290

Closed
p6rt opened this issue May 29, 2017 · 4 comments
Closed

Documentation improvement for NativeCall #6290

p6rt opened this issue May 29, 2017 · 4 comments

Comments

@p6rt
Copy link

p6rt commented May 29, 2017

Migrated from rt.perl.org#131396 (status was 'resolved')

Searchable as RT131396$

@p6rt
Copy link
Author

p6rt commented May 29, 2017

From @BenGoldberg1

The ‘is native’ trait works on methods. It would be nice if this were
documented.
Also, users can (and probably should) create their own traits which call
trait_mod​:<is>(Routine, :$native);

If we start with the code in
https://perl6advent.wordpress.com/2015/12/21/day-21-nativecall-backs-and-beyond-c/
we can modify it as follows​:

multi trait_mod​:<is>(Routine $r, :$e!) {
  trait_mod​:<is>($r, native => ‘expat’);
  trait_mod​:<is>($r, symbol => ‘XML_’ ~ $name);
};
class XML_Parser is repr(‘CPointer’) {
  multi trait_mod​:<is>(Routine $r, :$p!) {
  trait_mod​:<is>($r, native => ‘expat’);
  trait_mod​:<is>($r, symbol => ‘XML_Parser’ ~ $name);
  };

  method SetElemetHandler(
  &start (OpaquePointer, Str, CArray[Str]), &end (OpaquePointer, Str))
  ) {...} is e;
  our sub Create(Str -> XML_Parser) is p {...};
  method Free() is p {...};
  method Parse(Buf, int32, int32 --> int32) is e {...};
}

my $xml = ...;
my $parser = XML_Parser​::Create('UTF-8');
$parser.SetElementHandler($parser, &start-element, &end-element);
my $buf = $xml.encode('UTF-8');
$parser.Parse($buf, $buf.elems, 1);
$parser.Free;

We could make the code even more compact, with the aid of a module to
generate 'e' and 'p' for us.
That module might be used as​:
  use NativeCall​::MakeTrait "e", native => "expat", prefix => 'XML_';
  use NativeCall​::MakeTrait "p", native => "expat", prefix =>
'XML_Parser';
with details for that module left as an exercise for the reader :).

@p6rt
Copy link
Author

p6rt commented Jun 12, 2017

From @zoffixznet

Moved to doc repo ticket queue​: Raku/doc#1376

@p6rt
Copy link
Author

p6rt commented Jun 12, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jun 12, 2017

@zoffixznet - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Jun 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant