dub 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/.gitignore +8 -0
  2. data/History.txt +5 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +53 -0
  5. data/Rakefile +58 -0
  6. data/dub.gemspec +194 -0
  7. data/lib/dub/argument.rb +261 -0
  8. data/lib/dub/entities_unescape.rb +16 -0
  9. data/lib/dub/function.rb +111 -0
  10. data/lib/dub/function_group.rb +74 -0
  11. data/lib/dub/generator.rb +15 -0
  12. data/lib/dub/group.rb +10 -0
  13. data/lib/dub/klass.rb +231 -0
  14. data/lib/dub/lua/class.cpp.erb +75 -0
  15. data/lib/dub/lua/class_gen.rb +78 -0
  16. data/lib/dub/lua/function.cpp.erb +4 -0
  17. data/lib/dub/lua/function_gen.rb +223 -0
  18. data/lib/dub/lua/group.cpp.erb +10 -0
  19. data/lib/dub/lua/lua_cpp_helper.h +141 -0
  20. data/lib/dub/lua/namespace.cpp.erb +35 -0
  21. data/lib/dub/lua/namespace_gen.rb +86 -0
  22. data/lib/dub/lua.rb +24 -0
  23. data/lib/dub/member_extraction.rb +88 -0
  24. data/lib/dub/namespace.rb +276 -0
  25. data/lib/dub/parser.rb +46 -0
  26. data/lib/dub/templates/lua_template.erb +21 -0
  27. data/lib/dub/version.rb +3 -0
  28. data/lib/dub.rb +26 -0
  29. data/test/argument_test.rb +423 -0
  30. data/test/fixtures/app/CMakeLists.txt +54 -0
  31. data/test/fixtures/app/Doxyfile +1600 -0
  32. data/test/fixtures/app/bindings/all_lua.cpp +299 -0
  33. data/test/fixtures/app/include/matrix.h +123 -0
  34. data/test/fixtures/app/make_lua_bindings.rb +13 -0
  35. data/test/fixtures/app/vendor/lua/CMakeLists.txt +25 -0
  36. data/test/fixtures/app/vendor/lua/COPYRIGHT +34 -0
  37. data/test/fixtures/app/vendor/lua/HISTORY +183 -0
  38. data/test/fixtures/app/vendor/lua/INSTALL +99 -0
  39. data/test/fixtures/app/vendor/lua/Makefile +183 -0
  40. data/test/fixtures/app/vendor/lua/README +37 -0
  41. data/test/fixtures/app/vendor/lua/lapi.c +1080 -0
  42. data/test/fixtures/app/vendor/lua/lapi.h +16 -0
  43. data/test/fixtures/app/vendor/lua/lauxlib.c +653 -0
  44. data/test/fixtures/app/vendor/lua/lauxlib.h +174 -0
  45. data/test/fixtures/app/vendor/lua/lbaselib.c +643 -0
  46. data/test/fixtures/app/vendor/lua/lcode.c +839 -0
  47. data/test/fixtures/app/vendor/lua/lcode.h +76 -0
  48. data/test/fixtures/app/vendor/lua/ldblib.c +397 -0
  49. data/test/fixtures/app/vendor/lua/ldebug.c +622 -0
  50. data/test/fixtures/app/vendor/lua/ldebug.h +33 -0
  51. data/test/fixtures/app/vendor/lua/ldo.c +516 -0
  52. data/test/fixtures/app/vendor/lua/ldo.h +57 -0
  53. data/test/fixtures/app/vendor/lua/ldump.c +164 -0
  54. data/test/fixtures/app/vendor/lua/lfunc.c +174 -0
  55. data/test/fixtures/app/vendor/lua/lfunc.h +34 -0
  56. data/test/fixtures/app/vendor/lua/lgc.c +711 -0
  57. data/test/fixtures/app/vendor/lua/lgc.h +110 -0
  58. data/test/fixtures/app/vendor/lua/liblua.a +0 -0
  59. data/test/fixtures/app/vendor/lua/linit.c +38 -0
  60. data/test/fixtures/app/vendor/lua/liolib.c +532 -0
  61. data/test/fixtures/app/vendor/lua/llex.c +461 -0
  62. data/test/fixtures/app/vendor/lua/llex.h +81 -0
  63. data/test/fixtures/app/vendor/lua/llimits.h +128 -0
  64. data/test/fixtures/app/vendor/lua/lmathlib.c +263 -0
  65. data/test/fixtures/app/vendor/lua/lmem.c +86 -0
  66. data/test/fixtures/app/vendor/lua/lmem.h +49 -0
  67. data/test/fixtures/app/vendor/lua/loadlib.c +664 -0
  68. data/test/fixtures/app/vendor/lua/lobject.c +214 -0
  69. data/test/fixtures/app/vendor/lua/lobject.h +381 -0
  70. data/test/fixtures/app/vendor/lua/lopcodes.c +102 -0
  71. data/test/fixtures/app/vendor/lua/lopcodes.h +268 -0
  72. data/test/fixtures/app/vendor/lua/loslib.c +244 -0
  73. data/test/fixtures/app/vendor/lua/lparser.c +1337 -0
  74. data/test/fixtures/app/vendor/lua/lparser.h +82 -0
  75. data/test/fixtures/app/vendor/lua/lstate.c +214 -0
  76. data/test/fixtures/app/vendor/lua/lstate.h +168 -0
  77. data/test/fixtures/app/vendor/lua/lstring.c +111 -0
  78. data/test/fixtures/app/vendor/lua/lstring.h +31 -0
  79. data/test/fixtures/app/vendor/lua/lstrlib.c +868 -0
  80. data/test/fixtures/app/vendor/lua/ltable.c +588 -0
  81. data/test/fixtures/app/vendor/lua/ltable.h +40 -0
  82. data/test/fixtures/app/vendor/lua/ltablib.c +278 -0
  83. data/test/fixtures/app/vendor/lua/ltm.c +75 -0
  84. data/test/fixtures/app/vendor/lua/ltm.h +54 -0
  85. data/test/fixtures/app/vendor/lua/lua.c +695 -0
  86. data/test/fixtures/app/vendor/lua/lua.h +385 -0
  87. data/test/fixtures/app/vendor/lua/lua_dub_helper.h +77 -0
  88. data/test/fixtures/app/vendor/lua/luac +0 -0
  89. data/test/fixtures/app/vendor/lua/luac.c +200 -0
  90. data/test/fixtures/app/vendor/lua/luaconf.h +762 -0
  91. data/test/fixtures/app/vendor/lua/lualib.h +53 -0
  92. data/test/fixtures/app/vendor/lua/lundump.c +223 -0
  93. data/test/fixtures/app/vendor/lua/lundump.h +36 -0
  94. data/test/fixtures/app/vendor/lua/lvm.c +765 -0
  95. data/test/fixtures/app/vendor/lua/lvm.h +36 -0
  96. data/test/fixtures/app/vendor/lua/lzio.c +82 -0
  97. data/test/fixtures/app/vendor/lua/lzio.h +67 -0
  98. data/test/fixtures/app/vendor/lua/matrix.h +102 -0
  99. data/test/fixtures/app/vendor/lua/print.c +227 -0
  100. data/test/fixtures/app/vendor/lua/test/README +26 -0
  101. data/test/fixtures/app/vendor/lua/test/bisect.lua +27 -0
  102. data/test/fixtures/app/vendor/lua/test/cf.lua +16 -0
  103. data/test/fixtures/app/vendor/lua/test/echo.lua +5 -0
  104. data/test/fixtures/app/vendor/lua/test/env.lua +7 -0
  105. data/test/fixtures/app/vendor/lua/test/factorial.lua +32 -0
  106. data/test/fixtures/app/vendor/lua/test/fib.lua +40 -0
  107. data/test/fixtures/app/vendor/lua/test/fibfor.lua +13 -0
  108. data/test/fixtures/app/vendor/lua/test/globals.lua +13 -0
  109. data/test/fixtures/app/vendor/lua/test/hello.lua +3 -0
  110. data/test/fixtures/app/vendor/lua/test/life.lua +111 -0
  111. data/test/fixtures/app/vendor/lua/test/luac.lua +7 -0
  112. data/test/fixtures/app/vendor/lua/test/printf.lua +7 -0
  113. data/test/fixtures/app/vendor/lua/test/readonly.lua +12 -0
  114. data/test/fixtures/app/vendor/lua/test/sieve.lua +29 -0
  115. data/test/fixtures/app/vendor/lua/test/sort.lua +66 -0
  116. data/test/fixtures/app/vendor/lua/test/table.lua +12 -0
  117. data/test/fixtures/app/vendor/lua/test/trace-calls.lua +32 -0
  118. data/test/fixtures/app/vendor/lua/test/trace-globals.lua +38 -0
  119. data/test/fixtures/app/vendor/lua/test/xd.lua +14 -0
  120. data/test/fixtures/app/xml/classdub_1_1_matrix.xml +239 -0
  121. data/test/fixtures/app/xml/classdub_1_1_t_mat.xml +233 -0
  122. data/test/fixtures/app/xml/combine.xslt +15 -0
  123. data/test/fixtures/app/xml/compound.xsd +814 -0
  124. data/test/fixtures/app/xml/dir_53661a2bdeb1d55e60581a7e15deb763.xml +12 -0
  125. data/test/fixtures/app/xml/index.xml +42 -0
  126. data/test/fixtures/app/xml/index.xsd +66 -0
  127. data/test/fixtures/app/xml/matrix_8h.xml +149 -0
  128. data/test/fixtures/app/xml/namespacedub.xml +41 -0
  129. data/test/fixtures/classcv_1_1_mat.xml +1996 -0
  130. data/test/fixtures/classcv_1_1_point__.xml +341 -0
  131. data/test/fixtures/classcv_1_1_size__.xml +270 -0
  132. data/test/fixtures/group___magic_type.xml +406 -0
  133. data/test/fixtures/namespacecv.xml +12659 -0
  134. data/test/function_group_test.rb +15 -0
  135. data/test/function_test.rb +252 -0
  136. data/test/group_test.rb +155 -0
  137. data/test/helper.rb +34 -0
  138. data/test/klass_test.rb +297 -0
  139. data/test/lua_function_gen_test.rb +179 -0
  140. data/test/namespace_test.rb +220 -0
  141. data/test/parser_test.rb +36 -0
  142. metadata +216 -0
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ .DS_Store
2
+ *.o
3
+ *.a
4
+ *.so
5
+ build
6
+ test/fixtures/app/vendor/lua/lua
7
+ *.gem
8
+ test/fixtures/app/html
data/History.txt ADDED
@@ -0,0 +1,5 @@
1
+ == 0.5.0 2010-03-03
2
+
3
+ * 1 major enhancement
4
+ * initial release and tested with OpenCV bindings for Lua
5
+
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
+
@@ -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>&lt; int &gt; &amp;</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 =~ /^(.+)&amp;$/
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*&lt;\s*(.+)\s*&gt;/
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
@@ -0,0 +1,16 @@
1
+ module Dub
2
+ module EntitiesUnescape
3
+ ENTITIES = {
4
+ '&amp;' => '&',
5
+ '&lt;' => '<',
6
+ '&gt;' => '>'
7
+ }
8
+
9
+ def unescape(str)
10
+ ENTITIES.each do |k,v|
11
+ str.gsub!(k, v)
12
+ end
13
+ str
14
+ end
15
+ end
16
+ end