From fd1ad2877725e94249150930028d47655f4bd33c Mon Sep 17 00:00:00 2001 From: titsuki Date: Tue, 21 Feb 2017 01:00:33 +0900 Subject: [PATCH] Add a concrete example of CStruct initialization --- doc/Language/nativecall.pod6 | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/Language/nativecall.pod6 b/doc/Language/nativecall.pod6 index 1513758db..2ec9eb9ee 100644 --- a/doc/Language/nativecall.pod6 +++ b/doc/Language/nativecall.pod6 @@ -286,7 +286,22 @@ type of a native function, the memory is not managed for you by the GC. NativeCall currently doesn't put object members in containers, so assigning new values to them (with =) doesn't work. Instead, you have to bind new values to the private -members: C<$!struct-member := StructObj.new;> +members: + + class MyStruct is repr('CStruct') { + has CArray[num64] $!arr; + has Str $!str; + has IntStruct $!int-struct; + + submethod TWEAK { + my $arr := CArray[num64].new; + $arr[0] = 0.9e0; + $arr[1] = 0.2e0; + $!arr := $arr; + $!str := 'Perl 6 is fun'; + $!int-struct := IntStruct.new; + } + } As you may have predicted by now, a null is represented by the type object of the struct type.