adjustments: * Change the implementation of the "shadow" user data so that only users of this functionality pay for the extra overhead of a lua table for every watcher. * Simplify how a watcher is "checked" so that it simply looks for a magic key in the metatable to determine if it is of the right metatable. * Require libev 3.7 (print a warning if this version is not satisfied). This version is required in order to set userdata on an event loop. * Instead of having a separate watcher metatable, simply mix-in the watcher metatable methods. * Add note about calling ev_loop() directly from C. TODO: Is the loop specific shadow user data desired? If not, then the obj_index and obj_newindex should be renamed watcher_index and watcher_newindex.
The lua_State for running callbacks used to be stored in a thread-local variable initialized when loop:loop() was called. At some point this changed to be a lua_State that is stored (in watcher->data) when a watcher is created. This is almost always the wrong thing in an environment with coroutines. Instead, abuse the userdata slot in the loop object for this. Save off the old userdata before calling ev_loop(), set it to L, run ev_loop(), then restore it. This gets roughly the same effect as the old code without requiring any pthreads nastiness, since if you're running the same loop from two different threads at the same time you've already got a problem.