[MacRuby] #942: feature: Please implement Pointer#to_a, Pointer#each.

MacRuby ruby-noreply at macosforge.org
Thu Oct 7 19:45:13 PDT 2010


#942: feature: Please implement Pointer#to_a, Pointer#each.
----------------------------------+-----------------------------------------
 Reporter:  watson1978@…          |       Owner:  lsansonetti@…        
     Type:  enhancement           |      Status:  new                  
 Priority:  minor                 |   Milestone:                       
Component:  MacRuby               |    Keywords:                       
----------------------------------+-----------------------------------------
 I hope to implement Pointer#to_a, Pointer#each, because it is serious to
 take out the value of Pointer instances.

 Now:
 {{{
 framework "JavaScriptCore"

 string = JSStringCreateWithUTF8CString("hello")
 size = JSStringGetMaximumUTF8CStringSize(string)
 buffer = Pointer.new('c', size)
 ret = JSStringGetUTF8CString(string, buffer, size)

 ary = []
 (ret - 1).times do |i|
   ary << buffer[i]
 end
 puts ary.pack('c*')
 }}}


 If possible, I want to write as following:
 {{{
 framework "JavaScriptCore"

 string = JSStringCreateWithUTF8CString("hello")
 size = JSStringGetMaximumUTF8CStringSize(string)
 buffer = Pointer.new('c', size)
 ret = JSStringGetUTF8CString(string, buffer, size)

 puts buffer.to_a.pack('c*')
 }}}

 {{{
 framework "JavaScriptCore"

 string = JSStringCreateWithUTF8CString("hello")
 size = JSStringGetMaximumUTF8CStringSize(string)
 buffer = Pointer.new('c', size)
 ret = JSStringGetUTF8CString(string, buffer, size)

 ary = []
 buffer.each do |byte|
   ary << byte
 end
 puts ary.pack('c*')
 }}}

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/942>
MacRuby <http://macruby.org/>



More information about the macruby-tickets mailing list