Skip to content

Commit 736e101

Browse files
committed
TWEAK → BUILD closes #1903
1 parent b6dc8f5 commit 736e101

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

doc/Language/nativecall.pod6

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ from the Perl 6 point of view:
297297
298298
=item C<AT-POS> provides a specific element at the given position (starting from zero);
299299
300-
=item C<list> provides the L<List> of elements within the array building it from the
301-
native array iterator.
300+
=item C<list> provides the L<List> of elements within the array building
301+
it from the native array iterator.
302302
303303
As an example, consider the following simple piece of code:
304304
@@ -443,22 +443,20 @@ class AStringAndAnInt is repr("CStruct") {
443443
has Str $.a_string;
444444
has int32 $.an_int32;
445445
446-
submethod TWEAK {
447-
$!a_string := Str.new;
448-
$!an_int32 = 0;
449-
}
450-
451446
sub init_struct(AStringAndAnInt is rw, Str, int32) is native('simple-struct') { * }
452-
method init(:$a_string, :$an_int) {
447+
448+
submethod BUILD(:$a_string, :$an_int) {
453449
init_struct(self, $a_string, $an_int);
454450
}
455451
}
456452
457453
=end code
458454
459-
In this code we first set up our members, C<$.a_string> and C<$.an_int32>. We then
460-
set the container of C<$.a_string> to a new C<Str>. After that we declare our
461-
C<init_struct()> function for the C<init()> method to wrap around.
455+
In this code we first set up our members, C<$.a_string> and
456+
C<$.an_int32>. After that we declare our C<init_struct()> function for
457+
the C<init()> method to wrap around; this function is then called from
458+
C<BUILD> to effectively assign the values before returning the created
459+
object.
462460
463461
=head3 In your C code...
464462
@@ -490,13 +488,11 @@ memory that it points <char *a_string> to within the structure as it
490488
copies the string. (Note you will also have to manage deallocation of
491489
the memory as well to avoid memory leaks.)
492490
491+
=begin code :preamble<class AStringAndAnInt {}>
493492
# A long time ago in a galaxy far, far away...
494-
495-
=begin code :skip-test
496-
497-
my $foo = AStringAndAnInt.new;
498-
$foo.init(a_string => "str", an_int => 123);
499-
493+
my $foo = AStringAndAnInt.new(a_string => "str", an_int => 123);
494+
say "foo is {$foo.a_string} and {$foo.an_int32}";
495+
# OUTPUT: «foo is str and 123␤»
500496
=end code
501497
502498
=head1 Typed Pointers

0 commit comments

Comments
 (0)