-
Notifications
You must be signed in to change notification settings - Fork 14
/
Nativecallable.p6
executable file
·42 lines (35 loc) · 1.51 KB
/
Nativecallable.p6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env perl6
use Whateverable;
use Whateverable::Bits;
use Whateverable::Output;
use Whateverable::Processing;
unit class Nativecallable does Whateverable;
method help($msg) {
“Like this {$msg.server.current-nick}: <some C definition>”;
}
sub run-gptrixie($header-file) {
my %ENV = %*ENV.clone;
%ENV<PATH> = join ‘:’, $*EXECUTABLE.parent, %ENV<PATH>;
my %output = get-output :%ENV, ‘gptrixie’, '--silent', ‘--all’, ‘--castxml=c99’, $header-file;
if %output<output>.lines > 20 {
return ‘’ but FileStore(%(‘GPTrixiefied.pm6’ => "#Generated by App::GPTrixie\n" ~ %output<output>))
}
my @pruned-output;
@pruned-output = %output<output>.lines.grep: { $_ and not .starts-with: ‘#’ };
if @pruned-output ≤ 10 {
return (@pruned-output.map: {.subst(/\s+/, " ", :g)}).join: “\n”;
}
my $definitive-output //= %output<output>;
‘’ but FileStore(%(‘result.pm6’ => "#Generated by App::GPTrixie\n" ~ $definitive-output))
}
multi method irc-to-me($msg where /^ \s* $<code>=.+ /) {
my $file = process-code $<code>, $msg;
my $code = slurp $file;
$file.unlink;
my $header-file = '/tmp/gptnc.h';
spurt $header-file, “\n#include <stddef.h>\n#include <stdbool.h>\n” ~ $code;
LEAVE unlink $_ with $header-file;
run-gptrixie($header-file)
}
Nativecallable.new.selfrun: ‘nativecallable6’, [ / nativecall6? <before ‘:’> /,
fuzzy-nick(‘nativecallable6’, 2) ];