summaryrefslogtreecommitdiffstats
path: root/lib/efl/ffi.rb
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2012-01-19 17:28:28 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2012-01-19 17:28:28 +0100
commitdf490aebdfce1d52f4e5c79cd778ea088cdff71f (patch)
treedaa92966e451ba840b409c5823436a2cf6aab236 /lib/efl/ffi.rb
parent40af126864cdfe1b8ede5e9c9176f1744968fa32 (diff)
downloadffi-efl-df490aebdfce1d52f4e5c79cd778ea088cdff71f.zip
ffi-efl-df490aebdfce1d52f4e5c79cd778ea088cdff71f.tar.gz
lib/efl/ffi.rb: add module MethResolver
Diffstat (limited to 'lib/efl/ffi.rb')
-rw-r--r--lib/efl/ffi.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/efl/ffi.rb b/lib/efl/ffi.rb
index f1c1d7d..98a9d69 100644
--- a/lib/efl/ffi.rb
+++ b/lib/efl/ffi.rb
@@ -112,6 +112,36 @@ module Efl
module_function :find_function
end
#
+ module MethResolver
+ 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, &block; r=Efl::Native.#{sym}(#{args_s}); yield r if block_given?; r; end"
+ sym
+ end
+ end
+ #
module ClassHelper
def to_a; [self] end
def to_ary; [self] end