Advertisement
Guest User

thread.lua

a guest
Nov 25th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.80 KB | None | 0 0
  1. thread = require("thread")
  2. event = require("event")
  3. serial = require("serialization")
  4.  
  5. eventsTable ={}
  6.  
  7. --------------------------------------------
  8.  
  9. function ioFile(name,action,data)
  10.   if action == "w" then
  11.     local wfile=io.open(name,action)
  12.     wfile:write(serial.serialize(data))
  13.     wfile:close()
  14.   elseif action == "r" then
  15.     local rfile=io.open(name,action)
  16.     returnedData = serial.unserialize(rfile:read())
  17.     rfile:close()
  18.     return returnedData
  19.   end
  20. end
  21.  
  22. eventLogging = function()
  23.  local j = 0
  24.   while true do
  25.     id,x2,x3,x4,x5,x6,x7,x8 = event.pull()
  26.     j=j+1
  27.     eventsTable[id] = j
  28.     ioFile("events","w",eventsTable)
  29.   end
  30. end
  31.  
  32.  
  33. local yourBackgroundProcess = thread.create(eventLogging)
  34. yourBackgroundProcess:detach()
  35.  
  36. while true do
  37.   os.sleep(30)
  38.   yourBackgroundProcess:kill()
  39.   break
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement