main.lua 770 B

1234567891011121314151617181920212223242526272829303132
  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 = { thread = require 'lovr.thread' }
  6. local channel = lovr.thread.getChannel('test')
  7. local x = 0
  8. while true do
  9. x = x + 1
  10. channel:push(x)
  11. end
  12. ]]
  13. -- Create a new test channel
  14. channel = lovr.thread.getChannel('test')
  15. -- Create a new thread called 'thread' using the code above
  16. thread = lovr.thread.newThread(threadCode)
  17. -- Start the thread
  18. thread:start()
  19. end
  20. function lovr.update(dt)
  21. -- Read and delete the message
  22. message = channel:pop()
  23. end
  24. function lovr.draw(pass)
  25. -- Display the message on screen/headset
  26. pass:text(tostring(message), 0, 1.7, -5)
  27. end