dub 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/History.txt +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +53 -0
- data/Rakefile +58 -0
- data/dub.gemspec +194 -0
- data/lib/dub/argument.rb +261 -0
- data/lib/dub/entities_unescape.rb +16 -0
- data/lib/dub/function.rb +111 -0
- data/lib/dub/function_group.rb +74 -0
- data/lib/dub/generator.rb +15 -0
- data/lib/dub/group.rb +10 -0
- data/lib/dub/klass.rb +231 -0
- data/lib/dub/lua/class.cpp.erb +75 -0
- data/lib/dub/lua/class_gen.rb +78 -0
- data/lib/dub/lua/function.cpp.erb +4 -0
- data/lib/dub/lua/function_gen.rb +223 -0
- data/lib/dub/lua/group.cpp.erb +10 -0
- data/lib/dub/lua/lua_cpp_helper.h +141 -0
- data/lib/dub/lua/namespace.cpp.erb +35 -0
- data/lib/dub/lua/namespace_gen.rb +86 -0
- data/lib/dub/lua.rb +24 -0
- data/lib/dub/member_extraction.rb +88 -0
- data/lib/dub/namespace.rb +276 -0
- data/lib/dub/parser.rb +46 -0
- data/lib/dub/templates/lua_template.erb +21 -0
- data/lib/dub/version.rb +3 -0
- data/lib/dub.rb +26 -0
- data/test/argument_test.rb +423 -0
- data/test/fixtures/app/CMakeLists.txt +54 -0
- data/test/fixtures/app/Doxyfile +1600 -0
- data/test/fixtures/app/bindings/all_lua.cpp +299 -0
- data/test/fixtures/app/include/matrix.h +123 -0
- data/test/fixtures/app/make_lua_bindings.rb +13 -0
- data/test/fixtures/app/vendor/lua/CMakeLists.txt +25 -0
- data/test/fixtures/app/vendor/lua/COPYRIGHT +34 -0
- data/test/fixtures/app/vendor/lua/HISTORY +183 -0
- data/test/fixtures/app/vendor/lua/INSTALL +99 -0
- data/test/fixtures/app/vendor/lua/Makefile +183 -0
- data/test/fixtures/app/vendor/lua/README +37 -0
- data/test/fixtures/app/vendor/lua/lapi.c +1080 -0
- data/test/fixtures/app/vendor/lua/lapi.h +16 -0
- data/test/fixtures/app/vendor/lua/lauxlib.c +653 -0
- data/test/fixtures/app/vendor/lua/lauxlib.h +174 -0
- data/test/fixtures/app/vendor/lua/lbaselib.c +643 -0
- data/test/fixtures/app/vendor/lua/lcode.c +839 -0
- data/test/fixtures/app/vendor/lua/lcode.h +76 -0
- data/test/fixtures/app/vendor/lua/ldblib.c +397 -0
- data/test/fixtures/app/vendor/lua/ldebug.c +622 -0
- data/test/fixtures/app/vendor/lua/ldebug.h +33 -0
- data/test/fixtures/app/vendor/lua/ldo.c +516 -0
- data/test/fixtures/app/vendor/lua/ldo.h +57 -0
- data/test/fixtures/app/vendor/lua/ldump.c +164 -0
- data/test/fixtures/app/vendor/lua/lfunc.c +174 -0
- data/test/fixtures/app/vendor/lua/lfunc.h +34 -0
- data/test/fixtures/app/vendor/lua/lgc.c +711 -0
- data/test/fixtures/app/vendor/lua/lgc.h +110 -0
- data/test/fixtures/app/vendor/lua/liblua.a +0 -0
- data/test/fixtures/app/vendor/lua/linit.c +38 -0
- data/test/fixtures/app/vendor/lua/liolib.c +532 -0
- data/test/fixtures/app/vendor/lua/llex.c +461 -0
- data/test/fixtures/app/vendor/lua/llex.h +81 -0
- data/test/fixtures/app/vendor/lua/llimits.h +128 -0
- data/test/fixtures/app/vendor/lua/lmathlib.c +263 -0
- data/test/fixtures/app/vendor/lua/lmem.c +86 -0
- data/test/fixtures/app/vendor/lua/lmem.h +49 -0
- data/test/fixtures/app/vendor/lua/loadlib.c +664 -0
- data/test/fixtures/app/vendor/lua/lobject.c +214 -0
- data/test/fixtures/app/vendor/lua/lobject.h +381 -0
- data/test/fixtures/app/vendor/lua/lopcodes.c +102 -0
- data/test/fixtures/app/vendor/lua/lopcodes.h +268 -0
- data/test/fixtures/app/vendor/lua/loslib.c +244 -0
- data/test/fixtures/app/vendor/lua/lparser.c +1337 -0
- data/test/fixtures/app/vendor/lua/lparser.h +82 -0
- data/test/fixtures/app/vendor/lua/lstate.c +214 -0
- data/test/fixtures/app/vendor/lua/lstate.h +168 -0
- data/test/fixtures/app/vendor/lua/lstring.c +111 -0
- data/test/fixtures/app/vendor/lua/lstring.h +31 -0
- data/test/fixtures/app/vendor/lua/lstrlib.c +868 -0
- data/test/fixtures/app/vendor/lua/ltable.c +588 -0
- data/test/fixtures/app/vendor/lua/ltable.h +40 -0
- data/test/fixtures/app/vendor/lua/ltablib.c +278 -0
- data/test/fixtures/app/vendor/lua/ltm.c +75 -0
- data/test/fixtures/app/vendor/lua/ltm.h +54 -0
- data/test/fixtures/app/vendor/lua/lua.c +695 -0
- data/test/fixtures/app/vendor/lua/lua.h +385 -0
- data/test/fixtures/app/vendor/lua/lua_dub_helper.h +77 -0
- data/test/fixtures/app/vendor/lua/luac +0 -0
- data/test/fixtures/app/vendor/lua/luac.c +200 -0
- data/test/fixtures/app/vendor/lua/luaconf.h +762 -0
- data/test/fixtures/app/vendor/lua/lualib.h +53 -0
- data/test/fixtures/app/vendor/lua/lundump.c +223 -0
- data/test/fixtures/app/vendor/lua/lundump.h +36 -0
- data/test/fixtures/app/vendor/lua/lvm.c +765 -0
- data/test/fixtures/app/vendor/lua/lvm.h +36 -0
- data/test/fixtures/app/vendor/lua/lzio.c +82 -0
- data/test/fixtures/app/vendor/lua/lzio.h +67 -0
- data/test/fixtures/app/vendor/lua/matrix.h +102 -0
- data/test/fixtures/app/vendor/lua/print.c +227 -0
- data/test/fixtures/app/vendor/lua/test/README +26 -0
- data/test/fixtures/app/vendor/lua/test/bisect.lua +27 -0
- data/test/fixtures/app/vendor/lua/test/cf.lua +16 -0
- data/test/fixtures/app/vendor/lua/test/echo.lua +5 -0
- data/test/fixtures/app/vendor/lua/test/env.lua +7 -0
- data/test/fixtures/app/vendor/lua/test/factorial.lua +32 -0
- data/test/fixtures/app/vendor/lua/test/fib.lua +40 -0
- data/test/fixtures/app/vendor/lua/test/fibfor.lua +13 -0
- data/test/fixtures/app/vendor/lua/test/globals.lua +13 -0
- data/test/fixtures/app/vendor/lua/test/hello.lua +3 -0
- data/test/fixtures/app/vendor/lua/test/life.lua +111 -0
- data/test/fixtures/app/vendor/lua/test/luac.lua +7 -0
- data/test/fixtures/app/vendor/lua/test/printf.lua +7 -0
- data/test/fixtures/app/vendor/lua/test/readonly.lua +12 -0
- data/test/fixtures/app/vendor/lua/test/sieve.lua +29 -0
- data/test/fixtures/app/vendor/lua/test/sort.lua +66 -0
- data/test/fixtures/app/vendor/lua/test/table.lua +12 -0
- data/test/fixtures/app/vendor/lua/test/trace-calls.lua +32 -0
- data/test/fixtures/app/vendor/lua/test/trace-globals.lua +38 -0
- data/test/fixtures/app/vendor/lua/test/xd.lua +14 -0
- data/test/fixtures/app/xml/classdub_1_1_matrix.xml +239 -0
- data/test/fixtures/app/xml/classdub_1_1_t_mat.xml +233 -0
- data/test/fixtures/app/xml/combine.xslt +15 -0
- data/test/fixtures/app/xml/compound.xsd +814 -0
- data/test/fixtures/app/xml/dir_53661a2bdeb1d55e60581a7e15deb763.xml +12 -0
- data/test/fixtures/app/xml/index.xml +42 -0
- data/test/fixtures/app/xml/index.xsd +66 -0
- data/test/fixtures/app/xml/matrix_8h.xml +149 -0
- data/test/fixtures/app/xml/namespacedub.xml +41 -0
- data/test/fixtures/classcv_1_1_mat.xml +1996 -0
- data/test/fixtures/classcv_1_1_point__.xml +341 -0
- data/test/fixtures/classcv_1_1_size__.xml +270 -0
- data/test/fixtures/group___magic_type.xml +406 -0
- data/test/fixtures/namespacecv.xml +12659 -0
- data/test/function_group_test.rb +15 -0
- data/test/function_test.rb +252 -0
- data/test/group_test.rb +155 -0
- data/test/helper.rb +34 -0
- data/test/klass_test.rb +297 -0
- data/test/lua_function_gen_test.rb +179 -0
- data/test/namespace_test.rb +220 -0
- data/test/parser_test.rb +36 -0
- metadata +216 -0
data/.gitignore
ADDED
data/History.txt
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 by Gaspard Bucher - Buma (http://teti.ch).
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
= Dub (Doxygen based Ubiquitous Binder)
|
2
|
+
|
3
|
+
This is a tool to ease the creation of scripting language bindings for a C++ library.
|
4
|
+
It is currently developed to crete the OpenCV bindings for Lua in Rubyk (http://rubyk.org).
|
5
|
+
|
6
|
+
The generator uses the xml output from Doxygen to avoid parsing C++ code by itself.
|
7
|
+
|
8
|
+
= Features
|
9
|
+
|
10
|
+
Currently, the parser supports:
|
11
|
+
|
12
|
+
* class methods
|
13
|
+
* overloaded class constructors
|
14
|
+
* overloaded class methods
|
15
|
+
* class instantiation from templates through typedefs
|
16
|
+
* class alias through typedefs
|
17
|
+
* automatic resolution of template parameters
|
18
|
+
* automatic handling of default values
|
19
|
+
* class enums
|
20
|
+
* namespace enums
|
21
|
+
* group constant defines
|
22
|
+
* well tested
|
23
|
+
|
24
|
+
If you are not good at reading lists, here is an example of the kind of tricks Dub plays with types:
|
25
|
+
|
26
|
+
template<class T>
|
27
|
+
class Point_ {
|
28
|
+
...
|
29
|
+
};
|
30
|
+
|
31
|
+
template<class T>
|
32
|
+
class Size_ {
|
33
|
+
Size_(const Point_<T>);
|
34
|
+
};
|
35
|
+
typedef Size_<int> Size2i;
|
36
|
+
typedef Size2i Size;
|
37
|
+
|
38
|
+
typedef Point_<int> Point2i;
|
39
|
+
typedef Point2i Point;
|
40
|
+
|
41
|
+
|
42
|
+
All these typedefs and templates will generate two class bindings with some aliases:
|
43
|
+
|
44
|
+
* <tt>Size</tt>, aliased as <tt>Size2i</tt>
|
45
|
+
* <tt>Point</tt>, aliased as <tt>Point2i</tt>
|
46
|
+
|
47
|
+
And what's really good is that in the definition for the <tt>Size</tt> constructor, <tt>Point_<T></tt> is
|
48
|
+
recognized as <tt>Point</tt> !
|
49
|
+
|
50
|
+
=== Lua Generator
|
51
|
+
|
52
|
+
Since this generator uses C++ code and memory allocation, you *MUST* compile Lua as C++ code
|
53
|
+
to avoid memory leaks (error handling should use exceptions instead of longjmp).
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
5
|
+
require 'dub/version'
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'jeweler'
|
9
|
+
Jeweler::Tasks.new do |gem|
|
10
|
+
gem.name = "dub"
|
11
|
+
gem.version = Dub::VERSION
|
12
|
+
gem.summary = %Q{A tool to ease the creation of scripting language bindings for a C++ library.}
|
13
|
+
gem.description = %Q{This is a tool to ease the creation of scripting language bindings for a C++ library.
|
14
|
+
It is currently developed to crete the OpenCV bindings for Lua in Rubyk (http://rubyk.org). The generator uses the xml output from Doxygen to avoid parsing C++ code by itself.}
|
15
|
+
gem.email = "gaspard@teti.ch"
|
16
|
+
gem.homepage = "http://github.com/ruby/dub"
|
17
|
+
gem.authors = ["Gaspard Bucher"]
|
18
|
+
gem.add_development_dependency "shoulda", ">= 0"
|
19
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
20
|
+
end
|
21
|
+
Jeweler::GemcutterTasks.new
|
22
|
+
rescue LoadError
|
23
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'rake/testtask'
|
27
|
+
Rake::TestTask.new(:test) do |test|
|
28
|
+
test.libs << 'lib' << 'test'
|
29
|
+
test.pattern = 'test/**/*_test.rb'
|
30
|
+
test.verbose = true
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
require 'rcov/rcovtask'
|
35
|
+
Rcov::RcovTask.new do |test|
|
36
|
+
test.libs << 'test'
|
37
|
+
test.pattern = 'test/**/*_test.rb'
|
38
|
+
test.verbose = true
|
39
|
+
end
|
40
|
+
rescue LoadError
|
41
|
+
task :rcov do
|
42
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
task :test => :check_dependencies
|
47
|
+
|
48
|
+
task :default => :test
|
49
|
+
|
50
|
+
require 'rake/rdoctask'
|
51
|
+
Rake::RDocTask.new do |rdoc|
|
52
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
53
|
+
|
54
|
+
rdoc.rdoc_dir = 'rdoc'
|
55
|
+
rdoc.title = "Dub #{version}"
|
56
|
+
rdoc.rdoc_files.include('README*')
|
57
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
58
|
+
end
|
data/dub.gemspec
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{dub}
|
8
|
+
s.version = "0.5.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Gaspard Bucher"]
|
12
|
+
s.date = %q{2010-03-03}
|
13
|
+
s.description = %q{This is a tool to ease the creation of scripting language bindings for a C++ library.
|
14
|
+
It is currently developed to crete the OpenCV bindings for Lua in Rubyk (http://rubyk.org). The generator uses the xml output from Doxygen to avoid parsing C++ code by itself.}
|
15
|
+
s.email = %q{gaspard@teti.ch}
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".gitignore",
|
22
|
+
"History.txt",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"dub.gemspec",
|
27
|
+
"lib/dub.rb",
|
28
|
+
"lib/dub/argument.rb",
|
29
|
+
"lib/dub/entities_unescape.rb",
|
30
|
+
"lib/dub/function.rb",
|
31
|
+
"lib/dub/function_group.rb",
|
32
|
+
"lib/dub/generator.rb",
|
33
|
+
"lib/dub/group.rb",
|
34
|
+
"lib/dub/klass.rb",
|
35
|
+
"lib/dub/lua.rb",
|
36
|
+
"lib/dub/lua/class.cpp.erb",
|
37
|
+
"lib/dub/lua/class_gen.rb",
|
38
|
+
"lib/dub/lua/function.cpp.erb",
|
39
|
+
"lib/dub/lua/function_gen.rb",
|
40
|
+
"lib/dub/lua/group.cpp.erb",
|
41
|
+
"lib/dub/lua/lua_cpp_helper.h",
|
42
|
+
"lib/dub/lua/namespace.cpp.erb",
|
43
|
+
"lib/dub/lua/namespace_gen.rb",
|
44
|
+
"lib/dub/member_extraction.rb",
|
45
|
+
"lib/dub/namespace.rb",
|
46
|
+
"lib/dub/parser.rb",
|
47
|
+
"lib/dub/templates/lua_template.erb",
|
48
|
+
"lib/dub/version.rb",
|
49
|
+
"test/argument_test.rb",
|
50
|
+
"test/fixtures/app/CMakeLists.txt",
|
51
|
+
"test/fixtures/app/Doxyfile",
|
52
|
+
"test/fixtures/app/bindings/all_lua.cpp",
|
53
|
+
"test/fixtures/app/include/matrix.h",
|
54
|
+
"test/fixtures/app/make_lua_bindings.rb",
|
55
|
+
"test/fixtures/app/vendor/lua/CMakeLists.txt",
|
56
|
+
"test/fixtures/app/vendor/lua/COPYRIGHT",
|
57
|
+
"test/fixtures/app/vendor/lua/HISTORY",
|
58
|
+
"test/fixtures/app/vendor/lua/INSTALL",
|
59
|
+
"test/fixtures/app/vendor/lua/Makefile",
|
60
|
+
"test/fixtures/app/vendor/lua/README",
|
61
|
+
"test/fixtures/app/vendor/lua/lapi.c",
|
62
|
+
"test/fixtures/app/vendor/lua/lapi.h",
|
63
|
+
"test/fixtures/app/vendor/lua/lauxlib.c",
|
64
|
+
"test/fixtures/app/vendor/lua/lauxlib.h",
|
65
|
+
"test/fixtures/app/vendor/lua/lbaselib.c",
|
66
|
+
"test/fixtures/app/vendor/lua/lcode.c",
|
67
|
+
"test/fixtures/app/vendor/lua/lcode.h",
|
68
|
+
"test/fixtures/app/vendor/lua/ldblib.c",
|
69
|
+
"test/fixtures/app/vendor/lua/ldebug.c",
|
70
|
+
"test/fixtures/app/vendor/lua/ldebug.h",
|
71
|
+
"test/fixtures/app/vendor/lua/ldo.c",
|
72
|
+
"test/fixtures/app/vendor/lua/ldo.h",
|
73
|
+
"test/fixtures/app/vendor/lua/ldump.c",
|
74
|
+
"test/fixtures/app/vendor/lua/lfunc.c",
|
75
|
+
"test/fixtures/app/vendor/lua/lfunc.h",
|
76
|
+
"test/fixtures/app/vendor/lua/lgc.c",
|
77
|
+
"test/fixtures/app/vendor/lua/lgc.h",
|
78
|
+
"test/fixtures/app/vendor/lua/liblua.a",
|
79
|
+
"test/fixtures/app/vendor/lua/linit.c",
|
80
|
+
"test/fixtures/app/vendor/lua/liolib.c",
|
81
|
+
"test/fixtures/app/vendor/lua/llex.c",
|
82
|
+
"test/fixtures/app/vendor/lua/llex.h",
|
83
|
+
"test/fixtures/app/vendor/lua/llimits.h",
|
84
|
+
"test/fixtures/app/vendor/lua/lmathlib.c",
|
85
|
+
"test/fixtures/app/vendor/lua/lmem.c",
|
86
|
+
"test/fixtures/app/vendor/lua/lmem.h",
|
87
|
+
"test/fixtures/app/vendor/lua/loadlib.c",
|
88
|
+
"test/fixtures/app/vendor/lua/lobject.c",
|
89
|
+
"test/fixtures/app/vendor/lua/lobject.h",
|
90
|
+
"test/fixtures/app/vendor/lua/lopcodes.c",
|
91
|
+
"test/fixtures/app/vendor/lua/lopcodes.h",
|
92
|
+
"test/fixtures/app/vendor/lua/loslib.c",
|
93
|
+
"test/fixtures/app/vendor/lua/lparser.c",
|
94
|
+
"test/fixtures/app/vendor/lua/lparser.h",
|
95
|
+
"test/fixtures/app/vendor/lua/lstate.c",
|
96
|
+
"test/fixtures/app/vendor/lua/lstate.h",
|
97
|
+
"test/fixtures/app/vendor/lua/lstring.c",
|
98
|
+
"test/fixtures/app/vendor/lua/lstring.h",
|
99
|
+
"test/fixtures/app/vendor/lua/lstrlib.c",
|
100
|
+
"test/fixtures/app/vendor/lua/ltable.c",
|
101
|
+
"test/fixtures/app/vendor/lua/ltable.h",
|
102
|
+
"test/fixtures/app/vendor/lua/ltablib.c",
|
103
|
+
"test/fixtures/app/vendor/lua/ltm.c",
|
104
|
+
"test/fixtures/app/vendor/lua/ltm.h",
|
105
|
+
"test/fixtures/app/vendor/lua/lua.c",
|
106
|
+
"test/fixtures/app/vendor/lua/lua.h",
|
107
|
+
"test/fixtures/app/vendor/lua/lua_dub_helper.h",
|
108
|
+
"test/fixtures/app/vendor/lua/luac",
|
109
|
+
"test/fixtures/app/vendor/lua/luac.c",
|
110
|
+
"test/fixtures/app/vendor/lua/luaconf.h",
|
111
|
+
"test/fixtures/app/vendor/lua/lualib.h",
|
112
|
+
"test/fixtures/app/vendor/lua/lundump.c",
|
113
|
+
"test/fixtures/app/vendor/lua/lundump.h",
|
114
|
+
"test/fixtures/app/vendor/lua/lvm.c",
|
115
|
+
"test/fixtures/app/vendor/lua/lvm.h",
|
116
|
+
"test/fixtures/app/vendor/lua/lzio.c",
|
117
|
+
"test/fixtures/app/vendor/lua/lzio.h",
|
118
|
+
"test/fixtures/app/vendor/lua/matrix.h",
|
119
|
+
"test/fixtures/app/vendor/lua/print.c",
|
120
|
+
"test/fixtures/app/vendor/lua/test/README",
|
121
|
+
"test/fixtures/app/vendor/lua/test/bisect.lua",
|
122
|
+
"test/fixtures/app/vendor/lua/test/cf.lua",
|
123
|
+
"test/fixtures/app/vendor/lua/test/echo.lua",
|
124
|
+
"test/fixtures/app/vendor/lua/test/env.lua",
|
125
|
+
"test/fixtures/app/vendor/lua/test/factorial.lua",
|
126
|
+
"test/fixtures/app/vendor/lua/test/fib.lua",
|
127
|
+
"test/fixtures/app/vendor/lua/test/fibfor.lua",
|
128
|
+
"test/fixtures/app/vendor/lua/test/globals.lua",
|
129
|
+
"test/fixtures/app/vendor/lua/test/hello.lua",
|
130
|
+
"test/fixtures/app/vendor/lua/test/life.lua",
|
131
|
+
"test/fixtures/app/vendor/lua/test/luac.lua",
|
132
|
+
"test/fixtures/app/vendor/lua/test/printf.lua",
|
133
|
+
"test/fixtures/app/vendor/lua/test/readonly.lua",
|
134
|
+
"test/fixtures/app/vendor/lua/test/sieve.lua",
|
135
|
+
"test/fixtures/app/vendor/lua/test/sort.lua",
|
136
|
+
"test/fixtures/app/vendor/lua/test/table.lua",
|
137
|
+
"test/fixtures/app/vendor/lua/test/trace-calls.lua",
|
138
|
+
"test/fixtures/app/vendor/lua/test/trace-globals.lua",
|
139
|
+
"test/fixtures/app/vendor/lua/test/xd.lua",
|
140
|
+
"test/fixtures/app/xml/classdub_1_1_matrix.xml",
|
141
|
+
"test/fixtures/app/xml/classdub_1_1_t_mat.xml",
|
142
|
+
"test/fixtures/app/xml/combine.xslt",
|
143
|
+
"test/fixtures/app/xml/compound.xsd",
|
144
|
+
"test/fixtures/app/xml/dir_53661a2bdeb1d55e60581a7e15deb763.xml",
|
145
|
+
"test/fixtures/app/xml/index.xml",
|
146
|
+
"test/fixtures/app/xml/index.xsd",
|
147
|
+
"test/fixtures/app/xml/matrix_8h.xml",
|
148
|
+
"test/fixtures/app/xml/namespacedub.xml",
|
149
|
+
"test/fixtures/classcv_1_1_mat.xml",
|
150
|
+
"test/fixtures/classcv_1_1_point__.xml",
|
151
|
+
"test/fixtures/classcv_1_1_size__.xml",
|
152
|
+
"test/fixtures/group___magic_type.xml",
|
153
|
+
"test/fixtures/namespacecv.xml",
|
154
|
+
"test/function_group_test.rb",
|
155
|
+
"test/function_test.rb",
|
156
|
+
"test/group_test.rb",
|
157
|
+
"test/helper.rb",
|
158
|
+
"test/klass_test.rb",
|
159
|
+
"test/lua_function_gen_test.rb",
|
160
|
+
"test/namespace_test.rb",
|
161
|
+
"test/parser_test.rb"
|
162
|
+
]
|
163
|
+
s.homepage = %q{http://github.com/ruby/dub}
|
164
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
165
|
+
s.require_paths = ["lib"]
|
166
|
+
s.rubygems_version = %q{1.3.5}
|
167
|
+
s.summary = %q{A tool to ease the creation of scripting language bindings for a C++ library.}
|
168
|
+
s.test_files = [
|
169
|
+
"test/argument_test.rb",
|
170
|
+
"test/fixtures/app/make_lua_bindings.rb",
|
171
|
+
"test/function_group_test.rb",
|
172
|
+
"test/function_test.rb",
|
173
|
+
"test/group_test.rb",
|
174
|
+
"test/helper.rb",
|
175
|
+
"test/klass_test.rb",
|
176
|
+
"test/lua_function_gen_test.rb",
|
177
|
+
"test/namespace_test.rb",
|
178
|
+
"test/parser_test.rb"
|
179
|
+
]
|
180
|
+
|
181
|
+
if s.respond_to? :specification_version then
|
182
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
183
|
+
s.specification_version = 3
|
184
|
+
|
185
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
186
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
187
|
+
else
|
188
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
189
|
+
end
|
190
|
+
else
|
191
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
data/lib/dub/argument.rb
ADDED
@@ -0,0 +1,261 @@
|
|
1
|
+
require 'dub/entities_unescape'
|
2
|
+
|
3
|
+
module Dub
|
4
|
+
class Argument
|
5
|
+
include Dub::EntitiesUnescape
|
6
|
+
attr_reader :name, :default, :function, :xml
|
7
|
+
attr_accessor :type
|
8
|
+
|
9
|
+
NUMBER_TYPES = [
|
10
|
+
'float',
|
11
|
+
'double',
|
12
|
+
'size_t',
|
13
|
+
'unsigned int',
|
14
|
+
'uint',
|
15
|
+
'int',
|
16
|
+
'size_t',
|
17
|
+
'unsigned int',
|
18
|
+
'uint',
|
19
|
+
'bool',
|
20
|
+
'uchar',
|
21
|
+
'void',
|
22
|
+
'int64'
|
23
|
+
]
|
24
|
+
|
25
|
+
STRING_TYPES = [
|
26
|
+
'char',
|
27
|
+
]
|
28
|
+
|
29
|
+
NATIVE_C_TYPES = NUMBER_TYPES + STRING_TYPES
|
30
|
+
|
31
|
+
class << self
|
32
|
+
|
33
|
+
# This is used to resolve overloaded functions
|
34
|
+
def type_group(arg)
|
35
|
+
# exact same type
|
36
|
+
if NATIVE_C_TYPES.include?(arg.type)
|
37
|
+
if NUMBER_TYPES.include?(arg.type)
|
38
|
+
# number synonym
|
39
|
+
arg.is_pointer? ? :number_ptr : :number
|
40
|
+
else
|
41
|
+
# string synonym
|
42
|
+
raise "Not implemented yet"
|
43
|
+
# :string
|
44
|
+
end
|
45
|
+
else
|
46
|
+
# custom class / type
|
47
|
+
arg.id_name
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# group is a list of functions, index = argument index
|
52
|
+
def decision_tree(group)
|
53
|
+
hash = {}
|
54
|
+
group.each do |function|
|
55
|
+
insert_by_type(hash, function)
|
56
|
+
end
|
57
|
+
hash
|
58
|
+
end
|
59
|
+
|
60
|
+
# Insert a function into the hash, using the argument at the given
|
61
|
+
# index to filter
|
62
|
+
def insert_by_type(hash, function, index = 0)
|
63
|
+
arg = function.arguments[index]
|
64
|
+
type = arg ? type_group(arg) : nil
|
65
|
+
slot = hash[type]
|
66
|
+
if slot.nil?
|
67
|
+
hash[type] = function
|
68
|
+
elsif slot.kind_of?(Hash)
|
69
|
+
insert_by_type(slot, function, index + 1)
|
70
|
+
elsif type.nil?
|
71
|
+
# ignore
|
72
|
+
|
73
|
+
# TODO: log level
|
74
|
+
# puts "Cannot filter functions #{function.source}"
|
75
|
+
else
|
76
|
+
h = {}
|
77
|
+
insert_by_type(h, slot, index + 1)
|
78
|
+
insert_by_type(h, function, index + 1)
|
79
|
+
hash[type] = h
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def initialize(function, xml, arg_pos = nil)
|
85
|
+
@function, @xml, @argument_position = function, xml, arg_pos
|
86
|
+
parse_xml
|
87
|
+
end
|
88
|
+
|
89
|
+
def signature
|
90
|
+
"#{is_const? ? 'const ' : ''}#{type}#{is_ref? ? '&' : ''}"
|
91
|
+
end
|
92
|
+
|
93
|
+
def full_type
|
94
|
+
container = function.parent
|
95
|
+
if container.kind_of?(Klass)
|
96
|
+
container = container.parent
|
97
|
+
end
|
98
|
+
container ? "#{container.name}::#{type}" : type
|
99
|
+
end
|
100
|
+
|
101
|
+
def id_name
|
102
|
+
full_type.gsub('::', '.')
|
103
|
+
end
|
104
|
+
|
105
|
+
alias inspect signature
|
106
|
+
|
107
|
+
def is_ref?
|
108
|
+
@ref
|
109
|
+
end
|
110
|
+
|
111
|
+
def is_pointer?
|
112
|
+
!@pointer.nil?
|
113
|
+
end
|
114
|
+
|
115
|
+
def is_const?
|
116
|
+
@const
|
117
|
+
end
|
118
|
+
|
119
|
+
def has_default?
|
120
|
+
!@default.nil?
|
121
|
+
end
|
122
|
+
|
123
|
+
def is_return_value?
|
124
|
+
@is_return_value
|
125
|
+
end
|
126
|
+
|
127
|
+
def is_native?
|
128
|
+
NATIVE_C_TYPES.include?(type)
|
129
|
+
end
|
130
|
+
|
131
|
+
def type
|
132
|
+
resolve_type if @template_params
|
133
|
+
@type
|
134
|
+
end
|
135
|
+
|
136
|
+
def vararg?
|
137
|
+
@type == '...'
|
138
|
+
end
|
139
|
+
|
140
|
+
def create_type
|
141
|
+
resolve_type if @template_params
|
142
|
+
(is_const? ? 'const ' : '') +
|
143
|
+
if (is_return_value? && !is_pointer?) || (is_native? && !is_pointer?)
|
144
|
+
"#{type} "
|
145
|
+
else
|
146
|
+
"#{type} *"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# this is for the cases where we have signatures like
|
151
|
+
# HuMoments(double moments[7])
|
152
|
+
def array_suffix
|
153
|
+
@array_suffix
|
154
|
+
end
|
155
|
+
|
156
|
+
def in_call_type
|
157
|
+
(is_native? || is_pointer?) ? name : "*#{name}"
|
158
|
+
end
|
159
|
+
|
160
|
+
private
|
161
|
+
def parse_xml
|
162
|
+
if type = (@xml/'type').first
|
163
|
+
# param
|
164
|
+
set_type(type)
|
165
|
+
|
166
|
+
@name = unescape((@xml/'declname').innerHTML)
|
167
|
+
if @name == ''
|
168
|
+
@name = "arg#{@argument_position}"
|
169
|
+
elsif @name == @function.name
|
170
|
+
@name = "arg_#{@name}"
|
171
|
+
end
|
172
|
+
|
173
|
+
if ref = (@xml/'defval/ref').first
|
174
|
+
ref.swap(ref.innerHTML)
|
175
|
+
end
|
176
|
+
@default = (@xml/'defval') ? unescape((@xml/'defval').innerHTML) : nil
|
177
|
+
@default = nil if @default == ''
|
178
|
+
expand_default_type if @default
|
179
|
+
else
|
180
|
+
# return value
|
181
|
+
@is_return_value = true
|
182
|
+
set_type(@xml/'')
|
183
|
+
end
|
184
|
+
|
185
|
+
if array = (@xml/'array').first
|
186
|
+
@array_suffix = array.innerHTML
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def set_type(type)
|
191
|
+
# <type>const <ref refid="classcv_1_1_point__" kindref="compound">Point_</ref>< int > &</type>
|
192
|
+
if ref = (type/'ref').first
|
193
|
+
@refid = ref[:refid]
|
194
|
+
ref.swap(ref.innerHTML)
|
195
|
+
end
|
196
|
+
|
197
|
+
type = type.innerHTML
|
198
|
+
|
199
|
+
# Strip CV_EXPORT .....
|
200
|
+
if type =~ /^([^ ]+)\s+([a-zA-Z_]+.*)$/
|
201
|
+
if $1 == 'const'
|
202
|
+
@const = true
|
203
|
+
end
|
204
|
+
type = $2
|
205
|
+
end
|
206
|
+
|
207
|
+
# Strip const .....
|
208
|
+
if type =~ /^const\s+(.+)$/
|
209
|
+
type = $1.strip
|
210
|
+
@const = true
|
211
|
+
end
|
212
|
+
|
213
|
+
# Strip ..... &
|
214
|
+
if type =~ /^(.+)&$/
|
215
|
+
type = $1.strip
|
216
|
+
@ref = true
|
217
|
+
end
|
218
|
+
|
219
|
+
# Strip ..... *
|
220
|
+
if type =~ /^(.+)(\*+)\s*$/
|
221
|
+
type = $1.strip
|
222
|
+
@pointer = $2
|
223
|
+
end
|
224
|
+
|
225
|
+
# Strip .....< ... >
|
226
|
+
if type =~ /^(.+)\s*<\s*(.+)\s*>/
|
227
|
+
type = $1.strip
|
228
|
+
@template_params = $2.split(',').map(&:strip)
|
229
|
+
end
|
230
|
+
@type = type
|
231
|
+
end
|
232
|
+
|
233
|
+
# Replace something like AUTO_STEP by cv::Mat::AUTO_STEP
|
234
|
+
def expand_default_type
|
235
|
+
container = @function.parent
|
236
|
+
if container && container.enums.include?(@default)
|
237
|
+
@default = "#{container.full_type}::#{@default}"
|
238
|
+
elsif container = container.parent && container.enums.include?(@default)
|
239
|
+
@default = "#{container.full_type}::#{@default}"
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
def resolve_type
|
244
|
+
if container = @function.parent
|
245
|
+
if container.kind_of?(Klass)
|
246
|
+
container = container.parent
|
247
|
+
end
|
248
|
+
if container && tclass = container.template_class(@type)
|
249
|
+
if instanciation = tclass.instanciations[@template_params]
|
250
|
+
@type = instanciation.name
|
251
|
+
else
|
252
|
+
Dub.logger.warn "Could not resolve templated type #{@type}<#{@template_params.join(', ')}>"
|
253
|
+
end
|
254
|
+
else
|
255
|
+
Dub.logger.warn "Could not find class for type #{@type}<#{@template_params.join(', ')}>"
|
256
|
+
end
|
257
|
+
end
|
258
|
+
@template_params = nil
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end # Namespace
|