Page 1 of 1

Corope - Lua Threading Library

Posted: Mon Sep 19, 2016 1:46 am
by bakpakin
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.

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)
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?

Re: Corope - Lua Threading Library

Posted: Wed Sep 21, 2016 8:29 pm
by Ikroth
This library looks super cool, I recently read your article on coroutines and I have been meaning to give them a try in LOVE. Do you have any other examples of this library, or examples of code similar to this library?

Re: Corope - Lua Threading Library

Posted: Fri Sep 23, 2016 3:37 pm
by bakpakin
I have posted an example using love in the repository. For examples with similar usage, your can checkout weblit, xavante, and lua-copas for examples from the Lua world.

Also, for clarification, the linked article is not my article, it is just a good article, and I am not affiliated with itch.io. I'm not sure if the previous post suggested that :)

Re: Corope - Lua Threading Library

Posted: Fri Sep 23, 2016 11:20 pm
by Ikroth
bakpakin wrote:I have posted an example using love in the repository. For examples with similar usage, your can checkout weblit, xavante, and lua-copas for examples from the Lua world.

Also, for clarification, the linked article is not my article, it is just a good article, and I am not affiliated with itch.io. I'm not sure if the previous post suggested that :)
Sorry, I got my names mixed up. Regardless, this is a good idea. I didn't see the example before, thanks I will examine this more closely.

Re: Corope - Lua Threading Library

Posted: Sat Oct 15, 2016 10:54 am
by pevzi
I was just thinking recently about making a similar library. I love the non-blocking tween method but the tween API itself could be better imo. Any other tween lib allows you to change several fields of an object at once, which is really useful for tweening object position or color.

On a side note, I'm still hesitant to leverage coroutines for everything throughout the game because I'm not sure if it is possible to implement game saving when every entity in the game lives by a coroutine which needs to be serialized with its current state somehow. Do you know of any solution?