Skip to content
IgorTimofeev edited this page Jan 9, 2019 · 7 revisions

This library provides an event system for registering specific event handlers. For example, it's used to automatically mount added filesystem components or to run some tasks regularly with specified interval. There's also important interrupting feature for instant killing not responding scripts.

event.pull(...): ...

Works the same way as computer.pullSignal(...) do, but also calls registered event handlers if needed and check interrupting status:

while true do
  local e1, e2, e4, e4 = event.pull()
  if e1 == "touch" then
    -- Do something when touch event was received
  end
end

event.addHandler(function handler[, int interval, int times]): int ID

Registers a new handler function, which will be analyzed for the need to run during each event.pull() call and returns internal handler ID. When handler is being run, it receives values returned from event.pull() as arguments.

You can specify an interval in seconds between each run of given handler. By default it's set to nil, i.e. handler will run every event.pull() call without any delay.

You can also specify number of times given handler will be run before being removed automatically. By default it's set to infinity.

event.addHandler(function(e1, e2, e3, e4))
  if e1 == "key_down" and e4 == 28 then
    -- Do someting every Return key press
  end
end)

event.addHandler(function()
  -- Do someting every 5 seconds
end, 5)

event.addHandler(function())
  -- Do someting every 5 seconds 10 times
end, 5, 10)

while true do
  event.pull()
end
Clone this wiki locally