Corope - Lua Threading Library

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
bakpakin
Party member
Posts: 114
Joined: Sun Mar 15, 2015 9:29 am
Location: Boston

Corope - Lua Threading Library

Post 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?
((_((_CRAYOLA_((_((_> GitHub <_((_((_CRAYOLA_((_(()
User avatar
Ikroth
Citizen
Posts: 79
Joined: Thu Jul 18, 2013 4:44 am

Re: Corope - Lua Threading Library

Post 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?
User avatar
bakpakin
Party member
Posts: 114
Joined: Sun Mar 15, 2015 9:29 am
Location: Boston

Re: Corope - Lua Threading Library

Post 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 :)
((_((_CRAYOLA_((_((_> GitHub <_((_((_CRAYOLA_((_(()
User avatar
Ikroth
Citizen
Posts: 79
Joined: Thu Jul 18, 2013 4:44 am

Re: Corope - Lua Threading Library

Post 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.
pevzi
Prole
Posts: 27
Joined: Tue Apr 02, 2013 4:09 pm
Contact:

Re: Corope - Lua Threading Library

Post 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?
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests