main.lua 796 B

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