The Squirrel interpreter. See http://www.squirrel-lang.org/
samples/coroutines.nut@3:7268a3ceaffc, 2014-12-16 (annotated)
- Committer:
- jhnwkmn
- Date:
- Tue Dec 16 11:39:42 2014 +0000
- Revision:
- 3:7268a3ceaffc
- Parent:
- 0:97a4f8cc534c
Accepts \r as line terminator as well.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jhnwkmn | 0:97a4f8cc534c | 1 | function coroutine_test(a,b) |
jhnwkmn | 0:97a4f8cc534c | 2 | { |
jhnwkmn | 0:97a4f8cc534c | 3 | ::print(a+" "+b+"\n"); |
jhnwkmn | 0:97a4f8cc534c | 4 | local ret = ::suspend("suspend 1"); |
jhnwkmn | 0:97a4f8cc534c | 5 | ::print("the coroutine says "+ret+"\n"); |
jhnwkmn | 0:97a4f8cc534c | 6 | ret = ::suspend("suspend 2"); |
jhnwkmn | 0:97a4f8cc534c | 7 | ::print("the coroutine says "+ret+"\n"); |
jhnwkmn | 0:97a4f8cc534c | 8 | ret = ::suspend("suspend 3"); |
jhnwkmn | 0:97a4f8cc534c | 9 | ::print("the coroutine says "+ret+"\n"); |
jhnwkmn | 0:97a4f8cc534c | 10 | return "I'm done" |
jhnwkmn | 0:97a4f8cc534c | 11 | } |
jhnwkmn | 0:97a4f8cc534c | 12 | |
jhnwkmn | 0:97a4f8cc534c | 13 | local coro = ::newthread(coroutine_test); |
jhnwkmn | 0:97a4f8cc534c | 14 | |
jhnwkmn | 0:97a4f8cc534c | 15 | local susparam = coro.call("test","coroutine"); //starts the coroutine |
jhnwkmn | 0:97a4f8cc534c | 16 | |
jhnwkmn | 0:97a4f8cc534c | 17 | local i = 1; |
jhnwkmn | 0:97a4f8cc534c | 18 | do |
jhnwkmn | 0:97a4f8cc534c | 19 | { |
jhnwkmn | 0:97a4f8cc534c | 20 | ::print("suspend passed ["+susparam+"]\n") |
jhnwkmn | 0:97a4f8cc534c | 21 | susparam = coro.wakeup("ciao "+i); |
jhnwkmn | 0:97a4f8cc534c | 22 | ++i; |
jhnwkmn | 0:97a4f8cc534c | 23 | }while(coro.getstatus()=="suspended") |
jhnwkmn | 0:97a4f8cc534c | 24 | |
jhnwkmn | 0:97a4f8cc534c | 25 | ::print("return passed ["+susparam+"]\n") |