Corope - Lua Threading Library
Posted: Mon Sep 19, 2016 1:46 am
Corope
GITHUB
Corope is a Lua Library to help organize your async code. Write AI behaviors and animations in a natural, synchronous style instead
of worrying about timers and callbacks. Corope also provides utilities for tweening and parallel processing.
If that's not exactly clear, examples are worth 1000 words.
Corope can do more than just this, and the API and code are on Github.
This was the result of some work on messing around with coroutines for asynchronous programming with an event loop. I took some of the techniques I learned from my work on moonmint, my standalone Lua HTTP server (which I'm also currently using to host my website). A similar technique is actually used on itch.io (see the article here), and in weblit, a proof of concept web framework by the author of Luvit. I thought that if it works so well for the web, why not in games?
GITHUB
Corope is a Lua Library to help organize your async code. Write AI behaviors and animations in a natural, synchronous style instead
of worrying about timers and callbacks. Corope also provides utilities for tweening and parallel processing.
If that's not exactly clear, examples are worth 1000 words.
Code: Select all
-- Require the module and create our bundle object
local corope = require 'corope'
local bundle = corope()
function love.update(dt)
bundle:update(dt)
end
-- Run this asynchronously
bundle(function(rope)
rope:wait(0.5) -- wait half a second
for i = 1, 10 do
print(i)
rope:wait(1)
end
end)
-- Also run this asynchronously
bundle(function(rope)
for i = 1, 10 do
print('Hey! ' .. i)
rope:wait(1)
end
end)
This was the result of some work on messing around with coroutines for asynchronous programming with an event loop. I took some of the techniques I learned from my work on moonmint, my standalone Lua HTTP server (which I'm also currently using to host my website). A similar technique is actually used on itch.io (see the article here), and in weblit, a proof of concept web framework by the author of Luvit. I thought that if it works so well for the web, why not in games?