Difference between revisions of "Testovací stránka"
Jump to navigation
Jump to search
(Založena nová stránka s textem „==== Toto je testovací stránka ====“) |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
==== Toto je testovací stránka ==== | ==== Toto je testovací stránka ==== | ||
+ | <syntaxhighlight lang="lua"> | ||
+ | function foo (a) | ||
+ | print("foo", a) | ||
+ | return coroutine.yield(2*a) | ||
+ | end | ||
+ | |||
+ | co = coroutine.create(function (a,b) | ||
+ | print("co-body", a, b) | ||
+ | local r = foo(a+1) | ||
+ | print("co-body", r) | ||
+ | local r, s = coroutine.yield(a+b, a-b) | ||
+ | print("co-body", r, s) | ||
+ | return b, "end" | ||
+ | end) | ||
+ | |||
+ | print("main", coroutine.resume(co, 1, 10)) | ||
+ | print("main", coroutine.resume(co, "r")) | ||
+ | print("main", coroutine.resume(co, "x", "y")) | ||
+ | print("main", coroutine.resume(co, "x", "y")) | ||
+ | </syntaxhighlight> |
Latest revision as of 17:00, 31 August 2016
Toto je testovací stránka
<syntaxhighlight lang="lua"> function foo (a)
print("foo", a) return coroutine.yield(2*a) end co = coroutine.create(function (a,b) print("co-body", a, b) local r = foo(a+1) print("co-body", r) local r, s = coroutine.yield(a+b, a-b) print("co-body", r, s) return b, "end" end) print("main", coroutine.resume(co, 1, 10)) print("main", coroutine.resume(co, "r")) print("main", coroutine.resume(co, "x", "y")) print("main", coroutine.resume(co, "x", "y"))
</syntaxhighlight>