From de54cc14ae2298865b18c204a7094ff2204545fd Mon Sep 17 00:00:00 2001 From: Stefan Merettig Date: Thu, 9 Nov 2017 00:01:35 +0100 Subject: [PATCH] Compatibility for Crystal 0.23.1 and later versions at once In versions after Crystal 0.23.1, Object#hash was changed to return an UInt64 instead of a Int32. This patch always forces hashes to use UInt64. --- src/cute.cr | 12 ++++++++---- src/cute/signal.cr | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/cute.cr b/src/cute.cr index f4ac65d..686fb00 100644 --- a/src/cute.cr +++ b/src/cute.cr @@ -8,6 +8,10 @@ require "./cute/version" # Easy to use event-oriented publisher/subscribe modelled after the # Qt Framework. module Cute + # Type of a connection handle, as returned by the `#on` method of signals and + # `#add` of middlewares. + alias ConnectionHandle = UInt64 + # Creates a *signal*. A signal manages listeners (So called *slots*), which # will be called when an event has been *emitted*. Emitting is the act of # triggering a signal to announce an event to the listeners. @@ -246,15 +250,15 @@ module Cute end # Appends a middleware handler - def add(&block : Handler) + def add(&block : Handler) : ::Cute::ConnectionHandle @listeners << block - block.hash + block.hash.to_u64 end # Appends *handler* - def add(handler : Handler) + def add(handler : Handler) : ::Cute::ConnectionHandle @listeners << handler - handler.hash + handler.hash.to_u64 end # Calls the middleware chain. diff --git a/src/cute/signal.cr b/src/cute/signal.cr index a71a53e..a124932 100644 --- a/src/cute/signal.cr +++ b/src/cute/signal.cr @@ -54,9 +54,9 @@ module Cute {{ call.name.stringify }} end - def on(&block : {{ handler_type.id }}) + def on(&block : {{ handler_type.id }}) : ::Cute::ConnectionHandle @listeners << block - block.hash + block.hash.to_u64 end def on(sink : Cute::Sink(U)) forall U @@ -81,7 +81,7 @@ module Cute {% if async %}end{% end %} end - def new_channel : Tuple({{ channel_type.id }}, Int32) + def new_channel : Tuple({{ channel_type.id }}, ::Cute::ConnectionHandle) ch = {{ channel_type.id }}.new handle = {% if call.args.empty? %}