Aadvert

Snippet #41

Feb 12th, 2012
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1. -- Main function*
  2. local renderTimer;
  3. local bExit = false; -- TODO: move this up
  4. local events = {}
  5.  
  6. local timerEvents = {}
  7. local activeTimers = {}
  8. local function registerTimer(fFunct, nDelay)
  9.     local timerT = os.startTimer(nDelay)
  10.     timerEvents[fFunct] = nDelay
  11.     activeTimers[timerT] = fFunct
  12.     return timerT
  13. end
  14.  
  15. function events.timer(timerT)
  16.     if activeTimers[timerT] then
  17.         print("We has!")
  18.         if activeTimers[timerT]() then
  19.             print("It wants MOAR!")
  20.             activeTimers[os.startTimer(timerEvents[activeTimers[timerT]])] = activeTimers[timerT] -- Problem?
  21.             activeTimers[timerT] = nil
  22.         else
  23.             print("STOP! HAMM0R TIEM!")
  24.         end
  25.     end
  26. end
  27.  
  28. function events.char(sChar)
  29.     if sChar == "x" then
  30.         bExit = true
  31.         term.clear()
  32.         term.setCursorPos(1, 1)
  33.         print("Goodbye!")
  34.     end
  35. end
  36.  
  37. setmetatable(events, {__index = function(_, k) return function(...) print("Event: " .. k .. "; Args: ", unpack(arg)) end end})
  38. local function main(cmdArg)
  39.     --local opt = unnamed_function(cmdArg) -- TODO: find function name for this.
  40.     showSplash()
  41.     --loadConfig() --TODO: Impliment this
  42.    
  43.     -- Start render timer -- NEED TO DO BELOW getNode; until getNode uses not http.get
  44.     -- Get pluginz.
  45.     plib.getNode(config["sMasterLink"], pasteTree, true)
  46.     registerTimer(render, 0.1)
  47.     -- Could cache this, too.
  48.     term.setCursorPos(1,1)
  49.     while not bExit do
  50.         local sEvent, param1, param2 = os.pullEvent()
  51.         local eRes = events[sEvent] and events[sEvent](param1, param2)
  52.     end
  53. end
Advertisement
Add Comment
Please, Sign In to add comment