🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). Log available at irclogs.raku.org/raku/live.html . If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 6 September 2022.
lizmat clickbaits rakudoweekly.blog/2023/04/24/2023-...aseperiod/ 11:46
Anton Antonov @lizmat Thanks. 14:01
Xliff Hi. How can I turn a Callable into a function pointer so I can have C run my Raku routines via NativeCall? 16:33
m: use NativeCall; sub a { 1 }; my $b = nativecast(Pointer, &a); say $b
camelia Native call cast expected return type with CPointer, CStruct, CArray, or VMArray representation, but got a P6opaque (Sub)
in sub nativecast at /home/camelia/rakudo-m-inst-2/share/perl6/core/sources/DEC5BE9BC483C8510E136763F98614A8853D2A40 (NativeC…
Xliff That used to work.
I think.
Xliff m: use NativeCall; sub set_func_pointer( \func, &sprint) { my $bug = buf8.allocate(20); my $len = &sprint($buf, '%lldf', func); Pointer.new( $buf.subbuf(^$len).decode.Int ); }; sub a { 1 }; say set_func_pointer(&a, &sprintf) 16:39
camelia ===SORRY!=== Error while compiling <tmp>
Variable '$buf' is not declared. Did you mean any of these: 'Buf',
'$bug'?
at <tmp>:1
------> = buf8.allocate(20); my $len = &sprint(⏏$buf, '%lldf', func); Pointer.new( $buf.
Xliff m: use NativeCall; sub set_func_pointer( \func, &sprint) { my $buf = buf8.allocate(20); my $len = &sprint($buf, '%lldf', func); Pointer.new( $buf.subbuf(^$len).decode.Int ); }; sub a { 1 }; say set_func_pointer(&a, &sprintf)
camelia Cannot resolve caller sprintf(Buf[uint8]:D, Str:D, Sub:D); none of these signatures matches:
(Str(Cool) $format, *@args)
in sub set_func_pointer at <tmp> line 1
in block <unit> at <tmp> line 1
Xliff I had some old code do to it but was hoping things had simplified since then. 16:40
m: use NativeCall; sub set_func_pointer( \func, &sprint) { my $buf = buf8.allocate(20); my $len = &sprint($buf, '%lldf', func); Pointer.new( $buf.subbuf(^$len).decode.Int ); }; sub a { 1 }; sub sprintf-v (Blob, Str, &() ) returns int64 is native is symbol('sprintf'); say set_func_pointer(&a, &sprintf-v) 16:42
camelia ===SORRY!=== Error while compiling <tmp>
Shape declaration with () is reserved;
please use whitespace if you meant a subsignature for unpacking,
or use the :() form if you meant to add signature info to the function's type
at <tmp>:1…
Xliff m: use NativeCall; sub set_func_pointer( \func, &sprint) { my $buf = buf8.allocate(20); my $len = &sprint($buf, '%lldf', func); Pointer.new( $buf.subbuf(^$len).decode.Int ); }; sub a { 1 }; sub sprintf-v(Blob, Str, &() ) returns int64 is native is symbol('sprintf'); say set_func_pointer(&a, &sprintf-v)
camelia ===SORRY!=== Error while compiling <tmp>
Shape declaration with () is reserved;
please use whitespace if you meant a subsignature for unpacking,
or use the :() form if you meant to add signature info to the function's type
at <tmp>:1…
Xliff m: use NativeCall; sub set_func_pointer( \func, &sprint) { my $buf = buf8.allocate(20); my $len = &sprint($buf, '%lldf', func); Pointer.new( $buf.subbuf(^$len).decode.Int ); }; sub a { 1 }; sub sprintf-v(Blob, Str, & () ) returns int64 is native is symbol('sprintf'); say set_func_pointer(&a, &sprintf-v)
camelia ===SORRY!=== Error while compiling <tmp>
A unit-scoped sub definition is not allowed except on a MAIN sub;
Please use the block form. If you did not mean to declare a unit-scoped sub,
perhaps you accidentally placed a semicolon after routi…
Xliff I have to do this: 16:49
m: use NativeCall; sub sprintf-v(Blob, Str, & () ) returns int64 is native is symbol('sprintf') { * }; sub set_func_pointer( \func, &sprint) { my $buf = buf8.allocate(20); my $len = &sprint($buf, '%lld', func); $buf.say; my $b =$buf.subbuf(^$len).decode.Int; say $b; Pointer.new($b) }; sub a { 1 }; say set_func_pointer(&a, &sprintf-v)
camelia Buf[uint8]:0x<31 34 30 33 33 30 33 34 30 39 37 30 34 39 36 00 00 00 00 00>
140330340970496
NativeCall::Types::Pointer<0x7fa1341ff000>
Xliff Because Rakudo doesn't nativecast a Callable to a pointer... 16:49
Is there a better way?
sjn Heya; Is there a "latinize" method in Raku (e.g. one that will translate a Cyrillic Р to R)? 17:29
rf I think you can change encoding of a string if that's what you're after
lizmat sjn: not to my knowledge. Would it be more than just a .trans ? 17:36
Xliff How can I check if a routine was marked with "is rw" trait? 20:53
m: class A { method a is rw { 1 } }; .say for my $m = A.^lookup("a"); $m.^attributes[2].get_value($m).say 20:58
camelia a
1
Xliff Gotta be a better way than that... :( 20:59
Nemokosch there is an rw method on Methods 21:11
gfldex m: class A { method m is rw { } }; A.^lookup('m').rw.say; 22:03
camelia True
gfldex Xliff: ^^^
m: class A { multi method m is rw { } }; A.^can('m')».rw.say; 22:05
camelia (False)
gfldex No idea why that doesn't work for multies.
Nemokosch the metadata probably needs to belong to the proto; multi dispatch candidates are kinda fakers 22:12
lizmat m: class A { multi method m is rw { } }; A.^find_method("m").candidates.head.rw.say 22:23
camelia True
lizmat m: class A { multi method m { } }; A.^find_method("m").candidates.head.rw.say
camelia False
Xliff gfldex++ lizmat++ 23:04
uzl[m] lizmat++ gfldex++ 23:14