Skip to content

Commit

Permalink
Add type annotations to fix after breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed Apr 20, 2016
1 parent 6714caa commit ec4d334
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions examples/diagnostics.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require "crsfml/window"
require "crsfml/graphics"
require "crsfml/audio"

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

$window = SF::RenderWindow.new(
Expand Down
12 changes: 7 additions & 5 deletions examples/snakes.cr
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct Food
property position
property color

def initialize(@position, @color)
def initialize(@position : SF::Vector2(Int32), @color : SF::Color)
end

def draw(target, states)
Expand All @@ -36,9 +36,11 @@ struct Food
end

class Snake
getter body
@direction : SF::Vector2(Int32)

getter body : Array(SF::Vector2(Int32))

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

class Field
getter size
getter size : SF::Vector2(Int32)

def initialize(@size)
def initialize(@size : SF::Vector2(Int32))
@snakes = [] of Snake
@foods = [] of Food
end
Expand Down
1 change: 1 addition & 0 deletions examples/transformable.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "crsfml"


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

class Logo
Expand Down
4 changes: 4 additions & 0 deletions src/audio.cr
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ module SF
# :nodoc:
alias FuncBox = Box({(CSFML::SoundStreamChunk* -> CSFML::Bool), (Time -> Nil)})

@funcs = Pointer(Void).null

def initialize(channel_count : Int, sample_rate : Int)
@owned = true
@funcs = FuncBox.box({
Expand Down Expand Up @@ -98,6 +100,8 @@ module SF
# :nodoc:
alias FuncBox = Box({(-> CSFML::Bool), ((Int16*, LibC::SizeT) -> CSFML::Bool), (-> Nil)})

@funcs = Pointer(Void).null

def initialize()
@owned = true
@funcs = FuncBox.box({
Expand Down
6 changes: 3 additions & 3 deletions src/common_obj.cr
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ module SF

# Put the pointer into the wrapper object.
# The pointer will **not** be freed on GC.
def self.wrap_ptr(ptr : T)
def self.wrap_ptr(ptr : T) : self
new(ptr, false)
end

# Put the pointer into the wrapper object.
# The pointer will **not** be freed on GC.
#
# Returns nil instead of `null` pointer.
def self.wrap_ptr?(ptr : T)
def self.wrap_ptr?(ptr : T) : self?
ptr ? new(ptr, false) : nil
end

# Transfer ownership of the pointer to the wrapper object.
# The pointer will be freed on GC.
#
# Raises `NullResult` if the passed pointer is `null`.
def self.transfer_ptr(ptr : T)
def self.transfer_ptr(ptr : T) : self
raise NullResult.new unless ptr
new(ptr, true)
end
Expand Down
4 changes: 4 additions & 0 deletions src/system.cr
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ module SF
end

class Thread
@func = Pointer(Void).null

def initialize(function : ->)
@owned = true
@func = Box.box(function)
Expand Down Expand Up @@ -194,6 +196,8 @@ module SF
# :nodoc:
alias FuncBox = Box({((Void*, Int64) -> Int64), ((Int64) -> Int64), (-> Int64), (-> Int64)})

@funcs = Pointer(Void).null

def initialize
@funcs = FuncBox.box({
->(data: Void*, size: Int64) { read((data as Pointer(UInt8)).to_slice(size.to_i)).to_i64 },
Expand Down

0 comments on commit ec4d334

Please sign in to comment.