rbind 0.0.12 → 0.0.13
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/generator_extern.rb +5 -3
- data/lib/rbind/generator_ruby.rb +1 -1
- data/lib/rbind/rbind.rb +2 -2
- data/lib/rbind/templates/c/CMakeLists.txt +2 -3
- data/lib/rbind/templates/ruby/rbind.rb +7 -4
- data/lib/rbind/templates/ruby/rnamespace.rb +3 -0
- data/lib/rbind/templates/ruby/rtype.rb +14 -2
- data/rbind.gemspec +1 -1
- metadata +2 -1
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
|
|
@@ -2,10 +2,11 @@ require 'yaml'
|
|
2
2
|
|
3
3
|
module Rbind
|
4
4
|
class GeneratorExtern
|
5
|
-
Config = Struct.new(:ruby_module_name)
|
5
|
+
Config = Struct.new(:ruby_module_name,:file_prefix)
|
6
6
|
|
7
7
|
attr_accessor :output_path
|
8
8
|
attr_accessor :ruby_module_name
|
9
|
+
attr_accessor :file_prefix
|
9
10
|
def self.normalize_type_name(name)
|
10
11
|
name.gsub('::','.')
|
11
12
|
end
|
@@ -14,9 +15,10 @@ module Rbind
|
|
14
15
|
@root = root
|
15
16
|
end
|
16
17
|
|
17
|
-
def generate(path = @output_path,ruby_module_name = @ruby_module_name)
|
18
|
+
def generate(path = @output_path,ruby_module_name = @ruby_module_name,file_prefix = @file_prefix)
|
18
19
|
@output_path = path
|
19
20
|
@ruby_module_name = ruby_module_name
|
21
|
+
@file_prefix = file_prefix
|
20
22
|
FileUtils.mkdir_p(path) if path && !File.directory?(path)
|
21
23
|
file_extern = File.new(File.join(path,"extern.rbind"),"w")
|
22
24
|
file_config = File.new(File.join(path,"config.rbind"),"w")
|
@@ -33,7 +35,7 @@ module Rbind
|
|
33
35
|
file_extern.write "const #{GeneratorExtern.normalize_type_name(c.full_name)} /Extern\n"
|
34
36
|
end
|
35
37
|
file_extern.write("\n")
|
36
|
-
file_config.write Config.new(ruby_module_name).to_yaml
|
38
|
+
file_config.write Config.new(ruby_module_name,file_prefix).to_yaml
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
data/lib/rbind/generator_ruby.rb
CHANGED
@@ -516,7 +516,7 @@ module Rbind
|
|
516
516
|
@rbind_wrapper = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","ruby","rbind.rb")).read)
|
517
517
|
@module_name = module_name
|
518
518
|
@library_name = library_name
|
519
|
-
@compact_namespace =
|
519
|
+
@compact_namespace = true
|
520
520
|
end
|
521
521
|
|
522
522
|
def generate(path=@output_path)
|
data/lib/rbind/rbind.rb
CHANGED
@@ -150,7 +150,7 @@ module Rbind
|
|
150
150
|
paths = Rbind.rbind_pkg_paths(@pkg_config)
|
151
151
|
modules = paths.map do |pkg|
|
152
152
|
config = YAML.load(File.open(File.join(pkg,"config.rbind")).read)
|
153
|
-
config.
|
153
|
+
config.file_prefix
|
154
154
|
end
|
155
155
|
@generator_ruby.required_module_names = modules + gems
|
156
156
|
@generator_ruby.generate(path)
|
@@ -165,7 +165,7 @@ module Rbind
|
|
165
165
|
end
|
166
166
|
|
167
167
|
def generate_extern(path)
|
168
|
-
@generator_extern.generate(path,@generator_ruby.module_name)
|
168
|
+
@generator_extern.generate(path,@generator_ruby.module_name,@generator_ruby.file_prefix)
|
169
169
|
end
|
170
170
|
|
171
171
|
def use_namespace(name)
|
@@ -17,9 +17,8 @@ ADD_LIBRARY(<%= library_name %> SHARED ${RBIND_SRC})
|
|
17
17
|
TARGET_LINK_LIBRARIES(<%= library_name %> <%= libs %> ${GEM_LIBRARIES})
|
18
18
|
|
19
19
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/rbind.pc.in ${CMAKE_CURRENT_BINARY_DIR}/<%= library_name %>.pc @ONLY)
|
20
|
-
set(ROOT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/..)
|
21
20
|
|
22
|
-
|
21
|
+
set(ROOT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/..)
|
23
22
|
if(GEM_INSTALL)
|
24
23
|
# local install
|
25
24
|
install(TARGETS <%= library_name %> LIBRARY DESTINATION ${ROOT_FOLDER}/lib/lib)
|
@@ -39,7 +38,7 @@ else()
|
|
39
38
|
MESSAGE(STATUS "Ruby library not found. Cannot install ruby extensions")
|
40
39
|
ELSEIF(NOT RUBY_EXTENSIONS_AVAILABLE)
|
41
40
|
STRING(REGEX REPLACE ".*lib(32|64)?/?" "lib/" RUBY_LIBRARY_INSTALL_DIR ${RUBY_RUBY_LIB_PATH})
|
42
|
-
INSTALL(DIRECTORY ${ROOT_FOLDER}/lib/ruby DESTINATION ${RUBY_LIBRARY_INSTALL_DIR}
|
41
|
+
INSTALL(DIRECTORY ${ROOT_FOLDER}/lib/ruby/ DESTINATION ${RUBY_LIBRARY_INSTALL_DIR}
|
43
42
|
FILES_MATCHING PATTERN "*.rb")
|
44
43
|
ENDIF(NOT RUBY_INCLUDE_PATH)
|
45
44
|
endif()
|
@@ -8,10 +8,13 @@ module <%= name %>
|
|
8
8
|
extend FFI::Library
|
9
9
|
|
10
10
|
#load library <%= library_name %>
|
11
|
-
path =
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
path = File.join(File.dirname(__FILE__),"..","..","lib")
|
12
|
+
path = if Dir.exist?(path)
|
13
|
+
Dir.chdir(path) do
|
14
|
+
path = Dir.glob("lib<%= library_name %>.*").first
|
15
|
+
File.absolute_path(path) if path
|
16
|
+
end
|
17
|
+
end
|
15
18
|
ffi_lib ["<%= library_name %>", path]
|
16
19
|
|
17
20
|
#add error checking
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# @api private
|
1
2
|
# object wrapping <%= full_name %>
|
2
3
|
class <%= name %>Struct < FFI::Struct
|
3
4
|
layout :version,:uchar,
|
@@ -26,6 +27,7 @@ class <%= name %>
|
|
26
27
|
raise ArgumentError, "no constructor for #{self}(#{args.inspect})"
|
27
28
|
end
|
28
29
|
|
30
|
+
# @api private
|
29
31
|
def self.rbind_to_native(obj,context)
|
30
32
|
if obj.is_a? <%= name %>
|
31
33
|
obj.__obj_ptr__
|
@@ -34,21 +36,27 @@ class <%= name %>
|
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
39
|
+
# @api private
|
37
40
|
def self.rbind_from_native(ptr,context)
|
38
41
|
<%= name %>.new(ptr)
|
39
42
|
end
|
40
43
|
|
44
|
+
# @api private
|
41
45
|
# can be overwritten by the user
|
42
46
|
def self.to_native(obj,context)
|
43
47
|
rbind_to_native(obj,context)
|
44
48
|
end
|
45
49
|
|
50
|
+
# @api private
|
46
51
|
# can be overwritten by the user
|
47
52
|
def self.from_native(ptr,context)
|
48
53
|
rbind_from_native(ptr,context)
|
49
54
|
end
|
50
55
|
|
56
|
+
# @api private
|
51
57
|
attr_reader :__obj_ptr__
|
58
|
+
|
59
|
+
# @api private
|
52
60
|
def initialize(ptr)
|
53
61
|
@__obj_ptr__ = if ptr.is_a? <%= name %>Struct
|
54
62
|
ptr
|
@@ -57,20 +65,24 @@ class <%= name %>
|
|
57
65
|
end
|
58
66
|
end
|
59
67
|
|
68
|
+
# @api private
|
60
69
|
# returns true if the underlying pointer is owner of
|
61
70
|
# the real object
|
62
71
|
def __owner__?
|
63
72
|
@__obj_ptr__[:bowner]
|
64
73
|
end
|
65
74
|
|
66
|
-
#
|
75
|
+
# @!group Sepcializing
|
67
76
|
<%= add_specializing %>
|
77
|
+
# @!endgroup
|
68
78
|
|
69
|
-
#
|
79
|
+
# @!group Constants
|
70
80
|
<%= add_consts %>
|
81
|
+
# @!endgroup
|
71
82
|
|
72
83
|
# methods
|
73
84
|
<%= add_methods %>
|
85
|
+
|
74
86
|
# types
|
75
87
|
<%= add_types %>
|
76
88
|
end
|
data/rbind.gemspec
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rbind
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.13
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Alexander Duda
|
@@ -106,3 +106,4 @@ specification_version: 3
|
|
106
106
|
summary: Library for genereating automated ffi-bindings for c/c++ libraries
|
107
107
|
test_files: []
|
108
108
|
|
109
|
+
has_rdoc:
|