|
8 | 8 |
|
9 | 9 | X<|nativecall>
|
10 | 10 |
|
11 |
| -The simplest imaginable use of NativeCall would look something like this: |
| 11 | +The simplest imaginable use of C<NativeCall> would look something like this: |
12 | 12 |
|
13 | 13 | use NativeCall;
|
14 | 14 | sub some_argless_function() is native('something') { * }
|
@@ -59,47 +59,13 @@ an example.
|
59 | 59 | use NativeCall;
|
60 | 60 | sub add(int32, int32) returns int32 is native("calculator") { * }
|
61 | 61 |
|
62 |
| -Here, we have declared that the function takes two 32-bit integers and returns |
63 |
| -a 32-bit integer. Here are some of the other types that you may pass (this will |
64 |
| -likely grow with time). |
65 |
| -
|
66 |
| -X<|int8>X<|int16>X<|int32>X<|int64>X<|uint8>X<|uint16>X<|uint32>X<|uint64>X<|long>X<|longlong>X<|ulong>X<|ulonglong>X<|num32>X<|num64>X<|Str>X<|Pointer>X<|bool>X<|size_t>X<|ssize_t> |
67 |
| -=begin table |
68 |
| - int (long in C) |
69 |
| - int8 (int8_t in C, also used for char) |
70 |
| - int16 (int16_t in C, also used for short) |
71 |
| - int32 (int32_t in C, also used for int) |
72 |
| - int64 (int64_t in C) |
73 |
| - uint (ulong in C) |
74 |
| - uint8 (uint8_t in C, also used for unsigned char) |
75 |
| - uint16 (uint16_t in C, also used for unsigned short) |
76 |
| - uint32 (uint32_t in C, also used for unsigned int) |
77 |
| - uint64 (uint64_t in C) |
78 |
| - long (long in C) |
79 |
| - longlong (long long in C, at least 64-bit) |
80 |
| - ulong (unsigned long in C) |
81 |
| - ulonglong (unsigned long long in C, at least 64-bit) |
82 |
| - longdouble (longdouble in C) |
83 |
| - Num, num (double in C) |
84 |
| - num32 (float in C) |
85 |
| - num64 (double in C) |
86 |
| - Str (C string) |
87 |
| - CArray[int32] (int32_t* in C, an array of 32-bit ints) |
88 |
| - Pointer[void] (void* in C, can point to all other types) |
89 |
| - bool (bool from C99) |
90 |
| - size_t (size_t in C) |
91 |
| - ssize_t (ssize_t in C) |
92 |
| - Callable (callback in C) |
93 |
| -=end table |
94 |
| -
|
95 |
| -Don't use Perl 6 native types like C<int> or C<num> in native calls, as they |
96 |
| -don't have to correspond to the local C equivalent (e.g., Perl 6's C<int> can be |
97 |
| -8 bytes but C's C<int> is only 4 bytes). |
98 |
| -
|
99 |
| -Note that the lack of a C<returns> trait is used to indicate C<void> return type. |
100 |
| -Do I<not> use the C<void> type anywhere except in the Pointer parameterization. |
101 |
| -
|
102 |
| -For strings, there is an additional "encoded" trait to give some extra hints on |
| 62 | +Here, we have declared that the function takes two 32-bit integers and returns a |
| 63 | +32-bit integer. You can find the other types that you may pass in the |
| 64 | +L<native types|/language/nativetypes> page. Note that the lack of a C<returns> |
| 65 | +trait is used to indicate C<void> return type. Do I<not> use the C<void> type |
| 66 | +anywhere except in the Pointer parameterization. |
| 67 | +
|
| 68 | +For strings, there is an additional C<encoded> trait to give some extra hints on |
103 | 69 | how to do the marshaling.
|
104 | 70 |
|
105 | 71 | use NativeCall;
|
|
0 commit comments