[macruby-changes] [916] MacRuby/branches/experimental/io.c

source_changes at macosforge.org source_changes at macosforge.org
Fri Mar 13 21:00:45 PDT 2009


Revision: 916
          http://trac.macosforge.org/projects/ruby/changeset/916
Author:   lsansonetti at apple.com
Date:     2009-03-13 21:00:45 -0700 (Fri, 13 Mar 2009)
Log Message:
-----------
naively implemented #readchar/#getchar

Modified Paths:
--------------
    MacRuby/branches/experimental/io.c

Modified: MacRuby/branches/experimental/io.c
===================================================================
--- MacRuby/branches/experimental/io.c	2009-03-14 03:53:50 UTC (rev 915)
+++ MacRuby/branches/experimental/io.c	2009-03-14 04:00:45 UTC (rev 916)
@@ -1278,7 +1278,21 @@
 static VALUE
 rb_io_getc(VALUE io, SEL sel)
 {
-    rb_notimplement();
+    rb_io_t *io_struct = ExtractIOStruct(io);
+    rb_io_assert_readable(io_struct);
+
+    // TODO should be encoding aware
+
+    UInt8 byte;
+    if (rb_io_read_internal(io_struct, &byte, 1) != 1) {
+	return Qnil;
+    }
+
+    char buf[2];
+    buf[0] = byte;
+    buf[1] = '\0';
+
+    return rb_str_new2(buf);
 }
 
 /*
@@ -1296,7 +1310,12 @@
 static VALUE
 rb_io_readchar(VALUE io, SEL sel)
 {
-    rb_notimplement();
+    VALUE c = rb_io_getc(io, 0);
+
+    if (NIL_P(c)) {
+	rb_eof_error();
+    }
+    return c;
 }
 
 /*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090313/a48e3224/attachment.html>


More information about the macruby-changes mailing list