dub 0.6.6 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +26 -0
- data/README.rdoc +41 -1
- data/dub.gemspec +160 -166
- data/lib/dub/argument.rb +25 -13
- data/lib/dub/function.rb +14 -4
- data/lib/dub/group.rb +2 -6
- data/lib/dub/klass.rb +55 -19
- data/lib/dub/lua/class.cpp.erb +29 -2
- data/lib/dub/lua/class_gen.rb +33 -34
- data/lib/dub/lua/function.cpp.erb +9 -12
- data/lib/dub/lua/function_gen.rb +55 -19
- data/lib/dub/lua/lua_cpp_helper.cpp +252 -0
- data/lib/dub/lua/lua_cpp_helper.h +118 -40
- data/lib/dub/lua/namespace.cpp.erb +3 -1
- data/lib/dub/lua/namespace_gen.rb +14 -33
- data/lib/dub/member_extraction.rb +47 -11
- data/lib/dub/namespace.rb +14 -3
- data/lib/dub/opts_parser.rb +3 -3
- data/lib/dub/version.rb +2 -2
- data/test/argument_test.rb +46 -12
- data/test/fixtures/app/include/matrix.h +121 -0
- data/test/fixtures/app/vendor/lua/liblua.a +0 -0
- data/test/fixtures/app/xml/classdub_1_1_base.xml +85 -0
- data/test/fixtures/app/xml/classdub_1_1_custom_destructor.xml +67 -0
- data/test/fixtures/app/xml/classdub_1_1_deletable_out_of_lua.xml +43 -0
- data/test/fixtures/app/xml/classdub_1_1_matrix.xml +162 -21
- data/test/fixtures/app/xml/classdub_1_1_no_destructor.xml +49 -0
- data/test/fixtures/app/xml/classdub_1_1_priv_sub_base.xml +89 -0
- data/test/fixtures/app/xml/classdub_1_1_private_constr.xml +68 -0
- data/test/fixtures/app/xml/classdub_1_1_static_constr.xml +69 -0
- data/test/fixtures/app/xml/classdub_1_1_sub_base.xml +89 -0
- data/test/fixtures/app/xml/classdub_1_1_t_mat.xml +15 -15
- data/test/fixtures/app/xml/index.xml +43 -0
- data/test/fixtures/app/xml/matrix_8h.xml +263 -132
- data/test/fixtures/app/xml/namespacedub.xml +10 -3
- data/test/function_group_test.rb +20 -1
- data/test/function_test.rb +10 -0
- data/test/group_test.rb +95 -9
- data/test/klass_test.rb +134 -5
- data/test/lua_function_gen_test.rb +36 -9
- metadata +20 -23
- data/.gitignore +0 -8
data/History.txt
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
+
== 0.7.0 2011-08-19
|
2
|
+
|
3
|
+
The tests in this release do not pass, but the generator is really better and works. I just
|
4
|
+
don't have the time to fix the tests.
|
5
|
+
|
6
|
+
* Major enhancements
|
7
|
+
* Support for finding userdata from lua table in checkuserdata.
|
8
|
+
* Support to access userdata with 'super'.
|
9
|
+
|
10
|
+
== 0.6.7
|
11
|
+
|
12
|
+
* Major enhancements
|
13
|
+
* Added support for LuaStackSize pseudo return value (enables direct stack manipulation).
|
14
|
+
* Added support for Qt 'public slot:' declarations.
|
15
|
+
* Added support for 'ignore' @dub setting.
|
16
|
+
* Added support for custom (or no) destructors.
|
17
|
+
* Fixed bugs related to overloaded methods and constructors.
|
18
|
+
* Added support for const char * return type.
|
19
|
+
* Added support for delete in C++ and/or Lua (DeletableOutOfLua class).
|
20
|
+
* Added 'deleted' method when the class can be destroyed out of Lua.
|
21
|
+
* Added support for custom constructors.
|
22
|
+
* Giving access to meta-table in libname.ClassName_.
|
23
|
+
* Changed LuaL_check... for dubL_check... to work in try/catch scope (thanks to Ignacio Burgueño)
|
24
|
+
* Fixed a bug in argument decision tree when there are default values.
|
25
|
+
* Fixed error reporting in try/catch to avoid memory leaks (thanks to Ignacio Burgueño)
|
26
|
+
|
1
27
|
== 0.6.6 2010-12-16
|
2
28
|
|
3
29
|
* Major enhancements
|
data/README.rdoc
CHANGED
@@ -64,4 +64,44 @@ Then you can write settings in the class documentation:
|
|
64
64
|
* string_args:'(*userdata)->interval()'
|
65
65
|
*/
|
66
66
|
|
67
|
-
Note that for some strange reason, you have to use a double '%' to get one.
|
67
|
+
Note that for some strange reason, you have to use a double '%' to get one.
|
68
|
+
|
69
|
+
== Constants
|
70
|
+
|
71
|
+
The easiest way to deal with constants is through documented enums (if this is possible) or defines with @defgroup.
|
72
|
+
|
73
|
+
== Custom destructors
|
74
|
+
|
75
|
+
By default Dub expects that the scripting app manages memory. This means that objects are deleted by the __gc method in
|
76
|
+
Lua for example. If you want to allow destruction from both the scripting language and C++, you can subclass the C++ with
|
77
|
+
DeletableOutOfLua (this protects Lua userdata from dangling pointers):
|
78
|
+
|
79
|
+
/** This class can be deleted from C++ or Lua
|
80
|
+
* @dub destructor: 'dub_destroy'
|
81
|
+
*/
|
82
|
+
class CustomDestructor : public DeletableOutOfLua
|
83
|
+
{
|
84
|
+
public:
|
85
|
+
// nothing special here
|
86
|
+
};
|
87
|
+
|
88
|
+
Once a custom destructor is set, the method calls in Lua are protected (check that the object still exists). You also get a new
|
89
|
+
method "deleted" that returns true if the C++ is ... well, yes: deleted.
|
90
|
+
|
91
|
+
You can also disable destruction from the scripting language by setting "destructor: ''" (empty string).
|
92
|
+
|
93
|
+
== Cucstom constructors
|
94
|
+
|
95
|
+
You can use custom constructors by using a static member function:
|
96
|
+
|
97
|
+
/** This class can be deleted from C++ or Lua
|
98
|
+
* @dub constructor: 'BuildCar'
|
99
|
+
*/
|
100
|
+
class Car
|
101
|
+
{
|
102
|
+
public:
|
103
|
+
static LuaStackSize BuildCar(lua_State *L);
|
104
|
+
};
|
105
|
+
|
106
|
+
Note that we have used the two special return values and parameters so that we can be in full control (this also means we will need
|
107
|
+
to push the userdata on the stack before returning the stack size). The LuaStackSize is a typedef for int.
|
data/dub.gemspec
CHANGED
@@ -1,189 +1,183 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dub}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.7.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = [
|
12
|
-
s.date = %q{
|
11
|
+
s.authors = [%q{Gaspard Bucher}]
|
12
|
+
s.date = %q{2011-08-19}
|
13
13
|
s.description = %q{This is a tool to ease the creation of scripting language bindings for a C++ library.
|
14
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
15
|
s.email = %q{gaspard@teti.ch}
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"LICENSE",
|
18
|
-
|
18
|
+
"README.rdoc"
|
19
19
|
]
|
20
20
|
s.files = [
|
21
|
-
".
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
21
|
+
"History.txt",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"dub.gemspec",
|
26
|
+
"lib/dub.rb",
|
27
|
+
"lib/dub/argument.rb",
|
28
|
+
"lib/dub/entities_unescape.rb",
|
29
|
+
"lib/dub/function.rb",
|
30
|
+
"lib/dub/function_group.rb",
|
31
|
+
"lib/dub/generator.rb",
|
32
|
+
"lib/dub/group.rb",
|
33
|
+
"lib/dub/klass.rb",
|
34
|
+
"lib/dub/lua.rb",
|
35
|
+
"lib/dub/lua/class.cpp.erb",
|
36
|
+
"lib/dub/lua/class_gen.rb",
|
37
|
+
"lib/dub/lua/function.cpp.erb",
|
38
|
+
"lib/dub/lua/function_gen.rb",
|
39
|
+
"lib/dub/lua/group.cpp.erb",
|
40
|
+
"lib/dub/lua/lua_cpp_helper.cpp",
|
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/opts_parser.rb",
|
47
|
+
"lib/dub/parser.rb",
|
48
|
+
"lib/dub/templates/lua_template.erb",
|
49
|
+
"lib/dub/version.rb",
|
50
|
+
"test/argument_test.rb",
|
51
|
+
"test/fixtures/app/CMakeLists.txt",
|
52
|
+
"test/fixtures/app/Doxyfile",
|
53
|
+
"test/fixtures/app/bindings/all_lua.cpp",
|
54
|
+
"test/fixtures/app/include/matrix.h",
|
55
|
+
"test/fixtures/app/make_lua_bindings.rb",
|
56
|
+
"test/fixtures/app/vendor/lua/CMakeLists.txt",
|
57
|
+
"test/fixtures/app/vendor/lua/COPYRIGHT",
|
58
|
+
"test/fixtures/app/vendor/lua/HISTORY",
|
59
|
+
"test/fixtures/app/vendor/lua/INSTALL",
|
60
|
+
"test/fixtures/app/vendor/lua/Makefile",
|
61
|
+
"test/fixtures/app/vendor/lua/README",
|
62
|
+
"test/fixtures/app/vendor/lua/lapi.c",
|
63
|
+
"test/fixtures/app/vendor/lua/lapi.h",
|
64
|
+
"test/fixtures/app/vendor/lua/lauxlib.c",
|
65
|
+
"test/fixtures/app/vendor/lua/lauxlib.h",
|
66
|
+
"test/fixtures/app/vendor/lua/lbaselib.c",
|
67
|
+
"test/fixtures/app/vendor/lua/lcode.c",
|
68
|
+
"test/fixtures/app/vendor/lua/lcode.h",
|
69
|
+
"test/fixtures/app/vendor/lua/ldblib.c",
|
70
|
+
"test/fixtures/app/vendor/lua/ldebug.c",
|
71
|
+
"test/fixtures/app/vendor/lua/ldebug.h",
|
72
|
+
"test/fixtures/app/vendor/lua/ldo.c",
|
73
|
+
"test/fixtures/app/vendor/lua/ldo.h",
|
74
|
+
"test/fixtures/app/vendor/lua/ldump.c",
|
75
|
+
"test/fixtures/app/vendor/lua/lfunc.c",
|
76
|
+
"test/fixtures/app/vendor/lua/lfunc.h",
|
77
|
+
"test/fixtures/app/vendor/lua/lgc.c",
|
78
|
+
"test/fixtures/app/vendor/lua/lgc.h",
|
79
|
+
"test/fixtures/app/vendor/lua/liblua.a",
|
80
|
+
"test/fixtures/app/vendor/lua/linit.c",
|
81
|
+
"test/fixtures/app/vendor/lua/liolib.c",
|
82
|
+
"test/fixtures/app/vendor/lua/llex.c",
|
83
|
+
"test/fixtures/app/vendor/lua/llex.h",
|
84
|
+
"test/fixtures/app/vendor/lua/llimits.h",
|
85
|
+
"test/fixtures/app/vendor/lua/lmathlib.c",
|
86
|
+
"test/fixtures/app/vendor/lua/lmem.c",
|
87
|
+
"test/fixtures/app/vendor/lua/lmem.h",
|
88
|
+
"test/fixtures/app/vendor/lua/loadlib.c",
|
89
|
+
"test/fixtures/app/vendor/lua/lobject.c",
|
90
|
+
"test/fixtures/app/vendor/lua/lobject.h",
|
91
|
+
"test/fixtures/app/vendor/lua/lopcodes.c",
|
92
|
+
"test/fixtures/app/vendor/lua/lopcodes.h",
|
93
|
+
"test/fixtures/app/vendor/lua/loslib.c",
|
94
|
+
"test/fixtures/app/vendor/lua/lparser.c",
|
95
|
+
"test/fixtures/app/vendor/lua/lparser.h",
|
96
|
+
"test/fixtures/app/vendor/lua/lstate.c",
|
97
|
+
"test/fixtures/app/vendor/lua/lstate.h",
|
98
|
+
"test/fixtures/app/vendor/lua/lstring.c",
|
99
|
+
"test/fixtures/app/vendor/lua/lstring.h",
|
100
|
+
"test/fixtures/app/vendor/lua/lstrlib.c",
|
101
|
+
"test/fixtures/app/vendor/lua/ltable.c",
|
102
|
+
"test/fixtures/app/vendor/lua/ltable.h",
|
103
|
+
"test/fixtures/app/vendor/lua/ltablib.c",
|
104
|
+
"test/fixtures/app/vendor/lua/ltm.c",
|
105
|
+
"test/fixtures/app/vendor/lua/ltm.h",
|
106
|
+
"test/fixtures/app/vendor/lua/lua.c",
|
107
|
+
"test/fixtures/app/vendor/lua/lua.h",
|
108
|
+
"test/fixtures/app/vendor/lua/lua_dub_helper.h",
|
109
|
+
"test/fixtures/app/vendor/lua/luac",
|
110
|
+
"test/fixtures/app/vendor/lua/luac.c",
|
111
|
+
"test/fixtures/app/vendor/lua/luaconf.h",
|
112
|
+
"test/fixtures/app/vendor/lua/lualib.h",
|
113
|
+
"test/fixtures/app/vendor/lua/lundump.c",
|
114
|
+
"test/fixtures/app/vendor/lua/lundump.h",
|
115
|
+
"test/fixtures/app/vendor/lua/lvm.c",
|
116
|
+
"test/fixtures/app/vendor/lua/lvm.h",
|
117
|
+
"test/fixtures/app/vendor/lua/lzio.c",
|
118
|
+
"test/fixtures/app/vendor/lua/lzio.h",
|
119
|
+
"test/fixtures/app/vendor/lua/matrix.h",
|
120
|
+
"test/fixtures/app/vendor/lua/print.c",
|
121
|
+
"test/fixtures/app/vendor/lua/test/README",
|
122
|
+
"test/fixtures/app/vendor/lua/test/bisect.lua",
|
123
|
+
"test/fixtures/app/vendor/lua/test/cf.lua",
|
124
|
+
"test/fixtures/app/vendor/lua/test/echo.lua",
|
125
|
+
"test/fixtures/app/vendor/lua/test/env.lua",
|
126
|
+
"test/fixtures/app/vendor/lua/test/factorial.lua",
|
127
|
+
"test/fixtures/app/vendor/lua/test/fib.lua",
|
128
|
+
"test/fixtures/app/vendor/lua/test/fibfor.lua",
|
129
|
+
"test/fixtures/app/vendor/lua/test/globals.lua",
|
130
|
+
"test/fixtures/app/vendor/lua/test/hello.lua",
|
131
|
+
"test/fixtures/app/vendor/lua/test/life.lua",
|
132
|
+
"test/fixtures/app/vendor/lua/test/luac.lua",
|
133
|
+
"test/fixtures/app/vendor/lua/test/printf.lua",
|
134
|
+
"test/fixtures/app/vendor/lua/test/readonly.lua",
|
135
|
+
"test/fixtures/app/vendor/lua/test/sieve.lua",
|
136
|
+
"test/fixtures/app/vendor/lua/test/sort.lua",
|
137
|
+
"test/fixtures/app/vendor/lua/test/table.lua",
|
138
|
+
"test/fixtures/app/vendor/lua/test/trace-calls.lua",
|
139
|
+
"test/fixtures/app/vendor/lua/test/trace-globals.lua",
|
140
|
+
"test/fixtures/app/vendor/lua/test/xd.lua",
|
141
|
+
"test/fixtures/app/xml/classdub_1_1_base.xml",
|
142
|
+
"test/fixtures/app/xml/classdub_1_1_custom_destructor.xml",
|
143
|
+
"test/fixtures/app/xml/classdub_1_1_deletable_out_of_lua.xml",
|
144
|
+
"test/fixtures/app/xml/classdub_1_1_matrix.xml",
|
145
|
+
"test/fixtures/app/xml/classdub_1_1_no_destructor.xml",
|
146
|
+
"test/fixtures/app/xml/classdub_1_1_priv_sub_base.xml",
|
147
|
+
"test/fixtures/app/xml/classdub_1_1_private_constr.xml",
|
148
|
+
"test/fixtures/app/xml/classdub_1_1_static_constr.xml",
|
149
|
+
"test/fixtures/app/xml/classdub_1_1_sub_base.xml",
|
150
|
+
"test/fixtures/app/xml/classdub_1_1_t_mat.xml",
|
151
|
+
"test/fixtures/app/xml/combine.xslt",
|
152
|
+
"test/fixtures/app/xml/compound.xsd",
|
153
|
+
"test/fixtures/app/xml/dir_53661a2bdeb1d55e60581a7e15deb763.xml",
|
154
|
+
"test/fixtures/app/xml/index.xml",
|
155
|
+
"test/fixtures/app/xml/index.xsd",
|
156
|
+
"test/fixtures/app/xml/matrix_8h.xml",
|
157
|
+
"test/fixtures/app/xml/namespacedub.xml",
|
158
|
+
"test/fixtures/classcv_1_1_mat.xml",
|
159
|
+
"test/fixtures/classcv_1_1_point__.xml",
|
160
|
+
"test/fixtures/classcv_1_1_scalar__.xml",
|
161
|
+
"test/fixtures/classcv_1_1_size__.xml",
|
162
|
+
"test/fixtures/dummy_class.cpp.erb",
|
163
|
+
"test/fixtures/dummy_function.cpp.erb",
|
164
|
+
"test/fixtures/group___magic_type.xml",
|
165
|
+
"test/fixtures/namespacecv.xml",
|
166
|
+
"test/function_group_test.rb",
|
167
|
+
"test/function_test.rb",
|
168
|
+
"test/group_test.rb",
|
169
|
+
"test/helper.rb",
|
170
|
+
"test/klass_test.rb",
|
171
|
+
"test/lua_function_gen_test.rb",
|
172
|
+
"test/namespace_test.rb",
|
173
|
+
"test/parser_test.rb"
|
166
174
|
]
|
167
175
|
s.homepage = %q{http://rubyk.org/en/project311.html}
|
168
|
-
s.
|
169
|
-
s.
|
170
|
-
s.rubygems_version = %q{1.3.7}
|
176
|
+
s.require_paths = [%q{lib}]
|
177
|
+
s.rubygems_version = %q{1.8.6}
|
171
178
|
s.summary = %q{A tool to ease the creation of scripting language bindings for a C++ library.}
|
172
|
-
s.test_files = [
|
173
|
-
"test/argument_test.rb",
|
174
|
-
"test/fixtures/app/make_lua_bindings.rb",
|
175
|
-
"test/function_group_test.rb",
|
176
|
-
"test/function_test.rb",
|
177
|
-
"test/group_test.rb",
|
178
|
-
"test/helper.rb",
|
179
|
-
"test/klass_test.rb",
|
180
|
-
"test/lua_function_gen_test.rb",
|
181
|
-
"test/namespace_test.rb",
|
182
|
-
"test/parser_test.rb"
|
183
|
-
]
|
184
179
|
|
185
180
|
if s.respond_to? :specification_version then
|
186
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
187
181
|
s.specification_version = 3
|
188
182
|
|
189
183
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
data/lib/dub/argument.rb
CHANGED
@@ -19,16 +19,19 @@ module Dub
|
|
19
19
|
'uint',
|
20
20
|
'bool',
|
21
21
|
'uchar',
|
22
|
-
'char',
|
23
22
|
'void',
|
24
|
-
'int64'
|
23
|
+
'int64',
|
25
24
|
]
|
26
25
|
|
27
26
|
STRING_TYPES = [
|
28
27
|
'char',
|
29
28
|
]
|
30
29
|
|
31
|
-
|
30
|
+
BOOL_TYPES = [
|
31
|
+
'bool',
|
32
|
+
]
|
33
|
+
|
34
|
+
NATIVE_C_TYPES = NUMBER_TYPES + STRING_TYPES + BOOL_TYPES
|
32
35
|
|
33
36
|
class << self
|
34
37
|
|
@@ -36,13 +39,13 @@ module Dub
|
|
36
39
|
def type_group(arg)
|
37
40
|
# exact same type
|
38
41
|
if NATIVE_C_TYPES.include?(arg.type)
|
39
|
-
if
|
42
|
+
if BOOL_TYPES.include?(arg.type)
|
43
|
+
:boolean
|
44
|
+
elsif STRING_TYPES.include?(arg.type) && arg.is_pointer?
|
45
|
+
:string
|
46
|
+
else
|
40
47
|
# number synonym
|
41
48
|
arg.is_pointer? ? :number_ptr : :number
|
42
|
-
else
|
43
|
-
# string synonym
|
44
|
-
raise "Not implemented yet"
|
45
|
-
# :string
|
46
49
|
end
|
47
50
|
else
|
48
51
|
# custom class / type
|
@@ -54,21 +57,30 @@ module Dub
|
|
54
57
|
def decision_tree(group)
|
55
58
|
hash = {}
|
56
59
|
group.each do |function|
|
57
|
-
|
60
|
+
insert_by_arg(hash, function)
|
58
61
|
end
|
62
|
+
print(hash.inspect) if group.first.name == 'bind'
|
59
63
|
hash
|
60
64
|
end
|
61
65
|
|
62
66
|
# Insert a function into the hash, using the argument at the given
|
63
67
|
# index to filter
|
64
|
-
def
|
68
|
+
def insert_by_arg(hash, function, index = 0)
|
65
69
|
arg = function.arguments[index]
|
66
70
|
type = arg ? type_group(arg) : nil
|
71
|
+
insert_by_type(hash, function, index, type)
|
72
|
+
if arg && arg.has_default?
|
73
|
+
insert_by_type(hash, function, index, nil)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def insert_by_type(hash, function, index, type)
|
78
|
+
# hash[nil] ==> there is a default argument
|
67
79
|
slot = hash[type]
|
68
80
|
if slot.nil?
|
69
81
|
hash[type] = function
|
70
82
|
elsif slot.kind_of?(Hash)
|
71
|
-
|
83
|
+
insert_by_arg(slot, function, index + 1)
|
72
84
|
elsif type.nil?
|
73
85
|
# ignore
|
74
86
|
|
@@ -76,8 +88,8 @@ module Dub
|
|
76
88
|
# puts "Cannot filter functions #{function.source}"
|
77
89
|
else
|
78
90
|
h = {}
|
79
|
-
|
80
|
-
|
91
|
+
insert_by_arg(h, slot, index + 1)
|
92
|
+
insert_by_arg(h, function, index + 1)
|
81
93
|
hash[type] = h
|
82
94
|
end
|
83
95
|
end
|