Skip to content

Commit

Permalink
Add a concrete example of CStruct initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
titsuki committed Feb 20, 2017
1 parent f98aa97 commit fd1ad28
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion doc/Language/nativecall.pod6
Expand Up @@ -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.
Expand Down

0 comments on commit fd1ad28

Please sign in to comment.