Skip to content

Commit ec4d334

Browse files
committed
Add type annotations to fix after breaking change
1 parent 6714caa commit ec4d334

File tree

6 files changed

+20
-8
lines changed

6 files changed

+20
-8
lines changed

examples/diagnostics.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ require "crsfml/window"
33
require "crsfml/graphics"
44
require "crsfml/audio"
55

6+
$font : SF::Font
67
$font = SF::Font.from_file("resources/font/Ubuntu-R.ttf")
78

89
$window = SF::RenderWindow.new(

examples/snakes.cr

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct Food
2424
property position
2525
property color
2626

27-
def initialize(@position, @color)
27+
def initialize(@position : SF::Vector2(Int32), @color : SF::Color)
2828
end
2929

3030
def draw(target, states)
@@ -36,9 +36,11 @@ struct Food
3636
end
3737

3838
class Snake
39-
getter body
39+
@direction : SF::Vector2(Int32)
40+
41+
getter body : Array(SF::Vector2(Int32))
4042

41-
def initialize(@field, start, @color)
43+
def initialize(@field : Field, start, @color : SF::Color)
4244
@direction = Up
4345
@body = [] of SF::Vector2(Int32)
4446
(0...3).each do |i|
@@ -122,9 +124,9 @@ class Snake
122124
end
123125

124126
class Field
125-
getter size
127+
getter size : SF::Vector2(Int32)
126128

127-
def initialize(@size)
129+
def initialize(@size : SF::Vector2(Int32))
128130
@snakes = [] of Snake
129131
@foods = [] of Food
130132
end

examples/transformable.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require "crsfml"
22

33

4+
$font : SF::Font
45
$font = SF::Font.from_file("resources/font/Ubuntu-R.ttf")
56

67
class Logo

src/audio.cr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ module SF
7070
# :nodoc:
7171
alias FuncBox = Box({(CSFML::SoundStreamChunk* -> CSFML::Bool), (Time -> Nil)})
7272

73+
@funcs = Pointer(Void).null
74+
7375
def initialize(channel_count : Int, sample_rate : Int)
7476
@owned = true
7577
@funcs = FuncBox.box({
@@ -98,6 +100,8 @@ module SF
98100
# :nodoc:
99101
alias FuncBox = Box({(-> CSFML::Bool), ((Int16*, LibC::SizeT) -> CSFML::Bool), (-> Nil)})
100102

103+
@funcs = Pointer(Void).null
104+
101105
def initialize()
102106
@owned = true
103107
@funcs = FuncBox.box({

src/common_obj.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,23 @@ module SF
4242

4343
# Put the pointer into the wrapper object.
4444
# The pointer will **not** be freed on GC.
45-
def self.wrap_ptr(ptr : T)
45+
def self.wrap_ptr(ptr : T) : self
4646
new(ptr, false)
4747
end
4848

4949
# Put the pointer into the wrapper object.
5050
# The pointer will **not** be freed on GC.
5151
#
5252
# Returns nil instead of `null` pointer.
53-
def self.wrap_ptr?(ptr : T)
53+
def self.wrap_ptr?(ptr : T) : self?
5454
ptr ? new(ptr, false) : nil
5555
end
5656

5757
# Transfer ownership of the pointer to the wrapper object.
5858
# The pointer will be freed on GC.
5959
#
6060
# Raises `NullResult` if the passed pointer is `null`.
61-
def self.transfer_ptr(ptr : T)
61+
def self.transfer_ptr(ptr : T) : self
6262
raise NullResult.new unless ptr
6363
new(ptr, true)
6464
end

src/system.cr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ module SF
166166
end
167167

168168
class Thread
169+
@func = Pointer(Void).null
170+
169171
def initialize(function : ->)
170172
@owned = true
171173
@func = Box.box(function)
@@ -194,6 +196,8 @@ module SF
194196
# :nodoc:
195197
alias FuncBox = Box({((Void*, Int64) -> Int64), ((Int64) -> Int64), (-> Int64), (-> Int64)})
196198

199+
@funcs = Pointer(Void).null
200+
197201
def initialize
198202
@funcs = FuncBox.box({
199203
->(data: Void*, size: Int64) { read((data as Pointer(UInt8)).to_slice(size.to_i)).to_i64 },

0 commit comments

Comments
 (0)