Skip to content

Commit

Permalink
Update nativecall.pod6 (#4026)
Browse files Browse the repository at this point in the history
Closes #4025 

* Update nativecall.pod6

More emphasis how to use Pointer class.

* Update nativecall.pod6

* Update nativecall.pod6

* Update nativecall.pod6

removed trailing space

* Update nativecall.pod6
  • Loading branch information
jaffa4 committed Feb 10, 2022
1 parent 50f4853 commit 70a96d3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions doc/Language/nativecall.pod6
Expand Up @@ -187,6 +187,20 @@ When the signature of your native function needs a pointer to some native type
sub my_version(int32 is rw, int32 is rw) is native('foo') { * }
my_version(my int32 $major, my int32 $minor); # Pass a pointer to
When you just want to use/pass a pointer using Pointer class you have to
create the pointers when you declare them. Then you can do this without specifying
what type it points to. Here is an example:
use NativeCall;
# C prototype is void create_object(void **object)
sub create_object(Pointer is rw) is native('foo') { * }
my Pointer $p = Pointer.new();
create_object($p); # pointer is set by create_object
The C<Pointer> class can be used with types as well e.g. C<Pointer[Str]>.
Note that Str is a pointer to a string (C<char *> in C/C++). So in that case, you
can use C<Pointer[Str]> or C<Str>.
Sometimes you need to get a pointer (for example, a library handle) back from a
C library. You don't care about what it points to - you just need to keep hold
of it. The C<Pointer> type provides for this.
Expand Down

0 comments on commit 70a96d3

Please sign in to comment.