Document changes due to issue #60

This commit is contained in:
Matthias Richter 2016-05-01 14:56:12 +02:00
parent 8435fc798f
commit dff00cc1dc
2 changed files with 27 additions and 16 deletions

View File

@ -18,7 +18,7 @@ signals that match a `Lua string pattern
**Example**:: **Example**::
-- in AI.lua -- in AI.lua
signals.register('shoot', function(x,y, dx,dy) Signal.register('shoot', function(x,y, dx,dy)
-- for every critter in the path of the bullet: -- for every critter in the path of the bullet:
-- try to avoid being hit -- try to avoid being hit
for critter in pairs(critters) do for critter in pairs(critters) do
@ -29,7 +29,7 @@ signals that match a `Lua string pattern
end) end)
-- in sounds.lua -- in sounds.lua
signals.register('shoot', function() Signal.register('shoot', function()
Sounds.fire_bullet:play() Sounds.fire_bullet:play()
end) end)
@ -38,7 +38,7 @@ signals that match a `Lua string pattern
if key == ' ' then if key == ' ' then
local x,y = player.pos:unpack() local x,y = player.pos:unpack()
local dx,dy = player.direction:unpack() local dx,dy = player.direction:unpack()
signals.emit('shoot', x,y, dx,dy) Signal.emit('shoot', x,y, dx,dy)
end end
end end
@ -57,6 +57,11 @@ global registry. Likewise, the global registry does not affect the instance.
If you don't need multiple independent registries, you can use the If you don't need multiple independent registries, you can use the
global/default registry (see examples). global/default registry (see examples).
.. note::
Unlike the default one, signal registry instances use the colon-syntax,
i.e., you need to call ``instance:emit('foo', 23)`` instead of
``Signal.mit('foo', 23)``.
**Example**:: **Example**::
player.signals = Signal.new() player.signals = Signal.new()
@ -81,7 +86,7 @@ Registers a function ``f`` to be called when signal ``s`` is emitted.
:: ::
menu.register('key-left', select_previous_item) menu:register('key-left', select_previous_item)
.. function:: Signal.emit(s, ...) .. function:: Signal.emit(s, ...)
@ -97,7 +102,7 @@ Calls all functions bound to signal ``s`` with the supplied arguments.
function love.keypressed(key) function love.keypressed(key)
-- using a signal instance -- using a signal instance
if key == 'left' then menu.emit('key-left') end if key == 'left' then menu:emit('key-left') end
end end
:: ::
@ -176,5 +181,5 @@ Removes **all** functions from all signals that match a `Lua string pattern
:: ::
player.signals.clearPattern('.*') -- clear all signals player.signals:clearPattern('.*') -- clear all signals

View File

@ -42,6 +42,11 @@ the global timer. Likewise, the global timer does not affect timer instances.
If you don't need multiple independent schedulers, you can use the If you don't need multiple independent schedulers, you can use the
global/default timer (see examples). global/default timer (see examples).
.. note::
Unlike the default timer, timer instances use the colon-syntax, i.e.,
you need to call ``instance:after(1, foo)`` instead of ``Timer.after(1,
foo)``.
**Example**:: **Example**::
menuTimer = Timer.new() menuTimer = Timer.new()
@ -79,7 +84,7 @@ periodic behavior (see the example).
:: ::
--Using a timer instance: --Using a timer instance:
menuTimer.after(1, finishAnimation) menuTimer:after(1, finishAnimation)
.. function:: Timer.script(func) .. function:: Timer.script(func)
@ -87,8 +92,9 @@ periodic behavior (see the example).
:param function func: Script to execute. :param function func: Script to execute.
Execute a function that can be paused without causing the rest of the program to Execute a function that can be paused without causing the rest of the program to
be suspended. ``func`` will receive a function - ``wait`` - to do that as only be suspended. ``func`` will receive a function - ``wait`` - to do interrupt the
argument. script (but not the whole program) as only argument. The function prototype of
wait is: ``wait(delay)``.
**Examples**:: **Examples**::
@ -122,7 +128,7 @@ argument.
:: ::
-- jumping with timer.script -- jumping with timer.script
timer.script(function(wait) self.timers:script(function(wait)
local w = 1/12 local w = 1/12
self.jumping = true self.jumping = true
Timer.tween(w*2, self, {z = -8}, "out-cubic", function() Timer.tween(w*2, self, {z = -8}, "out-cubic", function()
@ -167,7 +173,7 @@ or :func:`Timer.cancel` or :func:`Timer.clear` is called on the timer instance.
:: ::
-- launch 5 fighters in quick succession (using a timer instance) -- launch 5 fighters in quick succession (using a timer instance)
mothership_timer.every(0.3, function() self:launchFighter() end, 5) mothership_timer:every(0.3, function() self:launchFighter() end, 5)
:: ::
@ -217,7 +223,7 @@ seconds have passed.
player.isInvincible = true player.isInvincible = true
-- flash player for 3 seconds -- flash player for 3 seconds
local t = 0 local t = 0
player.timer.during(3, function(dt) player.timer:during(3, function(dt)
t = t + dt t = t + dt
player.visible = (t % .2) < .1 player.visible = (t % .2) < .1
end, function() end, function()
@ -248,9 +254,9 @@ Prevent a timer from being executed in the future.
function tick() function tick()
print('tick... tock...') print('tick... tock...')
end end
handle = menuTimer.every(1, tick) handle = menuTimer:every(1, tick)
-- later -- later
menuTimer.cancel(handle) menuTimer:cancel(handle)
.. function:: Timer.clear() .. function:: Timer.clear()
@ -264,7 +270,7 @@ executed will discarded.
:: ::
menuTimer.clear() menuTimer:clear()
.. function:: Timer.update(dt) .. function:: Timer.update(dt)
@ -285,7 +291,7 @@ Update timers and execute functions if the deadline is reached. Call in
-- using hump.gamestate and a timer instance -- using hump.gamestate and a timer instance
function menuState:update(dt) function menuState:update(dt)
self.timer.update(dt) self.timers:update(dt)
end end