Skip to content

Commit c53899d

Browse files
authored
Merge pull request #1209 from titsuki/add-cstruct-example
Add a concrete example of CStruct initialization
2 parents f98aa97 + fd1ad28 commit c53899d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

doc/Language/nativecall.pod6

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,22 @@ type of a native function, the memory is not managed for you by the GC.
286286
287287
NativeCall currently doesn't put object members in containers, so assigning new values
288288
to them (with =) doesn't work. Instead, you have to bind new values to the private
289-
members: C<$!struct-member := StructObj.new;>
289+
members:
290+
291+
class MyStruct is repr('CStruct') {
292+
has CArray[num64] $!arr;
293+
has Str $!str;
294+
has IntStruct $!int-struct;
295+
296+
submethod TWEAK {
297+
my $arr := CArray[num64].new;
298+
$arr[0] = 0.9e0;
299+
$arr[1] = 0.2e0;
300+
$!arr := $arr;
301+
$!str := 'Perl 6 is fun';
302+
$!int-struct := IntStruct.new;
303+
}
304+
}
290305
291306
As you may have predicted by now, a null is represented by the type object of the
292307
struct type.

0 commit comments

Comments
 (0)