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)
   output = "?"          ; coroutine.yield()
   output = math.sqrt(n) ; coroutine.yield()
end

function on.enterKey()
   coroutine.resume(co_test, 5, 10) -- resume するときに一緒に引数を渡す。
   platform.window:invalidate()
end
function on.mouseUp()
   on.enterKey()
end
function on.paint(gc)
   gc:drawString("What is the square root of "..(input or "_").." ?", 10, 10)
   gc:drawString(output or "_", 10, 30)
end

f:id:ti-nspire:20170728061731p:plain:w300