src/pmc/parrotio.pmc - Parrot IO
These are the vtable functions for Parrot IO.
METHOD INTVAL say(STRING *s)
- Print the string with an appended newline to SELF or to stdout if used as a class method.
METHOD PMC *open(STRING *file, STRING *mode, STRING *layer)
- Opens the file with the given mode,
using the given IO layer.
METHOD INTVAL isatty()
METHOD INTVAL set_readline_interactive(INTVAL)
- Sets readline interactive mode to the given value,
if PARROT_HAS_READLINE is defined,
if the readline library is available.
The return values are:
readline isn't configured
The file is not open/not input or not a tty,
if turning on interactive.
- 0 / 1
old interactive setting
METHOD PMC *readline(STRING *prompt)
- Reads a line from the given PIO.
If readline is interactive and a prompt is not empty,
it will be displayed.
The interactive feature is not available with the
readline opcode (which will be removed anyway).
Interactive mode adds non-empty lines to the readline history.
- Returns the line without the newline in a String PMC.
If ^D/eof occurred,
this will return a Null PMC.
pio = getstdin
$I0 = pio.'set_readline_interactive'(1)
if $I0 >= 0 goto loop
printerr "set_readline_interactive failed: "
$P1 = pio.'readline'('hello polly> ')
if null $P1 goto ex
- METHOD STRING *slurp(STRING *name);
- Slurp an (existing, disc) file named name into a STRING result.
- Please note that this method isn't catching any failures yet.
- Usage as class method:
.local pmc cl
cl = getclass 'ParrotIO'
$S0 = cl.'slurp'('the_file')
- The file will be opened, read, and closed.
- Or with an openend file:
pio = open 'the_file', '<'
$S0 = pio.'slurp'('')
- This does not close the file.
- Class initialization.
METHOD INTVAL eof()
- Returns true or false according to the end of file state of the object.
METHOD void flush()
- Flushes pending writes.
METHOD INTVAL setbuf(INTVAL)
- RT#46087 TBD
METHOD INTVAL setlinebuf()
- RT#46089 TBD
- Initializes the IO PMC.
- Destroys the IO PMC, flushing and closing as necessary.
- Clones the IO PMC.
- For now, both PMCs refer to the same
ParrotIO object. If we have different IO layers, we might copy
- Returns whether at
EOF or not.
STRING *get_string_keyed_int(INTVAL n)
- Returns the name of the nth layer. n >= 0 returns layer names up from the bottom. If n is negative, returns layer names from top down. For non-existent layers, returns an empty string.
void push_string(STRING *value)
- Pushes the layer name
value onto the PIO's layer stack.
- Pops a layer off the PIO's layer stack and returns its name.
Initial version by leo 2003/06/23.