main.lua
Code: Select all
-- main
--here we create a thread using "print.lua"
thread = love.thread.newThread("print.lua")
--starting a new channel called "channel"
channel = love.thread.getChannel("create")
--starting the thread
thread:start()
--a variable to count
x = 1
while x < 100 do
x = x + 1
--here we are pushing to the channel, which the thread will recieve
channel:push({x,x+1,x+2,x+3,x+4})
end
--show how long the delay is from when the main program finishes
--to where the thread catches up
while thread:isRunning( ) == true do
love.timer.sleep(0.1)
print("print.lua is still running")
end
--shows when all threads are closed
print("print.lua is no longer running")
love.event.quit( )
Code: Select all
--print.lua
--here we get the channel that has already been created
channel = love.thread.getChannel("create")
--a random variable to repeat
repeatr = true
while repeatr == true do
--when queue count is depleted, break loop
if channel:getCount( ) == 0 then
repeatr = false
break
end
--here we recieve the variables from main.lua
local x = channel:pop()
--creating a string to display the table being sent
local str = ""
for i = 1,table.getn(x) do
str = str..tostring(x[i]).."|"
end
--printing the string
print(str.."\n")
--printing the queues remaining
print("queues:"..channel:getCount( ).."\n")
--channel:clear()
end
--the end of the print thread
print("end of print.lua")