main.lua 891 B

12345678910111213141516171819202122232425262728293031323334353637
  1. function lovr.load()
  2. -- This holds the thread code
  3. -- This must be wrapped with [[]] or '' to allow the engine to run it as Lua
  4. threadCode = [[
  5. local lovr = {}
  6. lovr.thread = require 'lovr.thread'
  7. lovr.timer = require 'lovr.timer'
  8. local channel = lovr.thread.getChannel('test')
  9. local x = 0
  10. while true do
  11. x = x + 1
  12. channel:push(x)
  13. lovr.timer.sleep(.1)
  14. end
  15. ]]
  16. -- Create a new test channel
  17. channel = lovr.thread.getChannel('test')
  18. -- Create a new thread called 'thread' using the code above
  19. thread = lovr.thread.newThread(threadCode)
  20. -- Start the thread
  21. thread:start()
  22. end
  23. function lovr.update(dt)
  24. -- Read and delete any messages in the queue
  25. while channel:peek() do
  26. message = channel:pop()
  27. end
  28. end
  29. function lovr.draw(pass)
  30. -- Display the message on screen/headset
  31. pass:text(tostring(message), 0, 1.7, -5)
  32. end