diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2012-01-20 00:55:59 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2012-01-20 00:55:59 +0100 |
commit | fefa2a86eab0021892f3a0df1c82d1816dbeb8c9 (patch) | |
tree | c11806bbc889e0bf85a2b18f2d8be962eec07157 /lib/efl.rb | |
parent | df490aebdfce1d52f4e5c79cd778ea088cdff71f (diff) | |
download | ffi-efl-fefa2a86eab0021892f3a0df1c82d1816dbeb8c9.zip ffi-efl-fefa2a86eab0021892f3a0df1c82d1816dbeb8c9.tar.gz |
get rid of ffi.rb => add usefull stuff into efl.rb
Diffstat (limited to 'lib/efl.rb')
-rw-r--r-- | lib/efl.rb | 85 |
1 files changed, 73 insertions, 12 deletions
@@ -1,23 +1,84 @@ #! /usr/bin/env ruby # -*- coding: UTF-8 -*- # +require 'ffi' # module Efl # VERSION = '0.0.10' # - autoload :EcoreEvas, './lib/efl/ecore_evas.rb' - autoload :EcoreGetopt, './lib/efl/ecore_getopt.rb' - autoload :EcoreInput, './lib/efl/ecore_input.rb' - autoload :Ecore, './lib/efl/ecore.rb' - autoload :Edje, './lib/efl/edje.rb' - autoload :Eet, './lib/efl/eet.rb' - autoload :EinaHash, './lib/efl/eina_hash.rb' - autoload :EinaList, './lib/efl/eina_list.rb' - autoload :EinaLog, './lib/efl/eina_log.rb' - autoload :Eina, './lib/efl/eina.rb' - autoload :Elm, './lib/efl/elementary.rb' - autoload :Evas, './lib/efl/evas.rb' + module Native + # + extend FFI::Library + # + def self.attach_fcts fcts + fcts.each do |func| + begin + attach_function(*func) + rescue Object => e + puts "Could not attach #{func} #{e.message}" + end + end + end + # + class << self + # keep + alias :ffi_lib_orig :ffi_lib + def ffi_lib *names + @all_ffi_libs||=[] + @all_ffi_libs += ffi_lib_orig(names) + @all_ffi_libs.uniq! + end + def find_variable name + @all_ffi_libs.each do |lib| + address = lib.find_variable name + return address if not address.nil? + end + return nil + end + end + # + class VersionStruct < FFI::Struct + layout :major, :int, + :minor, :int, + :micro, :int, + :revision, :int + + def full + [:major,:minor,:micro,:revision].collect { |e| self[e].to_s }.join '.' + end + end + end + # + module MethResolver + def self.resolve mod, meth, prefix + meth_s = meth.to_s + if meth_s =~/^(.*)=$/ + meth_s = $1+'_set' + args_s = '*args[0]' + elsif meth_s =~/^(.*)\?$/ + meth_s = $1+'_get' + args_s = '*args' + else + args_s = '*args' + end + sym = ( + if Efl::Native.respond_to? prefix+meth_s + prefix+meth_s + elsif Efl::Native.respond_to? meth_s + meth_s + elsif Efl::Native.respond_to? prefix+meth_s+'_get' + prefix+meth_s+'_get' + elsif Efl::Native.respond_to? meth_s+'_get' + meth_s+'_get' + else + raise NameError.new "#{mod.name}.#{meth_s} (#{meth})" + end + ) + mod.module_eval "def self.#{meth} *args, █ r=Efl::Native.#{sym}(#{args_s}); yield r if block_given?; r; end" + sym + end + end end # # EOF |