Sha256: 0bf89dd182f8bae50225a34ffa6ee008a2b968054dda4bf6b7c60d519d7b6061

Contents?: true

Size: 840 Bytes

Versions: 21

Compression:

Stored size: 840 Bytes

Contents

`/* global imports */`

# Basic version, appends \n:
# $stdout.write_proc = `function(s){print(s)}`
# $stderr.write_proc = `function(s){printerr(s)}`

# Advanced version:
%x{
  var GLib = imports.gi.GLib;
  var ByteArray = imports.byteArray;

  var stdin = GLib.IOChannel.unix_new(0);
  var stdout = GLib.IOChannel.unix_new(1);
  var stderr = GLib.IOChannel.unix_new(2);

  Opal.gvars.stdout.write_proc = function(s) {
    var buf = ByteArray.fromString(s);
    stdout.write_chars(buf, buf.length);
    stdout.flush();
  }

  Opal.gvars.stderr.write_proc = function(s) {
    var buf = ByteArray.fromString(s);
    stderr.write_chars(buf, buf.length);
    stderr.flush();
  }

  Opal.gvars.stdin.read_proc = function(_s) {
    var out = stdin.read_line();
    if (out[0] == GLib.IOStatus.EOF) return nil;
    return out[1].toString();
  }
}

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
opal-1.7.4 stdlib/gjs/io.rb
opal-1.7.3 stdlib/gjs/io.rb
opal-1.7.2 stdlib/gjs/io.rb
opal-1.7.1 stdlib/gjs/io.rb
opal-1.7.0 stdlib/gjs/io.rb
opal-1.7.0.rc1 stdlib/gjs/io.rb
opal-1.6.1 stdlib/gjs/io.rb
opal-1.6.0 stdlib/gjs/io.rb
opal-1.6.0.rc1 stdlib/gjs/io.rb
opal-1.6.0.alpha1 stdlib/gjs/io.rb
opal-1.5.1 stdlib/gjs/io.rb
opal-1.5.0 stdlib/gjs/io.rb
opal-1.5.0.rc1 stdlib/gjs/io.rb
opal-1.4.1 stdlib/gjs/io.rb
opal-1.4.0 stdlib/gjs/io.rb
opal-1.4.0.alpha1 stdlib/gjs/io.rb
opal-1.3.2 stdlib/gjs/io.rb
opal-1.3.1 stdlib/gjs/io.rb
opal-1.3.0 stdlib/gjs/io.rb
opal-1.3.0.rc1 stdlib/gjs/io.rb