lib/win/library.rb in win-0.0.6 vs lib/win/library.rb in win-0.1.0

- old
+ new

@@ -365,10 +365,11 @@ # Generates possible effective names for function in Win32 dll (name+A/W), # Rubyesque name and aliases for method(s) defined based on function name, # sets boolean flag for test functions (Is...) # def generate_names(name, options={}) + name = name.to_s effective_names = [name] effective_names += ["#{name}A", "#{name}W"] unless name =~ /[WA]$/ aliases = ([options[:alias]] + [options[:aliases]]).flatten.compact method_name = options[:rename] || name.snake_case case method_name @@ -392,15 +393,15 @@ returns = TYPES[returns.to_sym] || returns # Convert chars into FFI type symbols [params, returns] end ## - # Wrapper for FFI::Library#callback() that converts Win32/shortcut types into FFI format - # + # Wrapper for FFI::Library#callback() that converts Win32/shortcut argument types into FFI-compliant types. + # This method overrides FFI.callback which must be aliased to FFI.attach_callback def callback(name, params, returns) params, returns = generate_signature(params, returns) - ffi_callback name.to_sym, params, returns + attach_callback name.to_sym, params, returns end ## # :method: namespace # This method is meta-generated when Win::Library module is included into other module/class @@ -423,17 +424,17 @@ # Hook executed when Win::Library is included into class or module. It extends host class/module # with both FFI::Library methods and Win::Library macro methods like 'function'. def self.included(klass) klass.extend FFI::Library - eigenklass = class << klass; self; end # Extracting host class's eigenclass - eigenklass.class_eval " - alias_method :ffi_callback, :callback - def namespace; #{klass}; end" - + eigenklass = class << klass; self; end # Extracting host class's eigenclass + eigenklass.class_eval do + define_method(:namespace) {klass} # Defining new class method for host pointing to itself + alias_method :attach_callback, :callback + end + klass.extend ClassMethods klass.ffi_lib 'user32', 'kernel32' # Default libraries klass.ffi_convention :stdcall end - end end \ No newline at end of file