Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Commit

Permalink
Test when Sprite.events are created just when the sprite is being closed
Browse files Browse the repository at this point in the history
As app 'sitechange' event is generated when we close a sprite,
accessing Sprite.events on that event will re-create the
app::script::SpriteEvents instance associated with the sprite.
  • Loading branch information
dacap committed Jul 16, 2022
1 parent a03ff22 commit 02a2f1f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions scripts/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,28 @@ do
-- listener instead of doing nothing.
expect_eq(2, i)
end

-- Accessing Sprite.events when closing the same sprite will call
-- push_sprite_events() creating a new app::script::SpriteEvents
-- instance again even when we've just destroyed the old one (because
-- we're just closing the sprite).
do
local s = Sprite(32, 32)
function onSpriteChange()
-- Do nothing
end
-- Here we access s.events for first time, creating the
-- app::script::SpriteEvents for this sprite.
s.events:on('change', onSpriteChange)
function onSiteChange()
-- Accessing s.events again on 'sitechange' when we're just
-- closing the sprite, re-generating its SpriteEvents instance.
-- We've to have special care of this case.
s.events:off(onSpriteChange)
end
app.events:on('sitechange', onSiteChange)
-- Closing the sprite will create a 'sitechange' event calling
-- onSiteChange() function.
s:close()
app.events:off(onSiteChange)
end

0 comments on commit 02a2f1f

Please sign in to comment.