rbind 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rbind/core/rbase.rb +4 -0
- data/lib/rbind/core/rstring.rb +2 -2
- data/lib/rbind/generator_ruby.rb +10 -0
- data/lib/rbind/templates/ruby/rmethod.rb +3 -1
- data/lib/rbind/templates/ruby/roverloaded_method_call.rb +7 -6
- data/lib/rbind/templates/ruby/rtype.rb +28 -2
- data/lib/rbind/typelib.rb +69 -0
- data/rbind.gemspec +3 -3
- metadata +40 -24
data/lib/rbind/core/rbase.rb
CHANGED
@@ -19,6 +19,8 @@ module Rbind
|
|
19
19
|
name = normalize(name)
|
20
20
|
cn = "#{cprefix}#{name.gsub("::","_")}"
|
21
21
|
cn = cn.gsub("()","_fct")
|
22
|
+
cn = cn.gsub("<=","_smaller_equal")
|
23
|
+
cn = cn.gsub(">=","_greater_equal")
|
22
24
|
cn = cn.gsub("!=","_unequal")
|
23
25
|
cn = cn.gsub("==","_equal")
|
24
26
|
cn = cn.gsub("&=","_and_set")
|
@@ -30,6 +32,8 @@ module Rbind
|
|
30
32
|
cn = cn.gsub("/","_div")
|
31
33
|
cn = cn.gsub("!","_not")
|
32
34
|
cn = cn.gsub("&","_and")
|
35
|
+
cn = cn.gsub("<","_smaller")
|
36
|
+
cn = cn.gsub(">","_greater")
|
33
37
|
cn.gsub("[]","_array")
|
34
38
|
end
|
35
39
|
|
data/lib/rbind/core/rstring.rb
CHANGED
@@ -28,14 +28,14 @@ module Rbind
|
|
28
28
|
%Q$ def self.to_native(obj,context)
|
29
29
|
if obj.is_a? ::String
|
30
30
|
str = obj.to_str
|
31
|
-
|
31
|
+
Std::String.new(str,str.length).__obj_ptr__
|
32
32
|
else
|
33
33
|
rbind_to_native(obj,context)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
def to_s
|
37
37
|
c_str
|
38
|
-
end
|
38
|
+
end$
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
data/lib/rbind/generator_ruby.rb
CHANGED
@@ -425,6 +425,16 @@ module Rbind
|
|
425
425
|
str
|
426
426
|
end
|
427
427
|
|
428
|
+
def add_to_s
|
429
|
+
str = []
|
430
|
+
@root.each_operation do |o|
|
431
|
+
next unless o.is_a? RGetter
|
432
|
+
op = OperationHelper.new(o)
|
433
|
+
str << "#{op.name}=\#{self.#{op.name}}"
|
434
|
+
end
|
435
|
+
"\"#<#{full_name} #{str.join(" ")}>\""
|
436
|
+
end
|
437
|
+
|
428
438
|
def add_methods(root=@root)
|
429
439
|
# sort all method according their target name
|
430
440
|
ops = Hash.new do |h,k|
|
@@ -4,8 +4,10 @@
|
|
4
4
|
Rbind::<%= cname %>( <%= wrap_parameters_call %>)
|
5
5
|
<%- else -%>
|
6
6
|
result = Rbind::<%= cname %>( <%= wrap_parameters_call %>)
|
7
|
+
if result.respond_to?(:__owner__?) && !result.__owner__?
|
7
8
|
# store owner insight the pointer to not get garbage collected
|
8
|
-
|
9
|
+
result.instance_variable_get(:@__obj_ptr__).instance_variable_set(:@__owner__,self)
|
10
|
+
end
|
9
11
|
result
|
10
12
|
<%- end -%>
|
11
13
|
end
|
@@ -1,21 +1,22 @@
|
|
1
1
|
# wrapper for <%= signature %>
|
2
2
|
@@<%=cname%>_defaults<%= index %> ||= <%= signature_default_values %>
|
3
3
|
if(args.size >= <%= min_number_of_parameters %> && args.size <= <%= parameters.size %>)
|
4
|
-
args.
|
5
|
-
|
4
|
+
targs = args.clone
|
5
|
+
targs.size.upto(<%= parameters.size-1%>) do |i|
|
6
|
+
targs[i] = @@<%=cname%>_defaults<%=index%>[i]
|
6
7
|
end
|
7
8
|
begin
|
8
9
|
<%- if !return_type || return_type.basic_type? || operator? -%>
|
9
10
|
<%- if constructor? || !instance_method? -%>
|
10
|
-
return Rbind::<%= cname %>(*
|
11
|
+
return Rbind::<%= cname %>(*targs)
|
11
12
|
<%- else -%>
|
12
|
-
return Rbind::<%= cname %>(self,*
|
13
|
+
return Rbind::<%= cname %>(self,*targs)
|
13
14
|
<%- end -%>
|
14
15
|
<%- else -%>
|
15
16
|
<%- if instance_method? -%>
|
16
|
-
result = Rbind::<%= cname %>(self,*
|
17
|
+
result = Rbind::<%= cname %>(self,*targs)
|
17
18
|
<%- else -%>
|
18
|
-
result = Rbind::<%= cname %>(*
|
19
|
+
result = Rbind::<%= cname %>(*targs)
|
19
20
|
<%- end -%>
|
20
21
|
# store owner insight the pointer to not get garbage collected
|
21
22
|
result.instance_variable_get(:@__obj_ptr__).instance_variable_set(:@__owner__,self) if !result.__owner__?
|
@@ -18,6 +18,16 @@ class <%= name %>
|
|
18
18
|
extend FFI::DataConverter
|
19
19
|
native_type FFI::Type::POINTER
|
20
20
|
|
21
|
+
# @api private
|
22
|
+
#
|
23
|
+
# Returns the *Struct type that Rbind uses to store additional information
|
24
|
+
# about the memory used by this object
|
25
|
+
#
|
26
|
+
# @return [FFI::Struct]
|
27
|
+
def self.rbind_struct
|
28
|
+
<%= name %>Struct
|
29
|
+
end
|
30
|
+
|
21
31
|
def self.new(*args)
|
22
32
|
if args.first.is_a?(FFI::Pointer) || args.first.is_a?(<%= name %>Struct)
|
23
33
|
raise ArgumentError, "too many arguments for creating #{self.name} from Pointer" unless args.size == 1
|
@@ -42,13 +52,24 @@ class <%= name %>
|
|
42
52
|
end
|
43
53
|
|
44
54
|
# @api private
|
45
|
-
#
|
55
|
+
#
|
56
|
+
# Performs the convertion a Ruby representation into the FFI representation
|
57
|
+
#
|
58
|
+
# @param [Object] obj the Ruby representation
|
59
|
+
# @param context necessary but undocumented argument from FFI
|
60
|
+
# @return [FFI::Pointer,FFI::AutoPointer]
|
46
61
|
def self.to_native(obj,context)
|
47
62
|
rbind_to_native(obj,context)
|
48
63
|
end
|
49
64
|
|
50
65
|
# @api private
|
51
|
-
#
|
66
|
+
#
|
67
|
+
# Performs the convertion from FFI into the Ruby representation that
|
68
|
+
# corresponds to this type
|
69
|
+
#
|
70
|
+
# @param [FFI::Pointer,FFI::AutoPointer] ptr
|
71
|
+
# @param [] context
|
72
|
+
# @return [Object]
|
52
73
|
def self.from_native(ptr,context)
|
53
74
|
rbind_from_native(ptr,context)
|
54
75
|
end
|
@@ -72,6 +93,11 @@ class <%= name %>
|
|
72
93
|
@__obj_ptr__[:bowner]
|
73
94
|
end
|
74
95
|
|
96
|
+
# converts <%= name %> into a string by crawling through all its attributes
|
97
|
+
def to_s
|
98
|
+
<%= add_to_s %>
|
99
|
+
end
|
100
|
+
|
75
101
|
# @!group Sepcializing
|
76
102
|
<%= add_specializing %>
|
77
103
|
# @!endgroup
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'typelib'
|
2
|
+
module Rbind
|
3
|
+
module Typelib
|
4
|
+
class << self
|
5
|
+
# @return [Typelib::Registry] The typelib registry that should be used by Typelib.to_typelib
|
6
|
+
attr_accessor :registry
|
7
|
+
end
|
8
|
+
self.registry = ::Typelib::Registry.new
|
9
|
+
|
10
|
+
# Converts +rbind+ into a Typelib value
|
11
|
+
#
|
12
|
+
# @param [Object] rbind the Rbind-generated representation of the type.
|
13
|
+
# It has to own the underlying memory
|
14
|
+
# @param [String] typename the Typelib type name into which this type
|
15
|
+
# should be represented
|
16
|
+
# @return [Typelib::Type,nil] the converted value or nil if Typelib.registry
|
17
|
+
# does not contain the requested type
|
18
|
+
def self.to_typelib(klass, rbind, typename)
|
19
|
+
if rbind.kind_of?(FFI::Pointer)
|
20
|
+
rbind = klass.rbind_struct.new(rbind)
|
21
|
+
end
|
22
|
+
if rbind.kind_of?(klass.rbind_struct)
|
23
|
+
if !rbind[:bowner]
|
24
|
+
raise ArgumentError, "cannot convert #{rbind}: it does not own the underlying memory"
|
25
|
+
end
|
26
|
+
if registry.include?(typename)
|
27
|
+
rbind[:bowner] = false
|
28
|
+
typelib_t = registry.get(typename)
|
29
|
+
::Typelib.to_ruby(typelib_t.from_address(rbind[:obj_ptr].address))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
# Converts +obj+ into the FFI::Struct that rbind uses to initialize its Ruby
|
36
|
+
# types (one of the XXXXStruct types generated by Rbind)
|
37
|
+
#
|
38
|
+
# @param [Class<FFI::Struct>] klass the FFI::Struct type
|
39
|
+
# @param [Object] obj the object to be converted
|
40
|
+
# @param [Array<String>] typenames the Typelib type names that are known to
|
41
|
+
# be equivalents of the FFI::Struct represented by klass
|
42
|
+
# @return [FFI::Struct,nil] the converted struct or nil if the obj argument
|
43
|
+
# is not a typelib type
|
44
|
+
# @raise ArgumentError if 'obj' is a typelib type, but not of one of the
|
45
|
+
# expected typenames
|
46
|
+
def self.from_typelib(klass, obj, *typenames)
|
47
|
+
typelib_value = nil
|
48
|
+
typenames.each do |tn|
|
49
|
+
target_t = registry.build(tn)
|
50
|
+
begin
|
51
|
+
typelib_value = ::Typelib.from_ruby(obj, target_t)
|
52
|
+
rescue ArgumentError
|
53
|
+
end
|
54
|
+
end
|
55
|
+
if typelib_value
|
56
|
+
s = klass.rbind_struct.new
|
57
|
+
s[:obj_ptr] = typelib_value.to_memory_ptr.zone_address
|
58
|
+
s[:bowner] = false
|
59
|
+
s[:size] = 0 #obj.marshalling_size
|
60
|
+
s[:type_id] = nil
|
61
|
+
s[:version] = 1
|
62
|
+
s
|
63
|
+
elsif obj.kind_of?(::Typelib::Type)
|
64
|
+
raise ArgumentError, "#{obj} is a typelib type, but I don't know how to convert it to #{klass}. Expected one of #{typenames.sort.join(", ")}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
data/rbind.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'rbind'
|
3
|
-
s.version = '0.0.
|
4
|
-
s.date = '2013-
|
3
|
+
s.version = '0.0.16'
|
4
|
+
s.date = '2013-08-13'
|
5
5
|
s.platform = Gem::Platform::RUBY
|
6
6
|
s.authors = ['Alexander Duda']
|
7
7
|
s.email = ['Alexander.Duda@dfki.de']
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
17
17
|
s.require_path = 'lib'
|
18
18
|
s.required_rubygems_version = ">= 1.3.6"
|
19
|
+
s.add_runtime_dependency "hooks", ">= 0.3.1"
|
19
20
|
|
20
21
|
#s.rubyforge_project = s.name
|
21
|
-
#s.add_runtime_dependency "other", "~> 1.2"
|
22
22
|
end
|
metadata
CHANGED
@@ -1,28 +1,38 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbind
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.15
|
3
|
+
version: !ruby/object:Gem::Version
|
5
4
|
prerelease:
|
5
|
+
version: 0.0.16
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Alexander Duda
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
|
13
|
+
date: 2013-08-13 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hooks
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.3.1
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
description: Rbind is developed to automatically generate ruby bindings for OpenCV but is not tight to this library. It allows to import already wrapped types from other gems/libraries using rbind to share the same types across multiple gems/libraries. For now rbind uses a copy of the OpenCV python hdr_parser to parse c/c++ header files and looks for certain defines. This gem is still under heavy development and the API might change in the future.
|
27
|
+
email:
|
21
28
|
- Alexander.Duda@dfki.de
|
22
29
|
executables: []
|
30
|
+
|
23
31
|
extensions: []
|
32
|
+
|
24
33
|
extra_rdoc_files: []
|
25
|
-
|
34
|
+
|
35
|
+
files:
|
26
36
|
- README.md
|
27
37
|
- lib/rbind.rb
|
28
38
|
- lib/rbind/core.rb
|
@@ -76,30 +86,36 @@ files:
|
|
76
86
|
- lib/rbind/templates/ruby/rtype.rb
|
77
87
|
- lib/rbind/templates/ruby/rtype_constructor.rb
|
78
88
|
- lib/rbind/tools/hdr_parser.py
|
89
|
+
- lib/rbind/typelib.rb
|
79
90
|
- rbind.gemspec
|
80
91
|
- test/test_generator_ruby.rb
|
81
92
|
homepage: http://github.com/D-Alex/rbind
|
82
93
|
licenses: []
|
94
|
+
|
83
95
|
post_install_message:
|
84
96
|
rdoc_options: []
|
85
|
-
|
97
|
+
|
98
|
+
require_paths:
|
86
99
|
- lib
|
87
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
101
|
none: false
|
89
|
-
requirements:
|
90
|
-
- -
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version:
|
93
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: "0"
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
107
|
none: false
|
95
|
-
requirements:
|
96
|
-
- -
|
97
|
-
- !ruby/object:Gem::Version
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
98
111
|
version: 1.3.6
|
99
112
|
requirements: []
|
113
|
+
|
100
114
|
rubyforge_project:
|
101
115
|
rubygems_version: 1.8.23
|
102
116
|
signing_key:
|
103
117
|
specification_version: 3
|
104
118
|
summary: Library for genereating automated ffi-bindings for c/c++ libraries
|
105
119
|
test_files: []
|
120
|
+
|
121
|
+
has_rdoc:
|