Method: Fiddle::Importer#bind
- Defined in:
- lib/fiddle/import.rb
#bind(signature, *opts, &blk) ⇒ Object
Creates a global method from the given C signature using the given opts as bind parameters with the given block.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/fiddle/import.rb', line 191 def bind(signature, *opts, &blk) name, ctype, argtype = parse_signature(signature, type_alias) h = (opts) case h[:callback_type] when :bind, nil f = bind_function(name, ctype, argtype, h[:call_type], &blk) else raise(RuntimeError, "unknown callback type: #{h[:callback_type]}") end @func_map[name] = f #define_method(name){|*args,&block| f.call(*args,&block)} begin /^(.+?):(\d+)/ =~ caller.first file, line = $1, $2.to_i rescue file, line = __FILE__, __LINE__+3 end module_eval(" def \#{name}(*args,&block)\n @func_map['\#{name}'].call(*args,&block)\n end\n EOS\n module_function(name)\n f\nend\n", file, line) |