diff options
-rw-r--r-- | lib/efl/ffi.rb | 94 | ||||
-rwxr-xr-x | tools/genruby.rb | 28 |
2 files changed, 65 insertions, 57 deletions
diff --git a/lib/efl/ffi.rb b/lib/efl/ffi.rb index 82ee537..72df658 100644 --- a/lib/efl/ffi.rb +++ b/lib/efl/ffi.rb @@ -5,9 +5,7 @@ require 'ffi' # module Efl # - module FFI - # - extend ::FFI::Library + module FFIHelper # def attach_fcts fcts fcts.each do |func| @@ -18,43 +16,55 @@ module Efl end end end - module_function :attach_fcts - # - typedef :pointer, :char_p - typedef :pointer, :short_p - typedef :pointer, :int_p - typedef :pointer, :long_p - typedef :pointer, :float_p - typedef :pointer, :double_p - typedef :pointer, :uchar_p - typedef :pointer, :ushort_p - typedef :pointer, :uint_p - typedef :pointer, :ulong_p - typedef :pointer, :ufloat_p - typedef :pointer, :udouble_p - typedef :pointer, :void_p - typedef :pointer, :string_array - typedef :pointer, :string_array_p - typedef :uint_p, :uintptr_t # - typedef :pointer, :eina_list_p - typedef :pointer, :eina_hash_p - typedef :pointer, :eina_iterator_p - typedef :pointer, :eina_accessor_p - typedef :pointer, :evas_p - typedef :pointer, :evas_object_p - typedef :pointer, :evas_object_pp - typedef :pointer, :ecore_getopt_p - typedef :pointer, :ecore_getopt_desc_p - typedef :pointer, :ecore_getopt_value_p + def self.extended mod + # + mod.extend FFI::Library + # + mod.typedef :pointer, :char_p + mod.typedef :pointer, :short_p + mod.typedef :pointer, :int_p + mod.typedef :pointer, :long_p + mod.typedef :pointer, :float_p + mod.typedef :pointer, :double_p + mod.typedef :pointer, :uchar_p + mod.typedef :pointer, :ushort_p + mod.typedef :pointer, :uint_p + mod.typedef :pointer, :ulong_p + mod.typedef :pointer, :ufloat_p + mod.typedef :pointer, :udouble_p + mod.typedef :pointer, :void_p + mod.typedef :pointer, :string_array + mod.typedef :pointer, :string_array_p + mod.typedef :uint_p, :uintptr_t + # + mod.typedef :bool, :eina_bool + mod.typedef :pointer, :eina_bool_p + mod.typedef :pointer, :eina_list_p + mod.typedef :pointer, :eina_hash_p + mod.typedef :pointer, :eina_iterator_p + mod.typedef :pointer, :eina_accessor_p + mod.typedef :pointer, :evas_p + mod.typedef :pointer, :evas_object_p + mod.typedef :pointer, :evas_object_pp + mod.typedef :pointer, :ecore_getopt_p + mod.typedef :pointer, :ecore_getopt_desc_p + mod.typedef :pointer, :ecore_getopt_value_p + # + mod.callback :eina_compare_cb, [ :void_p, :void_p ], :int + mod.callback :eina_each_cb, [ :void_p, :void_p, :void_p ], :eina_bool + mod.callback :eina_free_cb, [ :void_p ], :void + end # end # - module Helper - def self.included m - m.class_eval "def ptr; @ptr; end" - m.class_eval "def self.func_prefixes; @func_prefixes; end" - m.class_eval "def self.inherited sub; sub.class_eval 'def self.func_prefixes; superclass.func_prefixes; end'; end" + module ClassHelper + def self.included kls + kls.class_eval "def self.search_paths; @search_paths; end" + kls.class_eval "def self.inherited sub; sub.class_eval 'def self.search_paths; superclass.search_paths; end'; end" + end + def to_ptr + @ptr end def === o @ptr === o.ptr @@ -73,20 +83,16 @@ module Efl m_s = m.to_s args_s = '*args' end - self.class.func_prefixes.each do |p| + self.class.search_paths.each do |mod,p| sym = p+m_s - if Efl::FFI.respond_to? sym - self.class.class_eval "def #{m} *args, █ r=Efl::FFI.#{sym}(@ptr,#{args_s}); yield r if block_given?; r; end" + if mod.respond_to? sym + self.class.class_eval "def #{m} *args, █ r=#{mod.name}.#{sym}(@ptr,#{args_s}); yield r if block_given?; r; end" return self.send m, *args, &block end end - r = Efl::FFI.send m, @ptr, *args - self.class.class_eval "def #{m} *args, █ r=Efl::FFI.#{m}(@ptr,#{args_s}); yield r if block_given?; r; end" - r + raise NameError.new "unable to resolve #{m} into #{self.class.search_paths.inspect}" end end end # -require 'efl/ffi/eina/eina_types' -# # EOF diff --git a/tools/genruby.rb b/tools/genruby.rb index 2b00004..fafa6a9 100755 --- a/tools/genruby.rb +++ b/tools/genruby.rb @@ -7,19 +7,19 @@ lib_path = File.join path, '..', 'lib', 'efl', 'ffi' # header, module name, fct prefix, lib libraries = [ # HEADER MODUE NAME FCT PREFIX LIB OUTPUT - [ 'eina_types.h', 'Eina', 'eina', 'eina', 'eina/eina_types.rb' ], + [ 'eina_types.h', 'Eina', 'eina', 'eina', 'eina_types.rb' ], [ 'eina_main.h', 'Eina', 'eina', 'eina', 'eina.rb' ], - [ 'eina_list.h', 'EinaList', 'eina_list', 'eina', 'eina/eina_list.rb' ], - [ 'eina_hash.h', 'EinaHash', 'eina_hash', 'eina', 'eina/eina_hash.rb' ], + [ 'eina_list.h', 'EinaList', 'eina_list', 'eina', 'eina_list.rb' ], + [ 'eina_hash.h', 'EinaHash', 'eina_hash', 'eina', 'eina_hash.rb' ], [ 'Eet.h', 'Eet', 'eet', 'eet', 'eet.rb' ], [ 'Evas.h', 'Evas', 'evas', 'evas', 'evas.rb' ], # [ 'Evas_GL.h', 'EvasGl', 'evas_gl', 'evas', 'evas/evas_gl.rb' ], [ 'Edje.h', 'Edje', 'edje', 'edje', 'edje.rb' ], [ 'Ecore.h', 'Ecore', 'ecore', 'ecore', 'ecore.rb' ], # [ 'Ecore_Con.h', 'EcoreCon', 'ecore_con', 'ecore', 'ecore/ecore_con.rb' ], - [ 'Ecore_Input.h', 'EcoreInput', 'ecore_event', 'ecore_input', 'ecore/ecore_input.rb' ], - [ 'Ecore_Getopt.h', 'EcoreGetopt', 'ecore_getopt', 'ecore', 'ecore/ecore_getopt.rb' ], - [ 'Ecore_Evas.h', 'EcoreEvas', 'ecore_evas', 'ecore_evas', 'ecore/ecore_evas.rb' ], + [ 'Ecore_Input.h', 'EcoreInput', 'ecore_event', 'ecore_input', 'ecore_input.rb' ], + [ 'Ecore_Getopt.h', 'EcoreGetopt', 'ecore_getopt', 'ecore', 'ecore_getopt.rb' ], + [ 'Ecore_Evas.h', 'EcoreEvas', 'ecore_evas', 'ecore_evas', 'ecore_evas.rb' ], # [ 'Ecore_Fb.h', 'EcoreFb', 'ecore', 'ecore', 'ecore/ecore_fb.rb' ], # [ 'Ecore_File.h', 'EcoreFile', 'ecore', 'ecore', 'ecore/ecore_file.rb' ], [ 'Elementary.h', 'Elm', 'elm', 'libelementary-ver-pre-svn-09.so.0', 'elementary.rb' ], @@ -36,13 +36,15 @@ require 'efl/ffi' module Efl # module MNAME + # + extend Efl::FFIHelper + # def self.method_missing m, *args, &block - return Efl::FFI.send 'PREFIX_'+m.to_s, *args, &block + sym = 'FCT_PREFIX_'+m.to_s + raise NameError.new "\#{self.name}.\#{sym} (\#{m})" if not self.respond_to? sym + self.module_eval "def self.\#{m} *args, █ r=self.\#{sym}(*args); yield r if block_given?; r; end" + self.send sym, *args, &block end - end - # - module FFI - # EOF FOOTER =<<-EOF end @@ -257,7 +259,7 @@ libraries.collect do |header,module_name,fct_prefix,lib, output| end.each do |lib, output, module_name, fct_prefix, enums, typedefs, callbacks, functions| printf "%-60s", "generate #{output}" open(output,'w:utf-8') do |f| - f << HEADER.sub(/MNAME/,module_name).sub(/PREFIX/,fct_prefix) + f << HEADER.gsub(/MNAME/,module_name).sub(/FCT_PREFIX/,fct_prefix) f << "#{INDENT}#\n#{INDENT}ffi_lib '#{lib}'" f << "\n#{INDENT}#\n#{INDENT}# ENUMS" print "enums, " @@ -271,7 +273,7 @@ end.each do |lib, output, module_name, fct_prefix, enums, typedefs, callbacks, f f << "\n#{INDENT}#\n#{INDENT}# FUNCTIONS" puts "functions." f << "\n"+functions.join("\n") unless functions.empty? - f << "\n#{INDENT}#\n#{INDENT}attach_fcts fcts\n" + f << "\n#{INDENT}#\n#{INDENT}attach_fcts fcts\n#{INDENT}#\n" f << FOOTER end end |