コルーチン

TI-Nspire & Lua / コルーチン 6 / yield の引数が resume の返値になる

結局何に使うのかわからない。 function test() for i = 1, 3 do coroutine.yield("stopped at", i) end end co = coroutine.create(test) for i = 1, 7 do print(coroutine.resume(co)) -- resume は、resume に成功したかどうかを示す true/false を返すほ…

TI-Nspire & Lua / コルーチン 5 / resume するときに coroutine に引数を渡す

参考: はじめてのLuaプログラミング―人気の軽量スクリプトでアプリケーション開発! (I・O BOOKS) function test(from, to) while true do for i = from, to do input = i calcRoot(i) end end end co_test = coroutine.create(test) function calcRoot(n) ou…

TI-Nspire & Lua / コルーチン 4 / 他の函数から間接的に中断する

参考: はじめての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 = "?" …

TI-Nspire & Lua / コルーチン 3 / 他の函数から間接的に再開する

参考: はじめてのLuaプログラミング―人気の軽量スクリプトでアプリケーション開発! (I・O BOOKS), pp.260-276 function on.construction() var.store("k", 0) end function test() while true do for i = 1, 5, 1 do var.store("k", i) coroutine.yield() en…

TI-Nspire & Lua / コルーチン 2 / ループの中断と再開とを繰り返す

参考: Programming in Lua プログラミング言語Lua公式解説書, pp.99-113 function test() for i = 1, 3 do print(i) coroutine.yield() end end co = coroutine.create(test) coroutine.resume(co) -- コルーチンを開始し、"1" をプリントし、コルーチンを中…

TI-Nspire & Lua / コルーチン 1 / コルーチンを作って開始する

参考: Programming in Lua プログラミング言語Lua公式解説書, pp.99-113 co = coroutine.create(function() print("hello, world") end) -- coroutine.create(函数) という構文でコルーチンを作成する。 print(co) -- 返値はスレッド (1) print(coroutine.st…