summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/e17/ffi.rb35
-rw-r--r--lib/e17/ffi_helper.rb39
-rwxr-xr-xtools/genruby.rb33
3 files changed, 48 insertions, 59 deletions
diff --git a/lib/e17/ffi.rb b/lib/e17/ffi.rb
new file mode 100644
index 0000000..e8a644c
--- /dev/null
+++ b/lib/e17/ffi.rb
@@ -0,0 +1,35 @@
+#! /usr/bin/env ruby
+# -*- coding: UTF-8 -*-
+#
+require 'ffi'
+#
+module E17
+ #
+ module API
+ #
+ extend FFI::Library
+ #
+ def attach_fcts fcts
+ fcts.each do |func|
+ begin
+ attach_function *func
+ rescue Object => e
+ puts "Could not attach #{func} #{e.message}"
+ end
+ end
+ end
+ module_function :attach_fcts
+ #
+ typedef :pointer, :int_p
+ typedef :pointer, :uint_p
+ typedef :pointer, :void_p
+ typedef :pointer, :uchar_p
+ typedef :pointer, :string_array
+ #
+ typedef :pointer, :eina_list_p
+ #
+ end
+ #
+end
+#
+# EOF
diff --git a/lib/e17/ffi_helper.rb b/lib/e17/ffi_helper.rb
deleted file mode 100644
index 26efe57..0000000
--- a/lib/e17/ffi_helper.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-#! /usr/bin/env ruby
-# -*- coding: UTF-8 -*-
-#
-require 'ffi'
-#
-module FFIHelper
- #
- def attach_fcts fcts
- fcts.each do |func|
- begin
- attach_function *func
- rescue Object => e
- puts "Could not attach #{func} #{e.message}"
- end
- end
- end
- #
- def create_aliases l, fcts
- module_eval <<-code
- class << self
- #{fcts.map{ |f,a,r| "alias #{f.to_s[l..-1]} #{f}" }.join "\n" }
- end
- code
- end
- #
- def self.extended mod
- mod.module_eval <<-EOF
- typedef :pointer, :int_p
- typedef :pointer, :uint_p
- typedef :pointer, :void_p
- typedef :pointer, :uchar_p
- typedef :pointer, :string_array
- #
- typedef :pointer, :eina_list_p
- EOF
- end
-end
-#
-# EOF
diff --git a/tools/genruby.rb b/tools/genruby.rb
index 9898d28..e291100 100755
--- a/tools/genruby.rb
+++ b/tools/genruby.rb
@@ -26,13 +26,18 @@ HEADER =<<-EOF
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
-require 'e17/ffi_helper'
+require 'e17/ffi'
#
module E17
+ #
module MNAME
+ def self.method_missing m, *args, &block
+ return E17::API.send 'MBASE_'+m.to_s, *args, &block
+ end
+ end
+ #
+ module API
#
- extend FFI::Library
- extend FFIHelper
EOF
FOOTER =<<-EOF
end
@@ -75,8 +80,6 @@ TYPES = {
'struct timeval *' => ':pointer',
'struct sockaddr *' => ':pointer',
# E17 BASE TYPES
-# 'Eina_Bool' => ':bool',
-# 'Eina_Bool *' => ':bool_p',
'Eina_List' => ':eina_list',
'Eina_List *' => ':eina_list_p',
'Eina_Hash' => ':eina_hash',
@@ -125,7 +128,6 @@ def get_type_from_arg arg, l
return '... FIXME'
end
k = arg.gsub(/const/,'').gsub(/\s{2,}/,' ').strip
-# if not k=~/^((?:\w+\s)+\**)\s?(\w+)$/
if k=~/(.*?)(\w+)$/
return get_type $1
end
@@ -154,8 +156,7 @@ def gen_enums path, indent
values = $2
typename = $3
v = set_type typename, typename
-# args = values.split(',').collect { |cst| ':'+cst.strip.downcase }.join ', '
- args = values.split(',').collect { |cst| ':'+cst.strip.downcase.sub(typename.downcase+'_','') }.join(', ').gsub(/=/,',')
+ args = values.split(',').collect { |cst| ':'+cst.strip.downcase }.join(', ').gsub(/=/,',')
r << indent+"# #{typedef} {...} #{typename};\n"
r << wrap_text( indent+"enum :#{v}, [ #{args} ]", 150, indent+' '*4 )+"\n"
end
@@ -178,7 +179,6 @@ def gen_typedefs path, indent
v = set_type t, v
r << indent+"# #{l}\n"
r << indent+"typedef :#{v}, :#{t.downcase}\n"
-# r << indent+"typedef :#{v.downcase}, :#{t.downcase}_p\n"
else
r << indent+"# #{l}\n#{indent}# FIXME\n"
next
@@ -227,31 +227,24 @@ def gen_functions path, indent
end
#
libraries.each do |header,lib|
- module_name = header[0..-3].sub(/_/,'')
+ module_name = header[0..-3].sub(/_/,'').capitalize
base = File.join path, 'api', header
dir = File.join lib_path, header[0..-3].split('_').first.downcase
Dir.mkdir dir unless Dir.exists? dir
- output = File.join dir, "#{header[0..-3].downcase}-defs.rb"
+ output = File.join dir, "#{header[0..-3].downcase}-ffi.rb"
puts "generate #{output}"
open(output,'w:utf-8') do |f|
- f << HEADER.sub(/MNAME/,module_name)
+ f << HEADER.sub(/MNAME/,module_name).sub(/MBASE/,header[0..-3].downcase)
+ f << "#{INDENT}#\n#{INDENT}ffi_lib '#{lib}'\n"
f << "#{INDENT}#\n#{INDENT}# ENUMS\n"
f << gen_enums(base, INDENT)
f << "#{INDENT}#\n#{INDENT}# TYPEDEFS\n"
f << gen_typedefs(base, INDENT)
f << "#{INDENT}#\n#{INDENT}# CALLBACKS\n"
f << gen_callbacks(base, INDENT)
- f << FOOTER
- end
- output = File.join dir, "#{header[0..-3].downcase}-funcs.rb"
- puts "generate #{output}"
- open(output,'w:utf-8') do |f|
- f << HEADER.sub(/MNAME/,module_name)
- f << "#{INDENT}#\n#{INDENT}ffi_lib '#{lib}'\n"
f << "#{INDENT}#\n#{INDENT}# FUNCTIONS\n"
f << gen_functions(base, INDENT)
f << "#{INDENT}#\n#{INDENT}attach_fcts fcts\n"
- f << "#{INDENT}#\n#{INDENT}create_aliases '#{module_name.downcase}_'.length, fcts\n#{INDENT}#\n"
f << FOOTER
end
end