summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Changelog4
-rw-r--r--lib/efl/eina_list.rb1
-rw-r--r--spec/eina_list_spec.rb22
3 files changed, 25 insertions, 2 deletions
diff --git a/Changelog b/Changelog
index f67848d..e629bb5 100644
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,7 @@
+2011-05-xx Jérémy Zurcher <jeremy@asynk.ch>
+ * add REinaList#from_a ptrt
+ * add REinaList#to_a ptrt=nil
+
2011-05-11 Jérémy Zurcher <jeremy@asynk.ch>
* use ditz ass issure tracker
* use FFI.attach_variable for EAPI extern ...
diff --git a/lib/efl/eina_list.rb b/lib/efl/eina_list.rb
index ba2bde3..7897827 100644
--- a/lib/efl/eina_list.rb
+++ b/lib/efl/eina_list.rb
@@ -58,6 +58,7 @@ module Efl
end
def to_a ptrt=nil
return inject([]) { |s,e| s<<e } if ptrt.nil?
+ inject([]) { |s,e| s<< e.send('read_'+ptrt.to_s) }
end
alias :to_ary :to_a
# for fun and tests
diff --git a/spec/eina_list_spec.rb b/spec/eina_list_spec.rb
index a51b148..230e9bb 100644
--- a/spec/eina_list_spec.rb
+++ b/spec/eina_list_spec.rb
@@ -38,7 +38,7 @@ describe Efl::EinaList do
end
#
it "should be able to convert into ruby Array from empty REinaList" do
- ary = REinaList.new.to_ary
+ ary = REinaList.new.to_a
ary.empty?.should be_true
ary.is_a?(Array).should be_true
end
@@ -71,7 +71,7 @@ describe Efl::EinaList do
l.prepend d2
l << d4
l.unshift d1
- ary = l.to_ary
+ ary = l.to_a
ary.length.should == 4
0.upto 3 do |i|
ary[i].read_string.should == "D#{i}"
@@ -79,6 +79,24 @@ describe Efl::EinaList do
l.free
end
#
+ it "should be able to convert into ruby Array from non empty REinaList pointer" do
+ l = REinaList.new
+ d1 = ::FFI::MemoryPointer.from_string "D0"
+ d2 = ::FFI::MemoryPointer.from_string "D1"
+ d3 = ::FFI::MemoryPointer.from_string "D2"
+ d4 = ::FFI::MemoryPointer.from_string "D3"
+ l.append d3
+ l.prepend d2
+ l << d4
+ l.unshift d1
+ ary = l.to_a :string
+ ary.length.should == 4
+ 0.upto 3 do |i|
+ ary[i].should == "D#{i}"
+ end
+ l.free
+ end
+ #
it "should be able to build from a ruby Array of pointers" do
a = []
a << ::FFI::MemoryPointer.from_string("D0")