Skip to content

Commit

Permalink
Fix #dup for types which can refer to its owner by reference
Browse files Browse the repository at this point in the history
Fixes #34.
  • Loading branch information
oprypin committed May 14, 2020
1 parent 2b5dafd commit 79249b3
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 122 deletions.
6 changes: 3 additions & 3 deletions generate.cr
Original file line number Diff line number Diff line change
Expand Up @@ -572,14 +572,14 @@ class CClass < CNamespace
end
end

unless has_module?("NonCopyable") || has_module?("RenderTarget") || has_module?("AlResource") || module?
unless has_module?("NonCopyable") || has_module?("RenderTarget") || has_module?("AlResource") || module? || abstract?
CFunction.new(@name.not_nil!, type: nil,
parameters: [CParameter.new("copy", CType.new(self, reference: true, const: true))],
visibility: Visibility::Public, parent: self, docs: [":nodoc:"]
).render(context, o)
if context.crystal?
o<< "def dup() : self"
o<< "return typeof(self).new(self)"
o<< "def dup() : #{name(Context::Crystal)}"
o<< "return #{name(Context::Crystal)}.new(self)"
o<< "end"
end
end
Expand Down
29 changes: 29 additions & 0 deletions spec/view_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require "spec"
require "../src/graphics"

describe SF::View do
describe "#dup" do
it "works from a Reference (#34)" do
w = SF::RenderTexture.new
w.view = SF::View.new(SF.float_rect(1, 2, 3, 4))
v = w.view.dup
v.size.should eq SF.vector2(3, 4)
end

it "works as a class member (#34)" do
v = ViewDupTest.new.view_dup
v.size.should eq SF.vector2(3, 4)
end
end
end

class ViewDupTest
def initialize
@view = SF::View.new(SF.float_rect(1, 2, 3, 4))
end

def view_dup
@view.dup
end
end

3 changes: 0 additions & 3 deletions src/graphics/ext.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/graphics/lib.cr

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 38 additions & 47 deletions src/graphics/obj.cr

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions src/network/obj.cr

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/system/ext.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/system/lib.cr

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 79249b3

Please sign in to comment.