lib/rbplusplus/builders/director.rb in rbplusplus-0.9 vs lib/rbplusplus/builders/director.rb in rbplusplus-0.9.1
- old
+ new
@@ -50,20 +50,10 @@
def wrap_constructor(constructor)
@constructors << constructor
end
- def write_class_registration
- # Need to tell Rice of the base class, while also making sure that if there's a superclass to this class
- # that we know about it, or attempts to use polymorphism will crash with 'unknown caster for {superclass}
- class_names = [@class_qualified_name]
- class_names << @superclass.qualified_name if @superclass && !do_not_wrap?(@superclass)
- class_names = class_names.join(",")
-
- self.parent.registrations << "Rice::define_class< #{class_names} >(\"__#{@class_base_name}__\");"
- end
-
def write_constructor(constructor = nil)
args = ["Rice::Object self"]
types = [@name, "Rice::Object"]
supercall_args = []
@@ -77,10 +67,12 @@
supercall_args << name
end
end
declarations << "#{@name}(#{args.join(", ")}) : #{@class_qualified_name}(#{supercall_args.join(", ")}), Rice::Director(self) { }"
+
+ registrations << "#{self.parent.rice_variable}.define_director< #{@name} >();"
registrations << "#{self.parent.rice_variable}.define_constructor(Rice::Constructor< #{types.join(", ")} >());"
end
def write
declarations << "class #{@name} : public #{@class_qualified_name}, public Rice::Director {"
@@ -113,11 +105,11 @@
reverse = ""
up_or_raise =
if method.default_return_value
reverse = "!"
- "return #{method.default_return_value};"
+ "return #{method.default_return_value}"
else
if method.purely_virtual?
"raisePureVirtual()"
else
"#{return_call} this->#{method.qualified_name}(#{call_arguments.join(", ")})"
@@ -127,17 +119,22 @@
call_down = "getSelf().call(\"#{ruby_name}\"#{call_arguments.empty? ? "" : ", "}#{call_arguments.map {|a| "to_ruby(#{a})" }.join(", ")})"
call_down = "return from_ruby< #{return_type} >( #{call_down} )" if return_type != "void"
const = method.const? ? "const" : ""
+ # Write out the virtual method that forwards calls into Ruby
declarations << ""
- declarations << "#{return_type} #{cpp_name}(#{def_arguments}) #{const} {"
- declarations << "if(#{reverse}callIsFromRuby(\"#{ruby_name}\")) {"
- declarations << "#{up_or_raise};"
- declarations << "} else {"
+ declarations << "virtual #{return_type} #{cpp_name}(#{def_arguments}) #{const} {"
declarations << "#{call_down};"
declarations << "}"
+
+ # Write out the wrapper method that gets exposed to Ruby that handles
+ # going up the inheritance chain
+ declarations << ""
+ declarations << "#{return_type} default_#{cpp_name}(#{def_arguments}) #{const} {"
+ declarations << "#{up_or_raise};"
declarations << "}"
+
end
declarations << "};"
end