summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/efl/eina_list.rb11
-rw-r--r--spec/eina_list_spec.rb11
2 files changed, 19 insertions, 3 deletions
diff --git a/lib/efl/eina_list.rb b/lib/efl/eina_list.rb
index 15c1707..ba2bde3 100644
--- a/lib/efl/eina_list.rb
+++ b/lib/efl/eina_list.rb
@@ -40,6 +40,13 @@ module Efl
Native.eina_list_free @ptr
@ptr = nil
end
+ def self.from_a ary, ptrt
+ REinaList.new ary.inject(FFI::Pointer::NULL) { |p,e|
+ ptr = FFI::MemoryPointer.new ptrt
+ ptr.send 'write_'+ptrt.to_s, e
+ Native.eina_list_append p, ptr
+ }
+ end
def each
return if not block_given?
p = @ptr
@@ -49,8 +56,8 @@ module Efl
p = l[:next]
end
end
- def to_a
- inject([]) { |s,e| s<<e }
+ def to_a ptrt=nil
+ return inject([]) { |s,e| s<<e } if ptrt.nil?
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 0cf2501..a51b148 100644
--- a/spec/eina_list_spec.rb
+++ b/spec/eina_list_spec.rb
@@ -79,7 +79,7 @@ describe Efl::EinaList do
l.free
end
#
- it "should be able to build from ruby Array" do
+ it "should be able to build from a ruby Array of pointers" do
a = []
a << ::FFI::MemoryPointer.from_string("D0")
a << ::FFI::MemoryPointer.from_string("D1")
@@ -92,6 +92,15 @@ describe Efl::EinaList do
l.free
end
#
+ it "should be able to build from a ruby Array of int" do
+ a = [3,4,5,6]
+ l = REinaList.from_a a, :int
+ 0.upto 3 do |i|
+ l.nth(i).read_int.should == i+3
+ end
+ l.free
+ end
+ #
it "Enumerable" do
l = REinaList.new
d1 = ::FFI::MemoryPointer.from_string "D0"