summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2011-04-27 06:00:58 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2011-04-27 06:00:58 +0200
commit7c63402a0087554395b97f6edc6c4cb7f10f6320 (patch)
tree738685f8a7f3df1c1286c723bad5a962646abf72
parent44abb93bd6ad3f44d8b8a139e2b0ac0da7953631 (diff)
downloadffi-efl-7c63402a0087554395b97f6edc6c4cb7f10f6320.zip
ffi-efl-7c63402a0087554395b97f6edc6c4cb7f10f6320.tar.gz
ffi Helper: method_missing nicely handles /^(.)=$/ setters
-rw-r--r--lib/efl/ffi.rb13
-rw-r--r--test/test_elm_win_class.rb2
2 files changed, 12 insertions, 3 deletions
diff --git a/lib/efl/ffi.rb b/lib/efl/ffi.rb
index eaa45e7..4419b38 100644
--- a/lib/efl/ffi.rb
+++ b/lib/efl/ffi.rb
@@ -51,15 +51,22 @@ module Efl
m.class_eval "def self.inherited sub; sub.class_eval 'def self.func_prefixes; superclass.func_prefixes; end'; end"
end
def method_missing m, *args, &block
+ if m =~/^(.*)=$/
+ m_s = $1+'_set'
+ args_s = '*args[0]'
+ else
+ m_s = m.to_s
+ args_s = '*args'
+ end
self.class.func_prefixes.each do |p|
- sym = p+m.to_s
+ sym = p+m_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"
+ self.class.class_eval "def #{m} *args, &block; r=Efl::API.#{sym}(@ptr,#{args_s}); 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"
+ self.class.class_eval "def #{m} *args, &block; r=Efl::API.#{m}(@ptr,#{args_s}); yield r if block_given?; r; end"
r
end
end
diff --git a/test/test_elm_win_class.rb b/test/test_elm_win_class.rb
index 7934551..fee0265 100644
--- a/test/test_elm_win_class.rb
+++ b/test/test_elm_win_class.rb
@@ -18,6 +18,7 @@ class MyWin < Elm::ElmWin
# using block
@bg = add 'bg' do |bg|
bg.size_hint_weight_set 1.0, 1.0
+ bg.color = 200,255,100,200 # same as bg.color_set 200,255,100,200
bg.show
end
resize_object_add @bg.ptr
@@ -37,6 +38,7 @@ end
Elm.init
#
win = MyWin.new "App name", "Window Title" do |w,eo|
+ w.alpha_set true
eo.move 300, 300
eo.resize 200, 100
eo.show