参考: はじめてのLuaプログラミング―人気の軽量スクリプトでアプリケーション開発! (I・O BOOKS)
function test() while true do for i = 1, 10 do input = i calcRoot(i) end end end co_test = coroutine.create(test) function calcRoot(n) output = "?" ; coroutine.yield() -- こっちでコルーチンを中断する。 output = math.sqrt(n) ; coroutine.yield() -- こっちでコルーチンを中断する。 end function on.enterKey() coroutine.resume(co_test) platform.window:invalidate() end function on.mouseUp() coroutine.resume(co_test) platform.window:invalidate() end function on.paint(gc) gc:drawString("What is the square root of "..(input or "_").." ?", 10, 10) gc:drawString(output or "_", 10, 30) end