diff options
Diffstat (limited to 'lib/efl/native.rb')
-rw-r--r-- | lib/efl/native.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/efl/native.rb b/lib/efl/native.rb index 24b336c..490ac9b 100644 --- a/lib/efl/native.rb +++ b/lib/efl/native.rb @@ -5,6 +5,36 @@ require 'ffi' # module Efl # + module MethodResolver + def self.resolve mod, meth, prefix + meth_s = meth.to_s + if meth_s =~/^(.*)=$/ + meth_s = $1+'_set' + args_s = '*args[0]' + elsif meth_s =~/^(.*)\?$/ + meth_s = $1+'_get' + args_s = '*args' + else + args_s = '*args' + end + sym = ( + if Efl::Native.respond_to? prefix+meth_s + prefix+meth_s + elsif Efl::Native.respond_to? meth_s + meth_s + elsif Efl::Native.respond_to? prefix+meth_s+'_get' + prefix+meth_s+'_get' + elsif Efl::Native.respond_to? meth_s+'_get' + meth_s+'_get' + else + raise NameError.new "#{mod.name}.#{meth_s} (#{meth})" + end + ) + mod.module_eval "def self.#{meth} *args, █ r=Efl::Native.#{sym}(#{args_s}); yield r if block_given?; r; end" + sym + end + end + # module Native # extend FFI::Library |