Front page | perl.perl6.users |
Postings from June 2020
Re: an error I don't understand
Thread Previous
|
Thread Next
From:
Brad Gilbert
Date:
June 27, 2020 17:32
Subject:
Re: an error I don't understand
Message ID:
CAD2L-T3J1cu9UYsQhNtS+X5kVFqSrmPQYnXshqRB+29-4hA8nQ@mail.gmail.com
I don't know why you are getting an error.
But I think that this is one case where you should be writing `BUILD`
instead of `TWEAK`.
Note though that you can only have one `BUILD` or `TWEAK` per class.
---
Or maybe you want a multi method `new` instead?
multi method new ( :$native-object! ) {
samewith( x => $native-object.x, y => $native-object.y )
}
Assuming that `x` and `y` are actually public attributes you could pull
them out of the object in the signature.
multi method new ( :$native-object! (:$x, :$y) ) {
samewith( :$x, :$y )
}
If you need to throw out other public attributes, add `*%`
multi method new ( :$native-object! (:$x, :$y, *%) ) {
samewith( :$x, :$y )
}
---
Honestly I do not understand why you are passing in an already constructed
object, and I don't know anything about it either.
If you gave us answers for those two questions, we may be able to help you
better.
On Sat, Jun 27, 2020 at 10:56 AM Marcel Timmerman <mt1957@gmail.com> wrote:
> Hi,
>
> I am getting an error and don't know why it happens, it might even be a
> bug. It is about an assignment to a CStruct variable.
>
> The structure is defined like;
>
> class cairo_path_data_point_t is repr('CStruct') is export {
> has num64 $.x;
> has num64 $.y;
>
> submethod TWEAK ( :$native-object ) {
> $!x = $native-object.x;
> $!y = $native-object.y;
> }
> }
>
>
> The error is generated when typed variables are used (below, $x is also
> a cairo_path_data_point_t);
>
> my cairo_path_data_point_t $p1 = $x;
>
> or
>
> my cairo_path_data_point_t $p1 =
> cairo_path_data_point_t.new(:native-object($x));
>
> but not with
>
> my cairo_path_data_point_t $p1 .= new(:native-object($x));
>
> or
>
> my $p1 = $x;
>
> After which all fields in the structure are happely accessable using $p1!
>
>
> The error is
>
> Type check failed in assignment to $p1; expected cairo_path_data_point_t
> but got cairo_path_data_point_t.new(x => 0e0, y => 0e0)
>
>
> Raku version: 2020.06-7-gf1960baa9 built on MoarVM version
> 2020.06-6-gbf6af07de
> implementing Raku 6.d.
>
> The content of the structure does not matter, I've seen it with other
> structures too.
>
> Regards,
> Marcel
>
Thread Previous
|
Thread Next