ymobe / rapanui

High level API for MOAI framework
185 stars 48 forks source link

Coroutine utility #88

Open MattiaFortunati opened 11 years ago

MattiaFortunati commented 11 years ago

It would be nice to have a global utility function to perform operations as coroutines, like:

function performAsCoroutine(_function, _param) local thread = MOAICoroutine.new() thread:run(_function, _param) end

so in the _function we can use coroutine.yield()

I already use this method in my projects , passing the other function to execute at the end of _function as _param.

like:

function performAsCoroutine(_function, _param) local thread = MOAICoroutine.new() thread:run(_function, _param) end

function toPerformAfterCoroutine() print("coroutine finished") end

function fCoroutine(nextFunction) --do something coroutine.yield() --other coroutine.yield() --other coroutine.yield()

nextFunction() end

performAsCoroutine(fCoroutine, toPerformAfterCoroutine)

EDIT:

A sample would be nice, too. A loading bar sample would be great. For a loading bar we should have two coroutines: one for the the loading bar each step moving and yielding, one for the GUI loading one piece and then yielding.