From cbee8a70f433192a69ed90d9632d696dcb4ff2ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 27 Apr 2011 16:05:02 +0200 Subject: add eina_list and specs --- lib/efl/eina_list.rb | 78 +++++++++++++++++++++++++++++++++++ lib/efl/ffi/eina_list.rb | 105 +++++++++++++++++++++++++++++++++++++++++++++++ spec/eina_list_spec.rb | 100 ++++++++++++++++++++++++++++++++++++++++++++ tools/extract-api.sh | 1 + tools/genruby.rb | 3 +- 5 files changed, 285 insertions(+), 2 deletions(-) create mode 100644 lib/efl/eina_list.rb create mode 100644 lib/efl/ffi/eina_list.rb create mode 100644 spec/eina_list_spec.rb diff --git a/lib/efl/eina_list.rb b/lib/efl/eina_list.rb new file mode 100644 index 0000000..823fe72 --- /dev/null +++ b/lib/efl/eina_list.rb @@ -0,0 +1,78 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +require 'efl/eina' +require 'efl/ffi/eina_list' +# +class Array + def self.from_eina_list o + if o.is_a? Efl::Eina::EinaList + o.to_ary + elsif o.is_a? ::FFI::Pointer + Efl::Eina::EinaList.new(o).to_ary + else + raise ArgumentError.new " wrong argument #{o.class.name}" + end + end +end +module Efl + module FFI + class EinaList < ::FFI::Struct + layout :data, :pointer, + :next, :pointer, + :prev, :pointer, + :accounting, :pointer, + :magic, :uint, + end + end + module Eina + # + class EinaList + include Efl::Helper + include Enumerable + @func_prefixes = [ 'eina_list_' ].freeze + def initialize o=nil + @ptr = ( + case o + when ::FFI::Pointer + o + when NilClass + ::FFI::Pointer::NULL + when self.class + o.ptr + when Array + o.inject(::FFI::Pointer::NULL) { |p,e| Efl::FFI::eina_list_append p, e } + else + raise ArgumentError.new "#{ptr.class} valid argument" + end + ) + end + def free + return if @ptr==::FFI::Pointer::NULL + @ptr = Efl::FFI.eina_list_free @ptr + end + def each + p = @ptr + while p!=::FFI::Pointer::NULL + l = Efl::FFI::EinaList.new p + yield l[:data] + p = l[:next] + end + end + def to_ary + inject([]) { |s,e| s< ':eina_bool', 'Eina_Bool *' => ':eina_bool_p', - 'Eina_List' => ':eina_list', - 'Eina_List *' => ':eina_list_p', 'Eina_Hash' => ':eina_hash', 'Eina_Hash *' => ':eina_hash_p', 'Eina_Iterator' => ':eina_iterator', -- cgit v1.1-2-g2b99