diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2011-05-19 09:47:05 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2011-05-19 09:47:05 +0200 |
commit | 422d2cf48320daed5caf35be2d94838268775a1b (patch) | |
tree | 4ced7dc7a3f24f35ee2f8bb6ec1efc6c1b360490 | |
parent | a3fbc22500199376091e37280c0dc336cab2da51 (diff) | |
download | ffi-efl-422d2cf48320daed5caf35be2d94838268775a1b.zip ffi-efl-422d2cf48320daed5caf35be2d94838268775a1b.tar.gz |
extract find_function from Module specific method_missing
-rw-r--r-- | lib/efl/ffi.rb | 30 | ||||
-rw-r--r-- | lib/efl/native/ecore.rb | 28 | ||||
-rw-r--r-- | lib/efl/native/ecore_evas.rb | 28 | ||||
-rw-r--r-- | lib/efl/native/ecore_getopt.rb | 28 | ||||
-rw-r--r-- | lib/efl/native/ecore_input.rb | 28 | ||||
-rw-r--r-- | lib/efl/native/edje.rb | 28 | ||||
-rw-r--r-- | lib/efl/native/eet.rb | 28 | ||||
-rw-r--r-- | lib/efl/native/eina.rb | 28 | ||||
-rw-r--r-- | lib/efl/native/eina_hash.rb | 28 | ||||
-rw-r--r-- | lib/efl/native/eina_list.rb | 28 | ||||
-rw-r--r-- | lib/efl/native/eina_log.rb | 28 | ||||
-rw-r--r-- | lib/efl/native/eina_types.rb | 28 | ||||
-rw-r--r-- | lib/efl/native/elementary.rb | 28 | ||||
-rw-r--r-- | lib/efl/native/evas.rb | 28 | ||||
-rwxr-xr-x | tools/genruby.rb | 30 |
15 files changed, 87 insertions, 337 deletions
diff --git a/lib/efl/ffi.rb b/lib/efl/ffi.rb index f66905f..9d206d4 100644 --- a/lib/efl/ffi.rb +++ b/lib/efl/ffi.rb @@ -80,6 +80,36 @@ module Efl # end # + module ModuleHelper + def find_function m, prefix + m_s = m.to_s + if m_s =~/^(.*)=$/ + m_s = $1+'_set' + args_s = '*args[0]' + elsif m_s =~/^(.*)\?$/ + m_s = $1+'_get' + args_s = '*args' + else + args_s = '*args' + end + sym = ( + if Efl::Native.respond_to? prefix+m_s + prefix+m_s + elsif Efl::Native.respond_to? m_s + m_s + elsif Efl::Native.respond_to? prefix+m_s+'_get' + prefix+m_s+'_get' + elsif Efl::Native.respond_to? m_s+'_get' + m_s+'_get' + else + raise NameError.new "#{self.name}.#{m_s} (#{m})" + end + ) + [sym, args_s] + end + module_function :find_function + end + # module ClassHelper def to_a; [self] end def to_ary; [self] end diff --git a/lib/efl/native/ecore.rb b/lib/efl/native/ecore.rb index 71e7daa..d790bd2 100644 --- a/lib/efl/native/ecore.rb +++ b/lib/efl/native/ecore.rb @@ -7,31 +7,11 @@ module Efl # module Ecore # + FCT_PREFIX = 'ecore_' + # def self.method_missing m, *args, &block - m_s = m.to_s - if m_s =~/^(.*)=$/ - m_s = $1+'_set' - args_s = '*args[0]' - elsif m_s =~/^(.*)\?$/ - m_s = $1+'_get' - args_s = '*args' - else - args_s = '*args' - end - sym = ( - if Efl::Native.respond_to? 'ecore_'+m_s - 'ecore_'+m_s - elsif Efl::Native.respond_to? m_s - m_s - elsif Efl::Native.respond_to? 'ecore_'+m_s+'_get' - 'ecore_'+m_s+'_get' - elsif Efl::Native.respond_to? m_s+'_get' - m_s+'_get' - else - raise NameError.new "#{self.name}.#{m_s} (#{m})" - end - ) - self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(*args); yield r if block_given?; r; end" + sym, args_s = ModuleHelper.find_function m, FCT_PREFIX + self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(#{args_s}); yield r if block_given?; r; end" self.send m, *args, &block end # diff --git a/lib/efl/native/ecore_evas.rb b/lib/efl/native/ecore_evas.rb index 4413980..f1f1112 100644 --- a/lib/efl/native/ecore_evas.rb +++ b/lib/efl/native/ecore_evas.rb @@ -7,31 +7,11 @@ module Efl # module EcoreEvas # + FCT_PREFIX = 'ecore_evas_' + # def self.method_missing m, *args, &block - m_s = m.to_s - if m_s =~/^(.*)=$/ - m_s = $1+'_set' - args_s = '*args[0]' - elsif m_s =~/^(.*)\?$/ - m_s = $1+'_get' - args_s = '*args' - else - args_s = '*args' - end - sym = ( - if Efl::Native.respond_to? 'ecore_evas_'+m_s - 'ecore_evas_'+m_s - elsif Efl::Native.respond_to? m_s - m_s - elsif Efl::Native.respond_to? 'ecore_evas_'+m_s+'_get' - 'ecore_evas_'+m_s+'_get' - elsif Efl::Native.respond_to? m_s+'_get' - m_s+'_get' - else - raise NameError.new "#{self.name}.#{m_s} (#{m})" - end - ) - self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(*args); yield r if block_given?; r; end" + sym, args_s = ModuleHelper.find_function m, FCT_PREFIX + self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(#{args_s}); yield r if block_given?; r; end" self.send m, *args, &block end # diff --git a/lib/efl/native/ecore_getopt.rb b/lib/efl/native/ecore_getopt.rb index feb74e8..ddce66b 100644 --- a/lib/efl/native/ecore_getopt.rb +++ b/lib/efl/native/ecore_getopt.rb @@ -7,31 +7,11 @@ module Efl # module EcoreGetopt # + FCT_PREFIX = 'ecore_getopt_' + # def self.method_missing m, *args, &block - m_s = m.to_s - if m_s =~/^(.*)=$/ - m_s = $1+'_set' - args_s = '*args[0]' - elsif m_s =~/^(.*)\?$/ - m_s = $1+'_get' - args_s = '*args' - else - args_s = '*args' - end - sym = ( - if Efl::Native.respond_to? 'ecore_getopt_'+m_s - 'ecore_getopt_'+m_s - elsif Efl::Native.respond_to? m_s - m_s - elsif Efl::Native.respond_to? 'ecore_getopt_'+m_s+'_get' - 'ecore_getopt_'+m_s+'_get' - elsif Efl::Native.respond_to? m_s+'_get' - m_s+'_get' - else - raise NameError.new "#{self.name}.#{m_s} (#{m})" - end - ) - self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(*args); yield r if block_given?; r; end" + sym, args_s = ModuleHelper.find_function m, FCT_PREFIX + self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(#{args_s}); yield r if block_given?; r; end" self.send m, *args, &block end # diff --git a/lib/efl/native/ecore_input.rb b/lib/efl/native/ecore_input.rb index ba246f2..88df1e1 100644 --- a/lib/efl/native/ecore_input.rb +++ b/lib/efl/native/ecore_input.rb @@ -7,31 +7,11 @@ module Efl # module EcoreInput # + FCT_PREFIX = 'ecore_event_' + # def self.method_missing m, *args, &block - m_s = m.to_s - if m_s =~/^(.*)=$/ - m_s = $1+'_set' - args_s = '*args[0]' - elsif m_s =~/^(.*)\?$/ - m_s = $1+'_get' - args_s = '*args' - else - args_s = '*args' - end - sym = ( - if Efl::Native.respond_to? 'ecore_event_'+m_s - 'ecore_event_'+m_s - elsif Efl::Native.respond_to? m_s - m_s - elsif Efl::Native.respond_to? 'ecore_event_'+m_s+'_get' - 'ecore_event_'+m_s+'_get' - elsif Efl::Native.respond_to? m_s+'_get' - m_s+'_get' - else - raise NameError.new "#{self.name}.#{m_s} (#{m})" - end - ) - self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(*args); yield r if block_given?; r; end" + sym, args_s = ModuleHelper.find_function m, FCT_PREFIX + self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(#{args_s}); yield r if block_given?; r; end" self.send m, *args, &block end # diff --git a/lib/efl/native/edje.rb b/lib/efl/native/edje.rb index 8b2d849..af7cf61 100644 --- a/lib/efl/native/edje.rb +++ b/lib/efl/native/edje.rb @@ -7,31 +7,11 @@ module Efl # module Edje # + FCT_PREFIX = 'edje_' + # def self.method_missing m, *args, &block - m_s = m.to_s - if m_s =~/^(.*)=$/ - m_s = $1+'_set' - args_s = '*args[0]' - elsif m_s =~/^(.*)\?$/ - m_s = $1+'_get' - args_s = '*args' - else - args_s = '*args' - end - sym = ( - if Efl::Native.respond_to? 'edje_'+m_s - 'edje_'+m_s - elsif Efl::Native.respond_to? m_s - m_s - elsif Efl::Native.respond_to? 'edje_'+m_s+'_get' - 'edje_'+m_s+'_get' - elsif Efl::Native.respond_to? m_s+'_get' - m_s+'_get' - else - raise NameError.new "#{self.name}.#{m_s} (#{m})" - end - ) - self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(*args); yield r if block_given?; r; end" + sym, args_s = ModuleHelper.find_function m, FCT_PREFIX + self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(#{args_s}); yield r if block_given?; r; end" self.send m, *args, &block end # diff --git a/lib/efl/native/eet.rb b/lib/efl/native/eet.rb index e035c85..606a8a3 100644 --- a/lib/efl/native/eet.rb +++ b/lib/efl/native/eet.rb @@ -7,31 +7,11 @@ module Efl # module Eet # + FCT_PREFIX = 'eet_' + # def self.method_missing m, *args, &block - m_s = m.to_s - if m_s =~/^(.*)=$/ - m_s = $1+'_set' - args_s = '*args[0]' - elsif m_s =~/^(.*)\?$/ - m_s = $1+'_get' - args_s = '*args' - else - args_s = '*args' - end - sym = ( - if Efl::Native.respond_to? 'eet_'+m_s - 'eet_'+m_s - elsif Efl::Native.respond_to? m_s - m_s - elsif Efl::Native.respond_to? 'eet_'+m_s+'_get' - 'eet_'+m_s+'_get' - elsif Efl::Native.respond_to? m_s+'_get' - m_s+'_get' - else - raise NameError.new "#{self.name}.#{m_s} (#{m})" - end - ) - self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(*args); yield r if block_given?; r; end" + sym, args_s = ModuleHelper.find_function m, FCT_PREFIX + self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(#{args_s}); yield r if block_given?; r; end" self.send m, *args, &block end # diff --git a/lib/efl/native/eina.rb b/lib/efl/native/eina.rb index a910567..9c831f7 100644 --- a/lib/efl/native/eina.rb +++ b/lib/efl/native/eina.rb @@ -7,31 +7,11 @@ module Efl # module Eina # + FCT_PREFIX = 'eina_' + # def self.method_missing m, *args, &block - m_s = m.to_s - if m_s =~/^(.*)=$/ - m_s = $1+'_set' - args_s = '*args[0]' - elsif m_s =~/^(.*)\?$/ - m_s = $1+'_get' - args_s = '*args' - else - args_s = '*args' - end - sym = ( - if Efl::Native.respond_to? 'eina_'+m_s - 'eina_'+m_s - elsif Efl::Native.respond_to? m_s - m_s - elsif Efl::Native.respond_to? 'eina_'+m_s+'_get' - 'eina_'+m_s+'_get' - elsif Efl::Native.respond_to? m_s+'_get' - m_s+'_get' - else - raise NameError.new "#{self.name}.#{m_s} (#{m})" - end - ) - self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(*args); yield r if block_given?; r; end" + sym, args_s = ModuleHelper.find_function m, FCT_PREFIX + self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(#{args_s}); yield r if block_given?; r; end" self.send m, *args, &block end # diff --git a/lib/efl/native/eina_hash.rb b/lib/efl/native/eina_hash.rb index f1df86e..5599da4 100644 --- a/lib/efl/native/eina_hash.rb +++ b/lib/efl/native/eina_hash.rb @@ -7,31 +7,11 @@ module Efl # module EinaHash # + FCT_PREFIX = 'eina_hash_' + # def self.method_missing m, *args, &block - m_s = m.to_s - if m_s =~/^(.*)=$/ - m_s = $1+'_set' - args_s = '*args[0]' - elsif m_s =~/^(.*)\?$/ - m_s = $1+'_get' - args_s = '*args' - else - args_s = '*args' - end - sym = ( - if Efl::Native.respond_to? 'eina_hash_'+m_s - 'eina_hash_'+m_s - elsif Efl::Native.respond_to? m_s - m_s - elsif Efl::Native.respond_to? 'eina_hash_'+m_s+'_get' - 'eina_hash_'+m_s+'_get' - elsif Efl::Native.respond_to? m_s+'_get' - m_s+'_get' - else - raise NameError.new "#{self.name}.#{m_s} (#{m})" - end - ) - self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(*args); yield r if block_given?; r; end" + sym, args_s = ModuleHelper.find_function m, FCT_PREFIX + self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(#{args_s}); yield r if block_given?; r; end" self.send m, *args, &block end # diff --git a/lib/efl/native/eina_list.rb b/lib/efl/native/eina_list.rb index 1d5396a..b24bce9 100644 --- a/lib/efl/native/eina_list.rb +++ b/lib/efl/native/eina_list.rb @@ -7,31 +7,11 @@ module Efl # module EinaList # + FCT_PREFIX = 'eina_list_' + # def self.method_missing m, *args, &block - m_s = m.to_s - if m_s =~/^(.*)=$/ - m_s = $1+'_set' - args_s = '*args[0]' - elsif m_s =~/^(.*)\?$/ - m_s = $1+'_get' - args_s = '*args' - else - args_s = '*args' - end - sym = ( - if Efl::Native.respond_to? 'eina_list_'+m_s - 'eina_list_'+m_s - elsif Efl::Native.respond_to? m_s - m_s - elsif Efl::Native.respond_to? 'eina_list_'+m_s+'_get' - 'eina_list_'+m_s+'_get' - elsif Efl::Native.respond_to? m_s+'_get' - m_s+'_get' - else - raise NameError.new "#{self.name}.#{m_s} (#{m})" - end - ) - self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(*args); yield r if block_given?; r; end" + sym, args_s = ModuleHelper.find_function m, FCT_PREFIX + self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(#{args_s}); yield r if block_given?; r; end" self.send m, *args, &block end # diff --git a/lib/efl/native/eina_log.rb b/lib/efl/native/eina_log.rb index c7b2acb..1aabb3c 100644 --- a/lib/efl/native/eina_log.rb +++ b/lib/efl/native/eina_log.rb @@ -7,31 +7,11 @@ module Efl # module EinaLog # + FCT_PREFIX = 'eina_log_' + # def self.method_missing m, *args, &block - m_s = m.to_s - if m_s =~/^(.*)=$/ - m_s = $1+'_set' - args_s = '*args[0]' - elsif m_s =~/^(.*)\?$/ - m_s = $1+'_get' - args_s = '*args' - else - args_s = '*args' - end - sym = ( - if Efl::Native.respond_to? 'eina_log_'+m_s - 'eina_log_'+m_s - elsif Efl::Native.respond_to? m_s - m_s - elsif Efl::Native.respond_to? 'eina_log_'+m_s+'_get' - 'eina_log_'+m_s+'_get' - elsif Efl::Native.respond_to? m_s+'_get' - m_s+'_get' - else - raise NameError.new "#{self.name}.#{m_s} (#{m})" - end - ) - self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(*args); yield r if block_given?; r; end" + sym, args_s = ModuleHelper.find_function m, FCT_PREFIX + self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(#{args_s}); yield r if block_given?; r; end" self.send m, *args, &block end # diff --git a/lib/efl/native/eina_types.rb b/lib/efl/native/eina_types.rb index fbe7130..e23b0a4 100644 --- a/lib/efl/native/eina_types.rb +++ b/lib/efl/native/eina_types.rb @@ -7,31 +7,11 @@ module Efl # module Eina # + FCT_PREFIX = 'eina_' + # def self.method_missing m, *args, &block - m_s = m.to_s - if m_s =~/^(.*)=$/ - m_s = $1+'_set' - args_s = '*args[0]' - elsif m_s =~/^(.*)\?$/ - m_s = $1+'_get' - args_s = '*args' - else - args_s = '*args' - end - sym = ( - if Efl::Native.respond_to? 'eina_'+m_s - 'eina_'+m_s - elsif Efl::Native.respond_to? m_s - m_s - elsif Efl::Native.respond_to? 'eina_'+m_s+'_get' - 'eina_'+m_s+'_get' - elsif Efl::Native.respond_to? m_s+'_get' - m_s+'_get' - else - raise NameError.new "#{self.name}.#{m_s} (#{m})" - end - ) - self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(*args); yield r if block_given?; r; end" + sym, args_s = ModuleHelper.find_function m, FCT_PREFIX + self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(#{args_s}); yield r if block_given?; r; end" self.send m, *args, &block end # diff --git a/lib/efl/native/elementary.rb b/lib/efl/native/elementary.rb index 7e2dc4d..76bc3d0 100644 --- a/lib/efl/native/elementary.rb +++ b/lib/efl/native/elementary.rb @@ -8,31 +8,11 @@ module Efl # module Elm # + FCT_PREFIX = 'elm_' + # def self.method_missing m, *args, &block - m_s = m.to_s - if m_s =~/^(.*)=$/ - m_s = $1+'_set' - args_s = '*args[0]' - elsif m_s =~/^(.*)\?$/ - m_s = $1+'_get' - args_s = '*args' - else - args_s = '*args' - end - sym = ( - if Efl::Native.respond_to? 'elm_'+m_s - 'elm_'+m_s - elsif Efl::Native.respond_to? m_s - m_s - elsif Efl::Native.respond_to? 'elm_'+m_s+'_get' - 'elm_'+m_s+'_get' - elsif Efl::Native.respond_to? m_s+'_get' - m_s+'_get' - else - raise NameError.new "#{self.name}.#{m_s} (#{m})" - end - ) - self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(*args); yield r if block_given?; r; end" + sym, args_s = ModuleHelper.find_function m, FCT_PREFIX + self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(#{args_s}); yield r if block_given?; r; end" self.send m, *args, &block end # diff --git a/lib/efl/native/evas.rb b/lib/efl/native/evas.rb index bd316e0..4f258d0 100644 --- a/lib/efl/native/evas.rb +++ b/lib/efl/native/evas.rb @@ -7,31 +7,11 @@ module Efl # module Evas # + FCT_PREFIX = 'evas_' + # def self.method_missing m, *args, &block - m_s = m.to_s - if m_s =~/^(.*)=$/ - m_s = $1+'_set' - args_s = '*args[0]' - elsif m_s =~/^(.*)\?$/ - m_s = $1+'_get' - args_s = '*args' - else - args_s = '*args' - end - sym = ( - if Efl::Native.respond_to? 'evas_'+m_s - 'evas_'+m_s - elsif Efl::Native.respond_to? m_s - m_s - elsif Efl::Native.respond_to? 'evas_'+m_s+'_get' - 'evas_'+m_s+'_get' - elsif Efl::Native.respond_to? m_s+'_get' - m_s+'_get' - else - raise NameError.new "#{self.name}.#{m_s} (#{m})" - end - ) - self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(*args); yield r if block_given?; r; end" + sym, args_s = ModuleHelper.find_function m, FCT_PREFIX + self.module_eval "def self.#{m} *args, █ r=Efl::Native.#{sym}(#{args_s}); yield r if block_given?; r; end" self.send m, *args, &block end # diff --git a/tools/genruby.rb b/tools/genruby.rb index 84f96d4..008837e 100755 --- a/tools/genruby.rb +++ b/tools/genruby.rb @@ -38,31 +38,11 @@ module Efl # module MNAME # + FCT_PREFIX = 'MY_FCT_PREFIX_' + # def self.method_missing m, *args, &block - m_s = m.to_s - if m_s =~/^(.*)=$/ - m_s = $1+'_set' - args_s = '*args[0]' - elsif m_s =~/^(.*)\\?$/ - m_s = $1+'_get' - args_s = '*args' - else - args_s = '*args' - end - sym = ( - if Efl::Native.respond_to? 'FCT_PREFIX_'+m_s - 'FCT_PREFIX_'+m_s - elsif Efl::Native.respond_to? m_s - m_s - elsif Efl::Native.respond_to? 'FCT_PREFIX_'+m_s+'_get' - 'FCT_PREFIX_'+m_s+'_get' - elsif Efl::Native.respond_to? m_s+'_get' - m_s+'_get' - else - raise NameError.new "\#{self.name}.\#{m_s} (\#{m})" - end - ) - self.module_eval "def self.\#{m} *args, █ r=Efl::Native.\#{sym}(*args); yield r if block_given?; r; end" + sym, args_s = ModuleHelper.find_function m, FCT_PREFIX + self.module_eval "def self.\#{m} *args, █ r=Efl::Native.\#{sym}(\#{args_s}); yield r if block_given?; r; end" self.send m, *args, &block end # @@ -303,7 +283,7 @@ libraries.collect do |header,module_name,fct_prefix,lib, output| end.each do |lib, output, module_name, fct_prefix, enums, typedefs, callbacks, variables, functions| printf "%-60s", "generate #{output}" open(output,'w:utf-8') do |f| - f << HEADER.gsub(/MNAME/,module_name).gsub(/FCT_PREFIX/,fct_prefix) + f << HEADER.gsub(/MNAME/,module_name).sub(/MY_FCT_PREFIX/,fct_prefix) f << "#{INDENT}#\n#{INDENT}ffi_lib '#{lib}'" f << "\n#{INDENT}#\n#{INDENT}# ENUMS" print "enums, " |