Fixed raku example

This commit is contained in:
qorg11 2021-12-09 19:58:36 +01:00
parent d05f4f6837
commit b591de609b
No known key found for this signature in database
GPG Key ID: 343FC20A4ACA62B9
1 changed files with 5 additions and 5 deletions

View File

@ -48,18 +48,18 @@ Class Socket {
has Int $.sockfd;
method new ($path) {
my $mfd = create_socket();
connect_socket($mfd,$path);
self.bless(sockfd => $mfd);
my $mfd = create_socket(); # This is a function written in C called with NativeCall
connect_socket($mfd,$path); # Idem
self.bless(sockfd => $mfd); # Give the attributes to the object
}
method send($str) {
my $len = $str.chars;
write_to_sock(self.sockfd, $str, $len);
write_to_sock(self.sockfd, $str, $len); # C func
}
}
my $sock = Socket.new("path/to/socket");
$sock.write("hello from raku!");
$sock.send("hello from raku!");
</pre>
Calling C functions from Raku is stupidly easy, to do this only use