wrap() function makes a coroutine and gives back a function. When that function is called, it resumes the coroutine.
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.
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!
Learn Lua on Codecademy
Computer ScienceLooking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
Includes 6 Courses
With Professional Certification
Beginner Friendly82 Lessons