rbplusplus 0.9 → 0.9.1

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.
Files changed (42) hide show
  1. data/Rakefile +6 -3
  2. data/TODO +3 -0
  3. data/lib/rbplusplus/builders/base.rb +8 -1
  4. data/lib/rbplusplus/builders/class.rb +4 -11
  5. data/lib/rbplusplus/builders/director.rb +12 -15
  6. data/lib/rbplusplus/builders/director_method.rb +1 -1
  7. data/lib/rbplusplus/builders/extension.rb +1 -0
  8. data/lib/rbplusplus/builders/instance_variable.rb +2 -2
  9. data/lib/rbplusplus/builders/method_base.rb +40 -2
  10. data/lib/rbplusplus/extension.rb +4 -5
  11. data/lib/rbplusplus/transformers/node.rb +6 -0
  12. data/lib/rbplusplus/writers/multiple_files_writer.rb +10 -3
  13. data/lib/rbplusplus/writers/single_file_writer.rb +4 -2
  14. data/test/allocation_strategies_test.rb +1 -1
  15. data/test/class_methods_encapsulate_test.rb +1 -1
  16. data/test/class_methods_test.rb +1 -1
  17. data/test/classes_test.rb +5 -1
  18. data/test/compiling_test.rb +1 -1
  19. data/test/constructors_test.rb +1 -1
  20. data/test/custom_code_test.rb +1 -1
  21. data/test/default_arguments_test.rb +19 -1
  22. data/test/director_test.rb +6 -1
  23. data/test/enumerations_test.rb +1 -1
  24. data/test/extension_test.rb +1 -1
  25. data/test/file_writers_test.rb +1 -1
  26. data/test/function_pointer_test.rb +1 -1
  27. data/test/function_pointers_classes_test.rb +1 -1
  28. data/test/functions_test.rb +1 -1
  29. data/test/generated/extconf.rb +1 -1
  30. data/test/headers/Adder.h +2 -0
  31. data/test/headers/default_arguments.h +37 -4
  32. data/test/headers/director.h +8 -0
  33. data/test/headers/overload.h +17 -0
  34. data/test/modules_test.rb +1 -1
  35. data/test/nested_test.rb +1 -1
  36. data/test/overloading_test.rb +12 -5
  37. data/test/struct_test.rb +1 -1
  38. data/test/subclass_test.rb +1 -1
  39. data/test/test_helper.rb +1 -1
  40. data/test/to_from_ruby_test.rb +1 -1
  41. data/test/wrap_as_test.rb +1 -1
  42. metadata +23 -3
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rake/rdoctask'
3
3
  require 'rake/contrib/sshpublisher'
4
4
 
5
5
  PROJECT_NAME = "rb++"
6
- RBPLUSPLUS_VERSION = "0.9"
6
+ RBPLUSPLUS_VERSION = "0.9.1"
7
7
 
8
8
  task :default => :test
9
9
 
@@ -22,7 +22,7 @@ task :test do
22
22
  # the exact ruby binary that's linked to the ruby running the Rakefile. Just saying
23
23
  # "ruby" will find the system's installed ruby and be worthless
24
24
  ruby = File.join(Config::CONFIG["bindir"], Config::CONFIG["RUBY_INSTALL_NAME"])
25
- sh "#{ruby} #{file}"
25
+ sh "#{ruby} -Itest #{file}"
26
26
  end
27
27
  end
28
28
 
@@ -74,7 +74,10 @@ make Ruby wrapping extensions easier to write than ever.
74
74
  END
75
75
 
76
76
  s.add_dependency "rbgccxml", "~> 0.9"
77
- s.add_dependency "rice", "~> 1.2.0"
77
+ s.add_dependency "rice", "~> 1.3.0"
78
+
79
+ s.add_development_dependency "test-unit", "1.2.3"
80
+ s.add_development_dependency "mocha", "~> 0.9"
78
81
 
79
82
  patterns = [
80
83
  'TODO',
data/TODO CHANGED
@@ -3,6 +3,9 @@ Parts to move into rbgccxml:
3
3
  - Class purely_virtual? (check the abstract attribute)
4
4
  - Namespace#methods ?
5
5
 
6
+ Seen in Ogre.rb
7
+ - method wrapping is finding a reference when should be a pointer (Ogre::ShadowTextureManager::getSingleton)
8
+
6
9
  Move documentation to YARD?
7
10
 
8
11
  Use sdoc?
@@ -108,7 +108,10 @@ module RbPlusPlus
108
108
  # Should this node be wrapped as it is or has the user
109
109
  # specified something else for this node?
110
110
  def do_not_wrap?(node)
111
- node.ignored? || (node.moved_to && node.moved_to != self.code) || !node.public?
111
+ node.ignored? ||
112
+ (node.moved_to && node.moved_to != self.code) ||
113
+ !node.public? ||
114
+ (node.is_a?(RbGCCXML::Struct) && node.incomplete?)
112
115
  end
113
116
 
114
117
  # Given a new node, build it and add it to our nodes list
@@ -148,6 +151,10 @@ module RbPlusPlus
148
151
  end
149
152
  end
150
153
 
154
+ if node == self.code && last_found != node
155
+ Logger.debug "Found Typedef #{last_found.qualified_name} for #{node.qualified_name}"
156
+ end
157
+
151
158
  last_found
152
159
  end
153
160
 
@@ -28,17 +28,17 @@ module RbPlusPlus
28
28
 
29
29
  if supers.length > 1
30
30
  if (@superclass = self.code._get_superclass).nil?
31
+ @superclass = supers[0]
31
32
  Logger.warn :mutiple_superclasses, "#{@qualified_name} has multiple public superclasses. " +
32
- "Will use first superclass, which is #{supers[0].qualified_name} "
33
+ "Will use first superclass, which is #{@superclass.qualified_name} "
33
34
  "Please use #use_superclass to specify another superclass as needed."
34
35
  end
35
36
  end
36
37
 
38
+ @director = nil
37
39
  if self.code.needs_director?
38
40
  @director = DirectorNode.new(self.code, self, @qualified_name, @superclass)
39
41
  add_child @director
40
-
41
- @qualified_name = @director.qualified_name
42
42
  end
43
43
 
44
44
  self.rice_variable = "rb_c#{@short_name.as_variable}"
@@ -63,16 +63,9 @@ module RbPlusPlus
63
63
  def write
64
64
  prefix = "#{rice_variable_type} #{rice_variable} = "
65
65
  ruby_name = @short_name
66
- expose_class = @qualified_name
67
66
  superclass = @superclass.qualified_name if @superclass && !do_not_wrap?(@superclass)
68
67
 
69
- if @director
70
- @director.write_class_registration
71
- expose_class = @director.qualified_name
72
- superclass = @class_base_type
73
- end
74
-
75
- class_names = [expose_class]
68
+ class_names = [@qualified_name]
76
69
  class_names << superclass if superclass
77
70
  class_names = class_names.join(",")
78
71
 
@@ -52,16 +52,6 @@ module RbPlusPlus
52
52
  @constructors << constructor
53
53
  end
54
54
 
55
- def write_class_registration
56
- # Need to tell Rice of the base class, while also making sure that if there's a superclass to this class
57
- # that we know about it, or attempts to use polymorphism will crash with 'unknown caster for {superclass}
58
- class_names = [@class_qualified_name]
59
- class_names << @superclass.qualified_name if @superclass && !do_not_wrap?(@superclass)
60
- class_names = class_names.join(",")
61
-
62
- self.parent.registrations << "Rice::define_class< #{class_names} >(\"__#{@class_base_name}__\");"
63
- end
64
-
65
55
  def write_constructor(constructor = nil)
66
56
  args = ["Rice::Object self"]
67
57
  types = [@name, "Rice::Object"]
@@ -79,6 +69,8 @@ module RbPlusPlus
79
69
  end
80
70
 
81
71
  declarations << "#{@name}(#{args.join(", ")}) : #{@class_qualified_name}(#{supercall_args.join(", ")}), Rice::Director(self) { }"
72
+
73
+ registrations << "#{self.parent.rice_variable}.define_director< #{@name} >();"
82
74
  registrations << "#{self.parent.rice_variable}.define_constructor(Rice::Constructor< #{types.join(", ")} >());"
83
75
  end
84
76
 
@@ -115,7 +107,7 @@ module RbPlusPlus
115
107
  up_or_raise =
116
108
  if method.default_return_value
117
109
  reverse = "!"
118
- "return #{method.default_return_value};"
110
+ "return #{method.default_return_value}"
119
111
  else
120
112
  if method.purely_virtual?
121
113
  "raisePureVirtual()"
@@ -129,14 +121,19 @@ module RbPlusPlus
129
121
 
130
122
  const = method.const? ? "const" : ""
131
123
 
124
+ # Write out the virtual method that forwards calls into Ruby
132
125
  declarations << ""
133
- declarations << "#{return_type} #{cpp_name}(#{def_arguments}) #{const} {"
134
- declarations << "if(#{reverse}callIsFromRuby(\"#{ruby_name}\")) {"
135
- declarations << "#{up_or_raise};"
136
- declarations << "} else {"
126
+ declarations << "virtual #{return_type} #{cpp_name}(#{def_arguments}) #{const} {"
137
127
  declarations << "#{call_down};"
138
128
  declarations << "}"
129
+
130
+ # Write out the wrapper method that gets exposed to Ruby that handles
131
+ # going up the inheritance chain
132
+ declarations << ""
133
+ declarations << "#{return_type} default_#{cpp_name}(#{def_arguments}) #{const} {"
134
+ declarations << "#{up_or_raise};"
139
135
  declarations << "}"
136
+
140
137
  end
141
138
 
142
139
  declarations << "};"
@@ -11,7 +11,7 @@ module RbPlusPlus
11
11
 
12
12
  def code_path
13
13
  cpp_name = self.code.qualified_name.split("::")[-1]
14
- "#{@director.qualified_name}::#{cpp_name}"
14
+ "#{@director.qualified_name}::default_#{cpp_name}"
15
15
  end
16
16
 
17
17
  end
@@ -44,6 +44,7 @@ module RbPlusPlus
44
44
  # then wrap it up in our own template
45
45
  registrations << "extern \"C\""
46
46
  registrations << "void Init_#{@name}() {"
47
+ registrations << "RUBY_TRY {"
47
48
  end
48
49
 
49
50
  private
@@ -14,7 +14,7 @@ module RbPlusPlus
14
14
  # Setter, only if it isn't const
15
15
  if !code.cpp_type.const?
16
16
  method_name = "wrap_#{parent_name}_#{code.name}_set"
17
- declarations << "void #{method_name}(#{parent.code.qualified_name}* self, #{code.cpp_type.base_type.qualified_name} val) {"
17
+ declarations << "void #{method_name}(#{parent.code.qualified_name}* self, #{code.cpp_type.to_cpp} val) {"
18
18
  declarations << "self->#{code.name} = val;"
19
19
  declarations << "}"
20
20
 
@@ -23,7 +23,7 @@ module RbPlusPlus
23
23
 
24
24
  # Getter
25
25
  method_name = "wrap_#{parent_name}_#{code.name}_get"
26
- declarations << "#{code.cpp_type.base_type.qualified_name} #{method_name}(#{parent.code.qualified_name}* self) {"
26
+ declarations << "#{code.cpp_type.to_cpp} #{method_name}(#{parent.code.qualified_name}* self) {"
27
27
  declarations << "return self->#{code.name};"
28
28
  declarations << "}"
29
29
 
@@ -114,22 +114,60 @@ module RbPlusPlus
114
114
 
115
115
  self.code.arguments.each do |arg|
116
116
  arguments << arg.to_cpp
117
- default_arguments << "Rice::Arg(\"#{arg.name}\")#{arg.value ? " = (#{arg.cpp_type.to_cpp})#{arg.value}" : "" }"
117
+
118
+ default_value =
119
+ if arg.value
120
+ if (base_type = arg.cpp_type.base_type).is_a?(RbGCCXML::Enumeration)
121
+ " = #{fix_enumeration_value(base_type, arg.value)}"
122
+ elsif base_type.is_a?(RbGCCXML::FundamentalType)
123
+ " = (#{arg.cpp_type.base_type.to_cpp})(#{arg.value})"
124
+ else
125
+ " = (#{arg.value})"
126
+ end
127
+ else
128
+ ""
129
+ end
130
+
131
+ default_arguments << "Rice::Arg(\"#{arg.name}\")#{default_value}"
118
132
  end
119
133
 
120
134
  return_type = find_typedef_for(self.code.return_type).to_cpp
121
135
 
122
136
  def_args = default_arguments.any? ? ", (#{default_arguments.join(", ")})" : ""
123
137
 
138
+ const = self.code.const? ? " const" : ""
139
+
124
140
  registrations << "{"
125
141
 
126
- registrations << "typedef #{return_type} ( #{method_ref} )( #{arguments.join(", ")} );"
142
+ registrations << "typedef #{return_type} ( #{method_ref} )( #{arguments.join(", ")} )#{const};"
127
143
  registrations << "#{self.prefix}#{self.rice_method}(\"#{@ruby_name + self.suffix}\", " +
128
144
  "#{usage_ref}( &#{code_path} )#{def_args});"
129
145
 
130
146
  registrations << "}"
131
147
  end
132
148
 
149
+ # See http://www.gccxml.org/Bug/view.php?id=9234
150
+ #
151
+ # Basically due to inconsistencies within gcc, GCC-XML parses default arguments
152
+ # with having enumeration values exactly as they are in the code. This means
153
+ # that if the C++ doesn't fully namespace the enumeration, extension compilation
154
+ # will fail because g++ can't find the enumeration.
155
+ #
156
+ # We work around this by checking if the argument is an Enumeration (above), then
157
+ # grabbing the appropriate EnumValue and printing it out.
158
+ #
159
+ # Of course, there could be times we don't want to do this and just use the actual
160
+ # default value. See default_arguments_test and headers/default_arguments.h
161
+ # for an example.
162
+ def fix_enumeration_value(enum, default_value)
163
+ found =
164
+ enum.values.select do |enum_value|
165
+ enum_value.name == default_value
166
+ end.first
167
+
168
+ found ? found.qualified_name : default_value
169
+ end
170
+
133
171
  end
134
172
 
135
173
  end
@@ -57,6 +57,8 @@ module RbPlusPlus
57
57
  @name = name
58
58
  @modules = []
59
59
  @writer_mode = :multiple
60
+ @requesting_console = false
61
+ @force_rebuild = false
60
62
 
61
63
  @options = {
62
64
  :include_paths => [],
@@ -74,6 +76,7 @@ module RbPlusPlus
74
76
 
75
77
  if requesting_console?
76
78
  block.call(self) if block
79
+ start_console
77
80
  elsif block
78
81
  build_working_dir(&block)
79
82
  block.call(self)
@@ -154,10 +157,6 @@ module RbPlusPlus
154
157
  @sources = Dir.glob dirs
155
158
  Logger.info "Parsing #{@sources.inspect}"
156
159
  @parser = RbGCCXML.parse(dirs, parser_options)
157
-
158
- if requesting_console?
159
- start_console
160
- end
161
160
  end
162
161
 
163
162
  # Set a namespace to be the main namespace used for this extension.
@@ -290,7 +289,7 @@ module RbPlusPlus
290
289
  # and if it does exist, clean it out
291
290
  def prepare_working_dir
292
291
  FileUtils.mkdir_p @working_dir unless File.directory?(@working_dir)
293
- FileUtils.rm_rf Dir["#{@working_dir}/*"] if @force_rebuild #ARGV.include?("clean")
292
+ FileUtils.rm_rf Dir["#{@working_dir}/*"] if @force_rebuild
294
293
  end
295
294
 
296
295
  # Make sure that any files or globs of files in :include_source_files are copied into the working
@@ -60,6 +60,12 @@ module RbGCCXML
60
60
  !!cache[:disable_typedef_lookup]
61
61
  end
62
62
 
63
+ # Is this node an incomplete node?
64
+ # TODO Move to rbgccxml
65
+ def incomplete?
66
+ self["incomplete"] ? self["incomplete"] == "1" : false
67
+ end
68
+
63
69
  protected
64
70
 
65
71
  # Get this node's settings cache
@@ -128,6 +128,11 @@ module RbPlusPlus
128
128
  @node = node
129
129
  @base_name = node.qualified_name.as_variable
130
130
 
131
+ @register_method = nil
132
+ @register_methods = []
133
+ @register_includes = []
134
+
135
+
131
136
  @header = parent ? "_#{@base_name}.rb.hpp" : nil
132
137
  @source = parent ? "_#{@base_name}.rb.cpp" : "#{@base_name}.rb.cpp"
133
138
  @parent = parent
@@ -167,9 +172,6 @@ module RbPlusPlus
167
172
  end
168
173
 
169
174
  def add_register_method(node_name, header)
170
- @register_methods ||= []
171
- @register_includes ||= []
172
-
173
175
  @register_includes << "#include \"#{header}\""
174
176
  @register_methods << "register_#{node_name}(#{has_rice_variable? ? self.rice_variable : ""});"
175
177
  end
@@ -263,6 +265,7 @@ module RbPlusPlus
263
265
 
264
266
  # I really need a better way of handling this
265
267
  if @needs_closing
268
+ cpp.puts "} RUBY_CATCH" unless @parent
266
269
  cpp.puts "}"
267
270
  end
268
271
  end
@@ -280,6 +283,10 @@ module RbPlusPlus
280
283
  @needs_closing = false
281
284
  @additional_includes = []
282
285
  @require_custom = true
286
+
287
+ @register_method = nil
288
+ @register_includes = []
289
+ @register_methods = []
283
290
  end
284
291
 
285
292
  def with_includes(includes)
@@ -28,8 +28,10 @@ module RbPlusPlus
28
28
  cpp.puts @global_hpp.flatten.compact.join("\n")
29
29
  cpp.puts @declarations.flatten.compact.join("\n")
30
30
  cpp.puts @global_cpp.flatten.compact.join("\n")
31
- cpp.puts @registrations.flatten.compact.join("\n")
32
- cpp.puts "}" # Yeah, need to figure this one out
31
+
32
+ cpp.puts @registrations.flatten.compact.join("\n\t")
33
+ cpp.puts "} RUBY_CATCH"
34
+ cpp.puts "}"
33
35
 
34
36
  end
35
37
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Allocation Strategies" do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Correct handling of encapsulated methods" do
4
4
  def setup
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Correct handling of static methods" do
4
4
  def setup
data/test/classes_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Extension with wrapped classes" do
4
4
 
@@ -108,5 +108,9 @@ context "Extension with wrapped classes" do
108
108
  a.add_integers(3, 7).should.equal 21
109
109
  a.add_strings("piz", "owned").should.equal "pizownedwoot"
110
110
  end
111
+
112
+ specify "should not wrap incomplete types" do
113
+ assert !defined?(Forwarder)
114
+ end
111
115
  end
112
116
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Compiler settings" do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Extension with constructors out the whazoo" do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Extension with wrapped classes" do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Default arguments properly exposed" do
4
4
 
@@ -66,4 +66,22 @@ context "Default arguments properly exposed" do
66
66
  end
67
67
  end
68
68
 
69
+ # See MethodBase#fix_enumeration_value
70
+ specify "properly handle incomplete enums in default values" do
71
+ modify(1).should.equal 11
72
+ modify(1, Ops::ADD).should.equal 11
73
+ modify(1, Ops::REMOVE).should.equal -9
74
+ end
75
+
76
+ # Ogre does this to handle some weird pass-back-enum-that-signals-error (Ogre::Frustum::isVisible)
77
+ specify "properly handle incomplete enums arguments with straight integer default values" do
78
+ modify2(1).should.equal 1
79
+ modify2(1, Ops::ADD).should.equal 1
80
+ modify2(1, Ops::REMOVE).should.equal 1
81
+ end
82
+
83
+ xspecify "should properly handle argument type qualifiers like refs and consts" do
84
+ build_strings("I'd ").should.equal "I'd kick-it"
85
+ build_strings("You won't", " do it").should.equal "You won't do it"
86
+ end
69
87
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Director proxy generation" do
4
4
 
@@ -170,4 +170,9 @@ context "Director proxy generation" do
170
170
  Worker::ZeeEnum::VALUE.to_i.should.equal 4
171
171
  end
172
172
 
173
+ specify "inheritance types are registered properly" do
174
+ two = VTwo.new
175
+ VBase::process(two).should.equal "methodTwo"
176
+ end
177
+
173
178
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Wrapping enumerations" do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Ruby Extension creation" do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Multiple file writer (default)" do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "properly handles and wraps function pointer arguments" do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Function pointers into class methods" do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Extension with globally available functions" do
4
4
 
@@ -22,4 +22,4 @@ if RUBY_PLATFORM =~ /darwin/
22
22
  append_ld_flags '-all_load'
23
23
  end
24
24
 
25
- create_makefile("function_pointers_class")
25
+ create_makefile("defargs")
data/test/headers/Adder.h CHANGED
@@ -5,6 +5,8 @@
5
5
  using namespace std;
6
6
 
7
7
  namespace classes {
8
+ class Forwarder;
9
+
8
10
  class Adder {
9
11
  public:
10
12
  Adder();
@@ -21,9 +21,11 @@ namespace default_args {
21
21
  public:
22
22
  Tester() { }
23
23
 
24
- // Class methods
25
- std::string concat(std::string value1, std::string value2, const char* with = "-") {
26
- return value1 + std::string(with) + value2;
24
+ static std::string DEFAULT_WITH;
25
+
26
+ // Class methods
27
+ std::string concat(std::string value1, std::string value2, std::string with = default_args::Tester::DEFAULT_WITH) {
28
+ return value1 + with + value2;
27
29
  }
28
30
 
29
31
  // Class static methods
@@ -36,6 +38,14 @@ namespace default_args {
36
38
  }
37
39
  };
38
40
 
41
+ std::string Tester::DEFAULT_WITH = std::string("-");
42
+ static std::string KICK_IT = std::string("kick-it");
43
+
44
+ // Make sure const and reference types are taken care of properly
45
+ //std::string build_strings(std::string value1, const std::string& with = default_args::KICK_IT) {
46
+ //return value1 + with;
47
+ //}
48
+
39
49
  class Directed {
40
50
  public:
41
51
  // Director methods
@@ -43,7 +53,30 @@ namespace default_args {
43
53
  return x * y;
44
54
  }
45
55
  };
46
-
56
+
57
+ enum Ops {
58
+ ADD = 0,
59
+ REMOVE = 1
60
+ };
61
+
62
+ int modify(int value, Ops by = ADD) {
63
+ switch(by) {
64
+ case ADD:
65
+ return value + 10;
66
+ break;
67
+ case REMOVE:
68
+ return value - 10;
69
+ break;
70
+ }
71
+ return value;
72
+ }
73
+
74
+ // Seen in Ogre3D
75
+ int modify2(int value, Ops* by = 0) {
76
+ return value;
77
+ }
78
+
79
+
47
80
  }
48
81
 
49
82
  #endif // __DEFAULT_ARGS_H__
@@ -125,6 +125,14 @@ namespace director {
125
125
  VBase() { }
126
126
  virtual ~VBase() { }
127
127
 
128
+ /**
129
+ * See that types are registered properly.
130
+ * Passing a VTwo into this method should work
131
+ */
132
+ static std::string process(VBase* base) {
133
+ return base->methodTwo();
134
+ }
135
+
128
136
  virtual std::string methodOne() = 0;
129
137
  virtual std::string methodTwo() = 0;
130
138
  virtual std::string methodThree() = 0;
@@ -1,6 +1,8 @@
1
1
  #ifndef __METHOD_OVERLOAD_H__
2
2
  #define __METHOD_OVERLOAD_H__
3
3
 
4
+ #include <string>
5
+
4
6
  namespace overload {
5
7
  class Mathy {
6
8
  public:
@@ -20,6 +22,21 @@ namespace overload {
20
22
  }
21
23
  void nothing() {}
22
24
  void nothing(int x) {}
25
+
26
+ /**
27
+ * Const methods
28
+ */
29
+ int constMethod(int x) {
30
+ return 1;
31
+ }
32
+
33
+ int constMethod(int x) const {
34
+ return 2;
35
+ }
36
+
37
+ int constMethod(std::string val) const {
38
+ return val.size();
39
+ }
23
40
  };
24
41
  }
25
42
  #endif
data/test/modules_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Extension with modules" do
4
4
 
data/test/nested_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Wrapping Classes within classes" do
4
4
  def setup
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Extension with overloaded methods" do
4
4
 
@@ -24,10 +24,10 @@ context "Extension with overloaded methods" do
24
24
  end
25
25
 
26
26
  should.not.raise NameError do
27
- math.times.should == 1
28
- math.times_1(3).should == 3
29
- math.times_2(3,2).should == 6
30
- math.times_3(3,2,3).should == 18
27
+ math.times.should.equal 1
28
+ math.times_1(3).should.equal 3
29
+ math.times_2(3,2).should.equal 6
30
+ math.times_3(3,2,3).should.equal 18
31
31
  end
32
32
 
33
33
  should.not.raise NameError do
@@ -35,6 +35,13 @@ context "Extension with overloaded methods" do
35
35
  math.nothing_1(1)
36
36
  end
37
37
 
38
+ # Should properly handle const overloads as well
39
+ should.not.raise NameError do
40
+ math.const_method_0(1).should.equal 1
41
+ math.const_method_1(1).should.equal 2
42
+ math.const_method_2("love").should.equal 4
43
+ end
44
+
38
45
  end
39
46
 
40
47
  end
data/test/struct_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Nested Struct" do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Extension with class hierachies" do
4
4
 
data/test/test_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- $: << File.expand_path(File.dirname(__FILE__) + "/../lib")
1
+ $:.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
2
2
  $:.unshift File.expand_path(File.dirname(__FILE__) + "/generated")
3
3
 
4
4
  require 'rubygems'
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Properly build known required to_ruby and from_ruby methods" do
4
4
 
data/test/wrap_as_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  context "Ugly interfaces cleaner" do
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbplusplus
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.9"
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Roelofs
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-26 00:00:00 -04:00
12
+ date: 2009-12-14 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,27 @@ dependencies:
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 1.2.0
33
+ version: 1.3.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: test-unit
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.2.3
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: mocha
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: "0.9"
34
54
  version:
35
55
  description: |
36
56
  Rb++ combines the powerful query interface of rbgccxml and the Rice library to