Timers problem

If I run 2 or more timers they won’t work. Script example:

function tmr1()
  while true do
    print(“timer 1”)
    wait(50)  
  end
end

function tmr2()
  while true do
    print(“timer 2”)
    wait(100)  
  end
end

run(tmr1); run(tmr2)

It’s caused by mistake in register() function in src_lua/scheduling.lua. If there is any timer already registered all others will be given wrong event name in proc array:

local function register (cell, ...)
….
--------------------------------------------------------------------
   -- 2 - register timer events
   --------------------------------------------------------------------
   for _, event in ipairs(events) do
      if type(event)=='number' then
         local t = internal.set_timer(event)
         if not ptwt then -- no timer queue at all
            ptwt={ [t] = { cell } }
            ptw.timer=ptwt 
         else -- there is a timer queue...
            local evq = ptwt[event]		-- should be ptwt[t] ?
            if not evq then -- ...but no sub-queue for that timer event
               evq = { cell };  ptwt[event] = evq		-- should be ptwt[t] ?
            else  -- there is already a queue for that timer event, append
               table.insert(evq, cell) 
            end
         end -- timer events queue
         trace("Registered cell for event timer."..t)
      end
   end
…..
end

Instead of ptwt[event] should be ptwt[t]. Am I right?
I hope it will be fixed soon while there’s no latest Lua version source code available.

You seem to be right. Sources have been put online, so I guess you’ll soon be unstuck; your fix will be integrated in the next release.

Incidentally, notice that you could have fixed this even without oatlua sources: you could have overloaded the default scheduler.lua by reloading your own version together with your application (at the price of some flash resources).

(just to remind people that dynamic code is cool :slight_smile:)