Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Test()
- print("hello, ", CurTime())
- local x = 0
- while true do
- x = x + 1
- print("world ", CurTime(x))
- coroutine.yield()
- end
- end
- -- same output, doesn't matter if the env is is is not set.
- setfenv(Test, {
- coroutine = table.Copy(coroutine),
- print = print,
- CurTime = CurTime
- })
- local co = coroutine.create(Test)
- concommand.Add("co_resume",
- function ()
- print("resuming at " .. CurTime())
- print(coroutine.resume(co))
- end
- )
- --[[
- http://i.imgur.com/KEAiq.png
- Running script autorun/server/co_test.lua...
- ] co_resume
- resuming at 839.35498046875
- hello, 1.1195346664694e-088
- world 1
- true
- ] co_resume
- resuming at 840.05999755859
- world 2
- true
- ] co_resume
- resuming at 840.88500976563
- world 3
- true
- ] lua_run print(CurTime(5))
- > print(CurTime(5))...
- 863.65496826172
- ] lua_run print(CurTime(5))
- > print(CurTime(5))...
- 864.19500732422
- ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement