Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use main thread of current Lua state for callbacks, when known
If the library is opened from a Lua thread (coroutine) that is not the main one, the stored L would be to that thread, which may become suspended (by calling yield). It is unsafe to call functions on suspended Lua threads, which luv does a lot (the stored L is used for callbacks). The main thread of a Lua state can never yield, so it is always safe to call callbacks on. This commit ensures the main thread is stored in the luv context instead of the current thread, when we are able to calculate it (LUA_RIDX_MAINTHREAD was added in Lua 5.2, and I have not found a way to determine the main thread in Lua 5.1). This fixes #503
- Loading branch information