wrap()
krushnarout8 total contributions
Published Oct 17, 2023
Contribute to Docs
The wrap()
function makes a coroutine and gives back a function. When that function is called, it resumes the coroutine.
Syntax
coroutine.wrap(function)
wrap()
is a function in Lua that creates a coroutine and returns a function that, when called, resumes the coroutine.- It is similar to
coroutine.create()
, but instead of returning the coroutine itself, it returns a function that can be called multiple times to resume the coroutine.
Example
This example utilizes the wrap()
function to execute a wrapped coroutine, printing a specific message.
function myCoroutine()print("Hello from coroutine wrap!")endlocal wrappedCoroutine = coroutine.wrap(myCoroutine)wrappedCoroutine()
This will output:
Hello from coroutine wrap!
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.