Skip to content

Instantly share code, notes, and snippets.

/test.p6 Secret

Created March 16, 2016 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6e111a1914dfc938c644 to your computer and use it in GitHub Desktop.
Save anonymous/6e111a1914dfc938c644 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl6
use NativeCall;
constant TtyLIB = "/home/daryl/Documents/projets-prog/perl6/p6-IO-Handle-Tty/src/C/libTty.so";
class winsize is repr('CStruct') {
has uint16 $.ws_row;
has uint16 $.ws_col;
has uint16 $.ws_xpixel;
has uint16 $.ws_ypixel;
}
class c_repr_pty is repr('CStruct') {
has int32 $!ptyfd;
has int32 $!ttyfd;
has Str $!name;
method ptyfd { $!ptyfd; }
method ttyfd { $!ttyfd; }
method name { $!name; }
}
sub pty_allocate() returns c_repr_pty is native(TtyLIB) { ... }
class IO::Tty {
has int32 $!ttyfd;
has winsize $!winsize;
method ttyfd { $!ttyfd; }
method set_ttyfd($new_ttyfd) { $!ttyfd = $new_ttyfd; }
}
class IO::Pty is IO::Handle {
has IO::Tty $.slave;
has int32 $ptyfd;
method allocate() {
my $c_pty = pty_allocate();
}
}
# I want to be able to do that :
IO::Pty.new.allocate;
IO::Pty.new('/path/to/file');
IO::Pty.new($pty); # $pty being IO::Pty
# but i don't known how i should create my BUILD/BUIDALL methods ... =(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment