dub 0.2.2 → 0.6.6

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.

Potentially problematic release.


This version of dub might be problematic. Click here for more details.

Files changed (267) hide show
  1. data/.gitignore +8 -0
  2. data/History.txt +53 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +67 -0
  5. data/Rakefile +59 -0
  6. data/dub.gemspec +201 -0
  7. data/lib/dub/argument.rb +275 -0
  8. data/lib/dub/entities_unescape.rb +9 -0
  9. data/lib/dub/function.rb +163 -0
  10. data/lib/dub/function_group.rb +72 -0
  11. data/lib/dub/generator.rb +15 -0
  12. data/lib/dub/group.rb +24 -0
  13. data/lib/dub/klass.rb +255 -0
  14. data/lib/dub/lua/class.cpp.erb +84 -0
  15. data/lib/dub/lua/class_gen.rb +97 -0
  16. data/lib/dub/lua/function.cpp.erb +18 -0
  17. data/lib/dub/lua/function_gen.rb +265 -0
  18. data/lib/dub/lua/group.cpp.erb +9 -0
  19. data/lib/dub/lua/lua_cpp_helper.h +141 -0
  20. data/lib/dub/lua/namespace.cpp.erb +40 -0
  21. data/lib/dub/lua/namespace_gen.rb +88 -0
  22. data/lib/dub/lua.rb +24 -0
  23. data/lib/dub/member_extraction.rb +92 -0
  24. data/lib/dub/namespace.rb +277 -0
  25. data/lib/dub/opts_parser.rb +30 -0
  26. data/lib/dub/parser.rb +46 -0
  27. data/lib/dub/templates/lua_template.erb +21 -0
  28. data/lib/dub/version.rb +3 -0
  29. data/lib/dub.rb +24 -20
  30. data/test/argument_test.rb +547 -0
  31. data/test/fixtures/app/CMakeLists.txt +54 -0
  32. data/test/fixtures/app/Doxyfile +1600 -0
  33. data/test/fixtures/app/bindings/all_lua.cpp +299 -0
  34. data/test/fixtures/app/include/matrix.h +162 -0
  35. data/test/fixtures/app/make_lua_bindings.rb +13 -0
  36. data/test/fixtures/app/vendor/lua/CMakeLists.txt +25 -0
  37. data/test/fixtures/app/vendor/lua/COPYRIGHT +34 -0
  38. data/test/fixtures/app/vendor/lua/HISTORY +183 -0
  39. data/test/fixtures/app/vendor/lua/INSTALL +99 -0
  40. data/test/fixtures/app/vendor/lua/Makefile +183 -0
  41. data/test/fixtures/app/vendor/lua/README +37 -0
  42. data/test/fixtures/app/vendor/lua/lapi.c +1080 -0
  43. data/test/fixtures/app/vendor/lua/lapi.h +16 -0
  44. data/test/fixtures/app/vendor/lua/lauxlib.c +653 -0
  45. data/test/fixtures/app/vendor/lua/lauxlib.h +174 -0
  46. data/test/fixtures/app/vendor/lua/lbaselib.c +643 -0
  47. data/test/fixtures/app/vendor/lua/lcode.c +839 -0
  48. data/test/fixtures/app/vendor/lua/lcode.h +76 -0
  49. data/test/fixtures/app/vendor/lua/ldblib.c +397 -0
  50. data/test/fixtures/app/vendor/lua/ldebug.c +622 -0
  51. data/test/fixtures/app/vendor/lua/ldebug.h +33 -0
  52. data/test/fixtures/app/vendor/lua/ldo.c +516 -0
  53. data/test/fixtures/app/vendor/lua/ldo.h +57 -0
  54. data/test/fixtures/app/vendor/lua/ldump.c +164 -0
  55. data/test/fixtures/app/vendor/lua/lfunc.c +174 -0
  56. data/test/fixtures/app/vendor/lua/lfunc.h +34 -0
  57. data/test/fixtures/app/vendor/lua/lgc.c +711 -0
  58. data/test/fixtures/app/vendor/lua/lgc.h +110 -0
  59. data/test/fixtures/app/vendor/lua/liblua.a +0 -0
  60. data/test/fixtures/app/vendor/lua/linit.c +38 -0
  61. data/test/fixtures/app/vendor/lua/liolib.c +532 -0
  62. data/test/fixtures/app/vendor/lua/llex.c +461 -0
  63. data/test/fixtures/app/vendor/lua/llex.h +81 -0
  64. data/test/fixtures/app/vendor/lua/llimits.h +128 -0
  65. data/test/fixtures/app/vendor/lua/lmathlib.c +263 -0
  66. data/test/fixtures/app/vendor/lua/lmem.c +86 -0
  67. data/test/fixtures/app/vendor/lua/lmem.h +49 -0
  68. data/test/fixtures/app/vendor/lua/loadlib.c +664 -0
  69. data/test/fixtures/app/vendor/lua/lobject.c +214 -0
  70. data/test/fixtures/app/vendor/lua/lobject.h +381 -0
  71. data/test/fixtures/app/vendor/lua/lopcodes.c +102 -0
  72. data/test/fixtures/app/vendor/lua/lopcodes.h +268 -0
  73. data/test/fixtures/app/vendor/lua/loslib.c +244 -0
  74. data/test/fixtures/app/vendor/lua/lparser.c +1337 -0
  75. data/test/fixtures/app/vendor/lua/lparser.h +82 -0
  76. data/test/fixtures/app/vendor/lua/lstate.c +214 -0
  77. data/test/fixtures/app/vendor/lua/lstate.h +168 -0
  78. data/test/fixtures/app/vendor/lua/lstring.c +111 -0
  79. data/test/fixtures/app/vendor/lua/lstring.h +31 -0
  80. data/test/fixtures/app/vendor/lua/lstrlib.c +868 -0
  81. data/test/fixtures/app/vendor/lua/ltable.c +588 -0
  82. data/test/fixtures/app/vendor/lua/ltable.h +40 -0
  83. data/test/fixtures/app/vendor/lua/ltablib.c +278 -0
  84. data/test/fixtures/app/vendor/lua/ltm.c +75 -0
  85. data/test/fixtures/app/vendor/lua/ltm.h +54 -0
  86. data/test/fixtures/app/vendor/lua/lua.c +695 -0
  87. data/test/fixtures/app/vendor/lua/lua.h +385 -0
  88. data/test/fixtures/app/vendor/lua/lua_dub_helper.h +77 -0
  89. data/test/fixtures/app/vendor/lua/luac +0 -0
  90. data/test/fixtures/app/vendor/lua/luac.c +200 -0
  91. data/test/fixtures/app/vendor/lua/luaconf.h +762 -0
  92. data/test/fixtures/app/vendor/lua/lualib.h +53 -0
  93. data/test/fixtures/app/vendor/lua/lundump.c +223 -0
  94. data/test/fixtures/app/vendor/lua/lundump.h +36 -0
  95. data/test/fixtures/app/vendor/lua/lvm.c +765 -0
  96. data/test/fixtures/app/vendor/lua/lvm.h +36 -0
  97. data/test/fixtures/app/vendor/lua/lzio.c +82 -0
  98. data/test/fixtures/app/vendor/lua/lzio.h +67 -0
  99. data/test/fixtures/app/vendor/lua/matrix.h +102 -0
  100. data/test/fixtures/app/vendor/lua/print.c +227 -0
  101. data/test/fixtures/app/vendor/lua/test/README +26 -0
  102. data/test/fixtures/app/vendor/lua/test/bisect.lua +27 -0
  103. data/test/fixtures/app/vendor/lua/test/cf.lua +16 -0
  104. data/test/fixtures/app/vendor/lua/test/echo.lua +5 -0
  105. data/test/fixtures/app/vendor/lua/test/env.lua +7 -0
  106. data/test/fixtures/app/vendor/lua/test/factorial.lua +32 -0
  107. data/test/fixtures/app/vendor/lua/test/fib.lua +40 -0
  108. data/test/fixtures/app/vendor/lua/test/fibfor.lua +13 -0
  109. data/test/fixtures/app/vendor/lua/test/globals.lua +13 -0
  110. data/test/fixtures/app/vendor/lua/test/hello.lua +3 -0
  111. data/test/fixtures/app/vendor/lua/test/life.lua +111 -0
  112. data/test/fixtures/app/vendor/lua/test/luac.lua +7 -0
  113. data/test/fixtures/app/vendor/lua/test/printf.lua +7 -0
  114. data/test/fixtures/app/vendor/lua/test/readonly.lua +12 -0
  115. data/test/fixtures/app/vendor/lua/test/sieve.lua +29 -0
  116. data/test/fixtures/app/vendor/lua/test/sort.lua +66 -0
  117. data/test/fixtures/app/vendor/lua/test/table.lua +12 -0
  118. data/test/fixtures/app/vendor/lua/test/trace-calls.lua +32 -0
  119. data/test/fixtures/app/vendor/lua/test/trace-globals.lua +38 -0
  120. data/test/fixtures/app/vendor/lua/test/xd.lua +14 -0
  121. data/test/fixtures/app/xml/classdub_1_1_matrix.xml +341 -0
  122. data/test/fixtures/app/xml/classdub_1_1_t_mat.xml +252 -0
  123. data/test/fixtures/app/xml/combine.xslt +15 -0
  124. data/test/fixtures/app/xml/compound.xsd +814 -0
  125. data/test/fixtures/app/xml/dir_53661a2bdeb1d55e60581a7e15deb763.xml +12 -0
  126. data/test/fixtures/app/xml/index.xml +48 -0
  127. data/test/fixtures/app/xml/index.xsd +66 -0
  128. data/test/fixtures/app/xml/matrix_8h.xml +179 -0
  129. data/test/fixtures/app/xml/namespacedub.xml +41 -0
  130. data/test/fixtures/classcv_1_1_mat.xml +1996 -0
  131. data/test/fixtures/classcv_1_1_point__.xml +341 -0
  132. data/test/fixtures/classcv_1_1_scalar__.xml +269 -0
  133. data/test/fixtures/classcv_1_1_size__.xml +270 -0
  134. data/test/fixtures/dummy_class.cpp.erb +1 -0
  135. data/test/fixtures/dummy_function.cpp.erb +1 -0
  136. data/test/fixtures/group___magic_type.xml +406 -0
  137. data/test/fixtures/namespacecv.xml +12659 -0
  138. data/test/function_group_test.rb +24 -0
  139. data/test/function_test.rb +395 -0
  140. data/test/group_test.rb +155 -0
  141. data/test/helper.rb +34 -0
  142. data/test/klass_test.rb +422 -0
  143. data/test/lua_function_gen_test.rb +215 -0
  144. data/test/namespace_test.rb +220 -0
  145. data/test/parser_test.rb +36 -0
  146. metadata +232 -274
  147. checksums.yaml +0 -7
  148. data/lib/open_api_sdk/analytics.rb +0 -99
  149. data/lib/open_api_sdk/domains.rb +0 -353
  150. data/lib/open_api_sdk/dub.rb +0 -88
  151. data/lib/open_api_sdk/links.rb +0 -766
  152. data/lib/open_api_sdk/metatags.rb +0 -54
  153. data/lib/open_api_sdk/models/operations/bulkcreatelinks_response.rb +0 -60
  154. data/lib/open_api_sdk/models/operations/bulkupdatelinks_requestbody.rb +0 -27
  155. data/lib/open_api_sdk/models/operations/bulkupdatelinks_response.rb +0 -60
  156. data/lib/open_api_sdk/models/operations/color.rb +0 -24
  157. data/lib/open_api_sdk/models/operations/createdomain_requestbody.rb +0 -33
  158. data/lib/open_api_sdk/models/operations/createdomain_response.rb +0 -60
  159. data/lib/open_api_sdk/models/operations/createlink_requestbody.rb +0 -95
  160. data/lib/open_api_sdk/models/operations/createlink_response.rb +0 -60
  161. data/lib/open_api_sdk/models/operations/createtag_requestbody.rb +0 -32
  162. data/lib/open_api_sdk/models/operations/createtag_response.rb +0 -60
  163. data/lib/open_api_sdk/models/operations/data.rb +0 -83
  164. data/lib/open_api_sdk/models/operations/deletedomain_request.rb +0 -24
  165. data/lib/open_api_sdk/models/operations/deletedomain_response.rb +0 -60
  166. data/lib/open_api_sdk/models/operations/deletedomain_responsebody.rb +0 -24
  167. data/lib/open_api_sdk/models/operations/deletelink_request.rb +0 -24
  168. data/lib/open_api_sdk/models/operations/deletelink_response.rb +0 -60
  169. data/lib/open_api_sdk/models/operations/deletelink_responsebody.rb +0 -24
  170. data/lib/open_api_sdk/models/operations/event.rb +0 -21
  171. data/lib/open_api_sdk/models/operations/getlinkinfo_request.rb +0 -33
  172. data/lib/open_api_sdk/models/operations/getlinkinfo_response.rb +0 -60
  173. data/lib/open_api_sdk/models/operations/getlinks_request.rb +0 -51
  174. data/lib/open_api_sdk/models/operations/getlinks_response.rb +0 -60
  175. data/lib/open_api_sdk/models/operations/getlinkscount_request.rb +0 -48
  176. data/lib/open_api_sdk/models/operations/getlinkscount_response.rb +0 -60
  177. data/lib/open_api_sdk/models/operations/getmetatags_request.rb +0 -24
  178. data/lib/open_api_sdk/models/operations/getmetatags_response.rb +0 -33
  179. data/lib/open_api_sdk/models/operations/getmetatags_responsebody.rb +0 -30
  180. data/lib/open_api_sdk/models/operations/getqrcode_request.rb +0 -39
  181. data/lib/open_api_sdk/models/operations/getqrcode_response.rb +0 -60
  182. data/lib/open_api_sdk/models/operations/gettags_response.rb +0 -60
  183. data/lib/open_api_sdk/models/operations/getworkspace_request.rb +0 -24
  184. data/lib/open_api_sdk/models/operations/getworkspace_response.rb +0 -60
  185. data/lib/open_api_sdk/models/operations/groupby.rb +0 -28
  186. data/lib/open_api_sdk/models/operations/interval.rb +0 -25
  187. data/lib/open_api_sdk/models/operations/level.rb +0 -21
  188. data/lib/open_api_sdk/models/operations/listdomains_response.rb +0 -60
  189. data/lib/open_api_sdk/models/operations/paymentprocessor.rb +0 -20
  190. data/lib/open_api_sdk/models/operations/requestbody.rb +0 -95
  191. data/lib/open_api_sdk/models/operations/retrieveanalytics_request.rb +0 -81
  192. data/lib/open_api_sdk/models/operations/retrieveanalytics_response.rb +0 -60
  193. data/lib/open_api_sdk/models/operations/sort.rb +0 -20
  194. data/lib/open_api_sdk/models/operations/trackcustomer_requestbody.rb +0 -33
  195. data/lib/open_api_sdk/models/operations/trackcustomer_response.rb +0 -60
  196. data/lib/open_api_sdk/models/operations/trackcustomer_responsebody.rb +0 -33
  197. data/lib/open_api_sdk/models/operations/tracklead_requestbody.rb +0 -42
  198. data/lib/open_api_sdk/models/operations/tracklead_response.rb +0 -60
  199. data/lib/open_api_sdk/models/operations/tracklead_responsebody.rb +0 -42
  200. data/lib/open_api_sdk/models/operations/tracksale_requestbody.rb +0 -42
  201. data/lib/open_api_sdk/models/operations/tracksale_response.rb +0 -60
  202. data/lib/open_api_sdk/models/operations/tracksale_responsebody.rb +0 -42
  203. data/lib/open_api_sdk/models/operations/updatedomain_request.rb +0 -27
  204. data/lib/open_api_sdk/models/operations/updatedomain_requestbody.rb +0 -33
  205. data/lib/open_api_sdk/models/operations/updatedomain_response.rb +0 -60
  206. data/lib/open_api_sdk/models/operations/updatelink_request.rb +0 -27
  207. data/lib/open_api_sdk/models/operations/updatelink_requestbody.rb +0 -95
  208. data/lib/open_api_sdk/models/operations/updatelink_response.rb +0 -60
  209. data/lib/open_api_sdk/models/operations/updatetag_color.rb +0 -24
  210. data/lib/open_api_sdk/models/operations/updatetag_request.rb +0 -27
  211. data/lib/open_api_sdk/models/operations/updatetag_requestbody.rb +0 -32
  212. data/lib/open_api_sdk/models/operations/updatetag_response.rb +0 -60
  213. data/lib/open_api_sdk/models/operations/updateworkspace_request.rb +0 -27
  214. data/lib/open_api_sdk/models/operations/updateworkspace_requestbody.rb +0 -27
  215. data/lib/open_api_sdk/models/operations/updateworkspace_response.rb +0 -60
  216. data/lib/open_api_sdk/models/operations/upsertlink_requestbody.rb +0 -95
  217. data/lib/open_api_sdk/models/operations/upsertlink_response.rb +0 -60
  218. data/lib/open_api_sdk/models/operations.rb +0 -74
  219. data/lib/open_api_sdk/models/shared/badrequest.rb +0 -24
  220. data/lib/open_api_sdk/models/shared/code.rb +0 -18
  221. data/lib/open_api_sdk/models/shared/color.rb +0 -24
  222. data/lib/open_api_sdk/models/shared/conflict.rb +0 -24
  223. data/lib/open_api_sdk/models/shared/conflict_code.rb +0 -18
  224. data/lib/open_api_sdk/models/shared/conflict_error.rb +0 -30
  225. data/lib/open_api_sdk/models/shared/countrycode.rb +0 -267
  226. data/lib/open_api_sdk/models/shared/domains.rb +0 -27
  227. data/lib/open_api_sdk/models/shared/domainschema.rb +0 -48
  228. data/lib/open_api_sdk/models/shared/error.rb +0 -30
  229. data/lib/open_api_sdk/models/shared/forbidden.rb +0 -24
  230. data/lib/open_api_sdk/models/shared/forbidden_code.rb +0 -18
  231. data/lib/open_api_sdk/models/shared/forbidden_error.rb +0 -30
  232. data/lib/open_api_sdk/models/shared/geo.rb +0 -771
  233. data/lib/open_api_sdk/models/shared/internalservererror.rb +0 -24
  234. data/lib/open_api_sdk/models/shared/internalservererror_code.rb +0 -18
  235. data/lib/open_api_sdk/models/shared/internalservererror_error.rb +0 -30
  236. data/lib/open_api_sdk/models/shared/inviteexpired.rb +0 -24
  237. data/lib/open_api_sdk/models/shared/inviteexpired_code.rb +0 -18
  238. data/lib/open_api_sdk/models/shared/inviteexpired_error.rb +0 -30
  239. data/lib/open_api_sdk/models/shared/linkgeotargeting.rb +0 -771
  240. data/lib/open_api_sdk/models/shared/linkschema.rb +0 -142
  241. data/lib/open_api_sdk/models/shared/notfound.rb +0 -24
  242. data/lib/open_api_sdk/models/shared/notfound_code.rb +0 -18
  243. data/lib/open_api_sdk/models/shared/notfound_error.rb +0 -30
  244. data/lib/open_api_sdk/models/shared/plan.rb +0 -24
  245. data/lib/open_api_sdk/models/shared/ratelimitexceeded.rb +0 -24
  246. data/lib/open_api_sdk/models/shared/ratelimitexceeded_code.rb +0 -18
  247. data/lib/open_api_sdk/models/shared/ratelimitexceeded_error.rb +0 -30
  248. data/lib/open_api_sdk/models/shared/role.rb +0 -19
  249. data/lib/open_api_sdk/models/shared/security.rb +0 -24
  250. data/lib/open_api_sdk/models/shared/tagschema.rb +0 -30
  251. data/lib/open_api_sdk/models/shared/unauthorized.rb +0 -24
  252. data/lib/open_api_sdk/models/shared/unauthorized_code.rb +0 -18
  253. data/lib/open_api_sdk/models/shared/unauthorized_error.rb +0 -30
  254. data/lib/open_api_sdk/models/shared/unprocessableentity.rb +0 -24
  255. data/lib/open_api_sdk/models/shared/unprocessableentity_code.rb +0 -18
  256. data/lib/open_api_sdk/models/shared/unprocessableentity_error.rb +0 -30
  257. data/lib/open_api_sdk/models/shared/users.rb +0 -24
  258. data/lib/open_api_sdk/models/shared/workspaceschema.rb +0 -81
  259. data/lib/open_api_sdk/models/shared.rb +0 -49
  260. data/lib/open_api_sdk/qr_codes.rb +0 -97
  261. data/lib/open_api_sdk/sdkconfiguration.rb +0 -52
  262. data/lib/open_api_sdk/tags.rb +0 -272
  263. data/lib/open_api_sdk/track.rb +0 -276
  264. data/lib/open_api_sdk/utils/metadata_fields.rb +0 -150
  265. data/lib/open_api_sdk/utils/t.rb +0 -59
  266. data/lib/open_api_sdk/utils/utils.rb +0 -772
  267. data/lib/open_api_sdk/workspaces.rb +0 -192
@@ -0,0 +1,9 @@
1
+ require 'htmlentities'
2
+ module Dub
3
+ module EntitiesUnescape
4
+ Decoder = HTMLEntities.new
5
+ def unescape(str)
6
+ Decoder.decode(str)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,163 @@
1
+ require 'dub/argument'
2
+ require 'dub/entities_unescape'
3
+
4
+ module Dub
5
+ class Function
6
+ include Dub::EntitiesUnescape
7
+ attr_reader :arguments, :prefix, :overloaded_index, :return_value, :xml, :parent
8
+ attr_accessor :gen, :name, :is_constructor
9
+
10
+ def initialize(parent, name, xml, prefix = '', overloaded_index = nil)
11
+ @parent, @name = parent, name
12
+ @xml, @prefix, @overloaded_index = xml, prefix, overloaded_index
13
+ parse_xml
14
+ parse_template_params
15
+ end
16
+
17
+ def set_as_constructor
18
+ @return_value = Argument.new(self, (Hpricot::XML("<type>#{name} *</type>")/''))
19
+ @is_constructor = true
20
+ end
21
+
22
+ def bind(generator)
23
+ @gen = generator.function_generator
24
+ end
25
+
26
+ def to_s
27
+ generator.function(self)
28
+ end
29
+
30
+ def generator
31
+ @gen || (@parent && @parent.function_generator)
32
+ end
33
+
34
+ def klass
35
+ @parent.kind_of?(Klass) ? @parent : nil
36
+ end
37
+
38
+ def member_method?
39
+ !klass.nil?
40
+ end
41
+
42
+ def constructor?
43
+ @is_constructor
44
+ end
45
+
46
+ def static?
47
+ @is_static
48
+ end
49
+
50
+ alias gen generator
51
+
52
+ def name=(n)
53
+ @name = n
54
+ if constructor?
55
+ @return_value.type = n
56
+ end
57
+ end
58
+
59
+ def call_name
60
+ if klass
61
+ static? ? "#{klass.name}::#{name}" : name
62
+ else
63
+ name
64
+ end
65
+ end
66
+
67
+ def id_name
68
+ @parent ? "#{@parent.id_name}.#{name}" : name
69
+ end
70
+
71
+ def source
72
+ loc = (@xml/'location').first.attributes
73
+ "#{loc['file'].split('/')[-3..-1].join('/')}:#{loc['line']}"
74
+ end
75
+
76
+ def original_signature
77
+ unescape "#{(@xml/'definition').innerHTML}#{(@xml/'argsstring').innerHTML}"
78
+ end
79
+
80
+ def has_default_arguments?
81
+ return @has_defaults if defined?(@has_defaults)
82
+ @has_defaults = !@arguments.detect {|a| a.has_default? }.nil?
83
+ end
84
+
85
+ def has_array_arguments?
86
+ return @has_array_arguments if defined?(@has_array_arguments)
87
+ @has_array_arguments = !@arguments.detect {|a| a.array_suffix }.nil?
88
+ end
89
+
90
+ def has_class_pointer_arguments?
91
+ return @has_class_pointer_arguments if defined?(@has_class_pointer_arguments)
92
+ @has_class_pointer_arguments = !@arguments.detect {|a| !a.is_native? && a.is_pointer? }.nil?
93
+ end
94
+
95
+ def has_complex_arguments?
96
+ return @has_complex_arguments if defined?(@has_complex_arguments)
97
+ @has_complex_arguments = !(@arguments + [@return_value]).compact.detect {|a| a.complex? }.nil?
98
+ end
99
+
100
+ def vararg?
101
+ @arguments.last && @arguments.last.vararg?
102
+ end
103
+
104
+ def arg_is_list(list_position, count_position)
105
+ @arguments[list_position ].is_list = true
106
+ @arguments[count_position].is_list_count = true
107
+ end
108
+
109
+ def template?
110
+ !@template_params.nil?
111
+ end
112
+
113
+ def template_params
114
+ @template_params
115
+ end
116
+
117
+ def inspect
118
+ "#<Function #{@prefix}_#{@name}(#{@arguments.inspect[1..-2]})>"
119
+ end
120
+
121
+ def <=>(other)
122
+ name <=> other.name
123
+ end
124
+
125
+ # ====== these methods are alias to
126
+ # generator methods on this object
127
+
128
+ def method_name(overloaded_index = nil)
129
+ gen.method_name(self, overloaded_index)
130
+ end
131
+
132
+ # =================================
133
+
134
+ private
135
+ def parse_xml
136
+ @arguments = []
137
+
138
+ (@xml/'param').each_with_index do |arg, i|
139
+ @arguments << Argument.new(self, arg, i + 1)
140
+ end
141
+
142
+ raw_type = (@xml/'/type').innerHTML
143
+
144
+ if raw_type.strip == ''
145
+ # no return type
146
+ else
147
+ arg = Argument.new(self, (@xml/'/type'))
148
+ @return_value = arg unless arg.create_type =~ /void\s*$/
149
+ end
150
+
151
+ @is_static = @xml[:static] == 'yes'
152
+ end
153
+
154
+ def parse_template_params
155
+ template_params = (@xml/'/templateparamlist/param')
156
+ if !template_params.empty?
157
+ @template_params = template_params.map do |param|
158
+ (param/'/type').innerHTML.gsub(/^\s*(typename|class)\s+/,'')
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end # Namespace
@@ -0,0 +1,72 @@
1
+ module Dub
2
+ class FunctionGroup < Array
3
+ def initialize(parent, gen = nil)
4
+ @parent, @gen = parent, gen
5
+ end
6
+
7
+ def bind(generator)
8
+ self.gen = generator.function_generator
9
+ end
10
+
11
+ def generator
12
+ @gen || (@parent && @parent.function_generator)
13
+ end
14
+
15
+ def gen=(generator)
16
+ @gen = generator
17
+ @gen_members = nil
18
+ end
19
+
20
+ alias gen generator
21
+
22
+ def members
23
+ if self.generator
24
+ if @parent.generator
25
+ @gen_members ||= @parent.generator.members_list(self)
26
+ else
27
+ @gen_members ||= generator.namespace_generator.members_list(self)
28
+ end
29
+ else
30
+ self
31
+ end
32
+ end
33
+
34
+ def to_s
35
+ generator.group(self)
36
+ end
37
+
38
+ def method_name(overloaded_index = nil)
39
+ first.method_name(overloaded_index)
40
+ end
41
+
42
+ def map(&block)
43
+ list = self.class.new(@parent, @gen)
44
+ super(&block).each do |e|
45
+ list << e
46
+ end
47
+ list
48
+ end
49
+
50
+ def compact
51
+ list = self.class.new(@parent, @gen)
52
+ super.each do |e|
53
+ list << e
54
+ end
55
+ list
56
+ end
57
+
58
+ def overloaded_index
59
+ nil
60
+ end
61
+
62
+ def <=>(other)
63
+ name <=> other.name
64
+ end
65
+
66
+ private
67
+ def method_missing(method, *args)
68
+ first.send(method, *args)
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,15 @@
1
+ require 'dub/function'
2
+
3
+ module Dub
4
+ class Generator
5
+
6
+ def comment(func)
7
+ "/** #{func.original_signature}\n * #{func.source}\n */"
8
+ end
9
+
10
+ protected
11
+ def indent(str, indent)
12
+ str.gsub(/^/, ' ' * indent)
13
+ end
14
+ end # Generator
15
+ end # Dub
data/lib/dub/group.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'dub/namespace'
2
+
3
+ module Dub
4
+ class Group < Namespace
5
+ def parse_xml
6
+ super
7
+ parse_defines
8
+ end
9
+
10
+ def arg_is_list(argument_pos, count_pos)
11
+ each do |f|
12
+ f.arg_is_list(argument_pos, count_pos)
13
+ end
14
+ end
15
+
16
+ def members
17
+ if self.generator
18
+ @gen_members ||= self.generator.members_list(super, @ignores)
19
+ else
20
+ super
21
+ end
22
+ end
23
+ end
24
+ end
data/lib/dub/klass.rb ADDED
@@ -0,0 +1,255 @@
1
+ module Dub
2
+ module MemberExtraction
3
+ end
4
+ end
5
+ require 'dub/member_extraction'
6
+
7
+ module Dub
8
+ class Klass
9
+ include MemberExtraction
10
+ attr_reader :name, :xml, :prefix, :constructor, :alias_names, :enums, :parent, :instanciations
11
+ attr_accessor :opts
12
+
13
+ def initialize(parent, name, xml, prefix = '')
14
+ @parent, @name, @xml, @prefix = parent, name, xml, prefix
15
+
16
+ @alias_names = []
17
+ @enums = []
18
+ @ignores = []
19
+ @instanciations = {}
20
+ @opts = {}
21
+ parse_xml
22
+ end
23
+
24
+ def bind(generator)
25
+ self.gen = generator.class_generator
26
+ end
27
+
28
+ def gen=(generator)
29
+ @gen = generator
30
+ @gen_members = nil
31
+ end
32
+
33
+ def to_s
34
+ generator.klass(self)
35
+ end
36
+
37
+ def generator
38
+ @gen || (@parent && @parent.class_generator)
39
+ end
40
+
41
+ def function_generator
42
+ if generator = self.generator
43
+ generator.function_generator
44
+ else
45
+ nil
46
+ end
47
+ end
48
+
49
+ alias gen generator
50
+
51
+ def ignore(list)
52
+ list = [list].flatten
53
+ @ignores += list
54
+ @ignores.uniq!
55
+ @gen_members = nil
56
+ end
57
+
58
+ def members
59
+ if self.generator
60
+ @gen_members ||= self.generator.members_list(super, @ignores)
61
+ else
62
+ super
63
+ end
64
+ end
65
+
66
+ def <=>(other)
67
+ (name || "") <=> (other.name || "")
68
+ end
69
+
70
+ def [](name)
71
+ name.to_s == @name ? constructor : get_member(name.to_s)
72
+ end
73
+
74
+ def class_methods
75
+ []
76
+ end
77
+
78
+ def template?
79
+ !@template_params.nil?
80
+ end
81
+
82
+ def has_constants?
83
+ has_enums?
84
+ end
85
+
86
+ def has_enums?
87
+ !@enums.empty?
88
+ end
89
+
90
+ def template_params
91
+ @template_params
92
+ end
93
+
94
+ def class_with_params(template_params)
95
+ @instanciations[template_params]
96
+ end
97
+
98
+ def register_instanciation(template_params, klass)
99
+ @instanciations[template_params] = klass
100
+ end
101
+
102
+ def source
103
+ loc = (@xml/'location').first.attributes
104
+ "#{loc['file'].split('/')[-3..-1].join('/')}:#{loc['line']}"
105
+ end
106
+
107
+ def header
108
+ @opts[:header] ||= (@xml/'location').first.attributes['file'].split('/').last
109
+ end
110
+
111
+ def full_type
112
+ @parent ? "#{@parent.full_type}::#{name}" : name
113
+ end
114
+
115
+ def lib_name
116
+ @opts[:lib_name] || name
117
+ end
118
+
119
+ def id_name(name = self.name)
120
+ "#{prefix}.#{name}"
121
+ end
122
+
123
+ def destructor_name
124
+ "#{name}_destructor"
125
+ end
126
+
127
+ def tostring_name
128
+ "#{name}__tostring"
129
+ end
130
+
131
+ def constructor
132
+ if defined?(@constructor)
133
+ @constructor
134
+ else
135
+ self.members
136
+ @constructor ||= nil
137
+ end
138
+ @constructor
139
+ end
140
+
141
+ def names
142
+ [@name] + @alias_names
143
+ end
144
+
145
+ private
146
+ def parse_xml
147
+ parse_opts_hash
148
+ parse_enums
149
+ parse_members
150
+ parse_template_params
151
+ parse_instanciations
152
+ parse_alias_names
153
+ end
154
+
155
+ def parse_opts_hash
156
+ if hash = Dub::OptsParser.extract_hash(@xml)
157
+ if hash.kind_of?(Hash)
158
+ @opts.merge!(hash)
159
+ else
160
+ raise "Could not parse @dub parameters #{hash.inspect}"
161
+ end
162
+ end
163
+ end
164
+
165
+ def parse_enums
166
+ @enums = (@xml/"enumvalue/name").map{|e| e.innerHTML}
167
+ end
168
+
169
+ def parse_template_params
170
+ template_params = (@xml/'/templateparamlist/param')
171
+ if !template_params.empty?
172
+ @template_params = template_params.map do |param|
173
+ (param/'/type').innerHTML.gsub(/^\s*(typename|class)\s+/,'')
174
+ end
175
+ end
176
+ end
177
+
178
+ def parse_instanciations
179
+ (@xml/'instanciation').each do |klass|
180
+ name = (klass/'name').innerHTML
181
+ params = (klass/'param').map do |p|
182
+ p.innerHTML
183
+ end
184
+
185
+ @instanciations[params] = @parent[name]
186
+ end
187
+ end
188
+
189
+ def parse_alias_names
190
+ (@xml/'aliases/name').each do |name|
191
+ name = name.innerHTML
192
+ if name.size < @name.size
193
+ @alias_names << @name
194
+ change_name(name)
195
+ else
196
+ @alias_names << name
197
+ end
198
+
199
+ if @parent
200
+ @parent.register_alias(name, self)
201
+ end
202
+ end
203
+ end
204
+
205
+ def make_member(name, member, overloaded_index = nil)
206
+ return nil unless member[:prot] == 'public'
207
+ if names.include?(name)
208
+ # keep constructors out of members list
209
+ if @constructor.kind_of?(FunctionGroup)
210
+ constr = super
211
+ constr.name = @name # force key name
212
+ constr.set_as_constructor
213
+ @constructor << constr
214
+ elsif @constructor
215
+ constr = super
216
+ constr.name = @name
217
+ constr.set_as_constructor
218
+ list = Dub::FunctionGroup.new(self)
219
+ list << @constructor
220
+ list << constr
221
+ @constructor = list
222
+ else
223
+ @constructor = super
224
+ @constructor.set_as_constructor
225
+ @constructor.name = @name
226
+ end
227
+ nil
228
+ else
229
+ super
230
+ end
231
+ end
232
+
233
+ def change_name(new_name)
234
+ @name = new_name
235
+ if @constructor.kind_of?(Array)
236
+ @constructor.each do |c|
237
+ c.name = new_name
238
+ end
239
+ elsif @constructor
240
+ @constructor.name = new_name
241
+ end
242
+ end
243
+
244
+ def method_missing(met, *args)
245
+ if args.empty? && @opts.has_key?(met.to_sym)
246
+ @opts[met.to_sym]
247
+ elsif args.size == 1 && met.to_s =~ /^(.+)=$/
248
+ @opts[$1.to_sym] = args.first
249
+ else
250
+ super
251
+ end
252
+ end
253
+
254
+ end
255
+ end
@@ -0,0 +1,84 @@
1
+ #include "<%= @class.header %>"
2
+
3
+ #include "lua_cpp_helper.h"
4
+
5
+ <% if @class.prefix %>
6
+ using namespace <%= @class.prefix %>;
7
+ <% end %>
8
+
9
+ /* ============================ Constructors ====================== */
10
+
11
+ <%= @class.constructor %>
12
+
13
+ /* ============================ Destructor ====================== */
14
+
15
+ static int <%= @class.destructor_name %>(lua_State *L) {
16
+ <%= @class.name %> **userdata = (<%= @class.name %>**)luaL_checkudata(L, 1, <%= @class.id_name.inspect %>);
17
+ if (*userdata) delete *userdata;
18
+ *userdata = NULL;
19
+ return 0;
20
+ }
21
+
22
+ /* ============================ tostring ====================== */
23
+
24
+ static int <%= @class.tostring_name %>(lua_State *L) {
25
+ <%= @class.name %> **userdata = (<%= @class.name %>**)luaL_checkudata(L, 1, <%= @class.id_name.inspect %>);
26
+ <% if @class.opts[:string_format] %>
27
+ lua_pushfstring(L, "<<%= @class.id_name %>: %p <%= @class.string_format %>>", *userdata, <%= @class.string_args %>);
28
+ <% else %>
29
+ lua_pushfstring(L, "<<%= @class.id_name %>: %p>", *userdata);
30
+ <% end %>
31
+ return 1;
32
+ }
33
+
34
+ /* ============================ Member Methods ====================== */
35
+
36
+ <% if @class.members; @class.members.each do |function| %>
37
+ <%= function %>
38
+
39
+ <% end; end %>
40
+
41
+
42
+ /* ============================ Lua Registration ====================== */
43
+
44
+ static const struct luaL_Reg <%= @class.name %>_member_methods[] = {
45
+ <%= indent(method_registration, 2) %>,
46
+ {NULL, NULL},
47
+ };
48
+
49
+ static const struct luaL_Reg <%= @class.name %>_namespace_methods[] = {
50
+ <%= indent(namespace_methods_registration, 2) %>,
51
+ {NULL, NULL},
52
+ };
53
+
54
+ <% if @class.has_constants? %>
55
+ static const struct lua_constants_Reg <%= @class.name %>_namespace_constants[] = {
56
+ <%= indent(constants_registration, 2) %>,
57
+ {NULL, NULL},
58
+ };
59
+ <% end %>
60
+
61
+ #ifdef DUB_LUA_NO_OPEN
62
+ int luaload_<%= @class.prefix %>_<%= @class.lib_name %>(lua_State *L) {
63
+ #else
64
+ extern "C" int luaopen_<%= @class.prefix %>_<%= @class.lib_name %>(lua_State *L) {
65
+ #endif
66
+ // Create the metatable which will contain all the member methods
67
+ luaL_newmetatable(L, <%= @class.id_name.inspect %>);
68
+
69
+ // metatable.__index = metatable (find methods in the table itself)
70
+ lua_pushvalue(L, -1);
71
+ lua_setfield(L, -2, "__index");
72
+
73
+ // register member methods
74
+ luaL_register(L, NULL, <%= @class.name %>_member_methods);
75
+
76
+ // register class methods in a global namespace table
77
+ luaL_register(L, <%= @class.prefix.inspect %>, <%= @class.name %>_namespace_methods);
78
+
79
+ <% if @class.has_constants? %>
80
+ // register class enums
81
+ register_constants(L, <%= (@class.id_name + '_const').inspect %>, <%= @class.name %>_namespace_constants);
82
+ <% end %>
83
+ return 1;
84
+ }