summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2011-04-21 14:28:10 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2011-04-21 14:28:10 +0200
commit5b1ec744cc7251d1f6d9478b705550cd1be2f002 (patch)
treed78f9ae11abf04b5fb932b05e262d5eedd210015
parent8caf7d9cb68205c74a46f1e0e5cc1cbd89f78113 (diff)
downloadffi-efl-5b1ec744cc7251d1f6d9478b705550cd1be2f002.zip
ffi-efl-5b1ec744cc7251d1f6d9478b705550cd1be2f002.tar.gz
move method_missing definition into Efl::Helper module
-rw-r--r--lib/efl/evas.rb22
-rw-r--r--lib/efl/ffi.rb18
2 files changed, 22 insertions, 18 deletions
diff --git a/lib/efl/evas.rb b/lib/efl/evas.rb
index b3df675..24ea514 100644
--- a/lib/efl/evas.rb
+++ b/lib/efl/evas.rb
@@ -7,7 +7,8 @@ module Efl
module Evas
#
class Evas
- attr_reader :ptr
+ include Efl::Helper
+ @func_prefixes = [ 'evas_' ].freeze
def initialize o=nil
@ptr = (
case o
@@ -32,12 +33,6 @@ module Efl
def === o
@ptr === o.ptr
end
- def method_missing m, *args, &block
- sym = 'evas_'+m.to_s
- Efl::API.send sym if not Efl::API.respond_to? sym
- self.class.class_eval "def #{m} *args, &block; r =Efl::API.#{sym}(@ptr,*args); yield r if block_given?; r; end"
- self.send m, *args, &block
- end
def output_size_get
x = FFI::MemoryPointer.new :int
y = FFI::MemoryPointer.new :int
@@ -67,7 +62,8 @@ module Efl
end
#
class EvasObject
- attr_reader :ptr
+ include Efl::Helper
+ @func_prefixes = [ 'evas_object_', 'evas_' ].freeze
def initialize o=nil
@ptr = (
case o
@@ -89,16 +85,6 @@ module Efl
Efl::API.evas_object_del @ptr
@ptr=nil
end
- def method_missing m, *args, &block
- if Efl::API.respond_to? m
- self.class.class_eval "def #{m} *args, &block; r=Efl::API.#{m}(@ptr,*args); yield r if block_given?; r; end"
- return self.send m, *args, &block
- end
- sym = 'evas_object_'+m.to_s
- Efl::API.send sym if not Efl::API.respond_to? sym
- self.class.class_eval "def #{m} *args, &block; r=Efl::API.#{sym}(@ptr,*args); yield r if block_given?; r; end"
- self.send m, *args, &block
- end
def geometry_get
x = FFI::MemoryPointer.new :int
y = FFI::MemoryPointer.new :int
diff --git a/lib/efl/ffi.rb b/lib/efl/ffi.rb
index 8af2042..38bf16b 100644
--- a/lib/efl/ffi.rb
+++ b/lib/efl/ffi.rb
@@ -37,6 +37,24 @@ module Efl
#
end
#
+ module Helper
+ def self.included m
+ m.class_eval "def ptr; @ptr; end"
+ m.class_eval "def self.func_prefixes; @func_prefixes; end"
+ end
+ def method_missing m, *args, &block
+ self.class.func_prefixes.each do |p|
+ sym = p+m.to_s
+ if Efl::API.respond_to? sym
+ self.class.class_eval "def #{m} *args, &block; r=Efl::API.#{sym}(@ptr,*args); yield r if block_given?; r; end"
+ return self.send m, *args, &block
+ end
+ end
+ r = Efl::API.send m, @ptr, *args
+ self.class.class_eval "def #{m} *args, &block; r=Efl::API.#{m}(@ptr,*args); yield r if block_given?; r; end"
+ r
+ end
+ end
end
#
require 'efl/eina/eina_types-ffi'