[Rubycocoa-devel 231] Re: const_missing hook for function-style constants

アーカイブの一覧に戻る

kimura wataru kimur****@i*****
Mon Mar 13 21:15:03 JST 2006


Hi,

On Sat, 11 Mar 2006 22:24:39 +0000, Jonathan Paisley wrote:
> Hi,
> 
> People get caught out sometimes by the dynamic function-style  
> constants on the OSX module (such as OSX.NSKeyValueChangeKindKey).  
> Below is a sample implementation using const_missing that makes these  
> available as normal constants (OSX::NS...).
> 
> Please let me know what you think.
> 
I'm worry about compatibility of this change. The feature const_missing 
is available on ruby-1.8.0 or later.

I think we can treat this symbols (NS...) as constants. 

=== framework/src/objc/cocoa/gen_cocoa_wrapper.rb
==================================================================
@@ -248,6 +248,10 @@
   ret
 end
 
+def gen_def_rb_mod_const(info)
+  ret = "  rb_define_const(mOSX, \"#{info.name}\", 
osx_#{info.name}(mOSX));\n"
+end
+
 def gen_def_enums(och)
   enums = och.enums
   return nil if enums.size == 0
@@ -284,6 +288,9 @@
     reconfig_info(info)
     ret_a.concat gen_def_c_func(info, 0)
     ret_b.concat gen_def_rb_mod_func(info, 0)
+    unless /\Aconst NS\w+CallBacks\z/ =~ info.rettype # 
NSHashTableCallBacks...
+      ret_b.concat gen_def_rb_mod_const(info) 
+    end
   end
   $stderr.print " : #{$notimpl_cnt}/#{consts.size} consts NG"
   $stderr.flush


This change was incomplete. I had to modify the initialization process 
of RubyCocoa to define OCObject and NSRect, NSPoint.. (in oc_types.rb)
before init_cocoa().


-- 
kimuwa wataru
-------------- next part --------------
A non-text attachment was scrubbed...
Name: define_const.patch
Type: application/octet-stream
Size: 3055 bytes
Desc: not available
Url : http://lists.sourceforge.jp/mailman/archives/rubycocoa-devel/attachments/20060313/dcb7a927/attachment.obj 


More information about the Rubycocoa-devel mailing list
アーカイブの一覧に戻る