[macruby-changes] [4034] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu May 6 16:00:58 PDT 2010


Revision: 4034
          http://trac.macosforge.org/projects/ruby/changeset/4034
Author:   lsansonetti at apple.com
Date:     2010-05-06 16:00:56 -0700 (Thu, 06 May 2010)
Log Message:
-----------
allow Pointer objects of type 'c' to be passed as C-style char arrays

Modified Paths:
--------------
    MacRuby/trunk/compiler.cpp
    MacRuby/trunk/spec/macruby/core/pointer_spec.rb

Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp	2010-05-06 22:01:33 UTC (rev 4033)
+++ MacRuby/trunk/compiler.cpp	2010-05-06 23:00:56 UTC (rev 4034)
@@ -6077,6 +6077,9 @@
 	    case T_SYMBOL:
 		return rb_sym2name(rval);
 	}
+	if (rb_obj_is_kind_of(rval, rb_cPointer)) {
+	    return (const char *)rb_pointer_get_data(rval, "^c");
+	}
 	return StringValueCStr(rval);
     }
 }

Modified: MacRuby/trunk/spec/macruby/core/pointer_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/pointer_spec.rb	2010-05-06 22:01:33 UTC (rev 4033)
+++ MacRuby/trunk/spec/macruby/core/pointer_spec.rb	2010-05-06 23:00:56 UTC (rev 4034)
@@ -185,4 +185,14 @@
     pointer2.type.should == NSRect.type
     pointer2[0].should == NSMakeRect(10, 20, 30, 40)
   end
+
+  it "of type 'c' can be passed as a C-style char array argument" do
+    s = NSString.stringWithString('foo')
+    ptr = Pointer.new(:char, 4)
+    s.getCString(ptr, maxLength: 4, encoding: NSASCIIStringEncoding).should == true
+    ptr[0].should == 102
+    ptr[1].should == 111
+    ptr[2].should == 111
+    ptr[3].should == 0
+  end
 end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100506/16667873/attachment-0001.html>


More information about the macruby-changes mailing list