 +#else
 +  HANDLE pid, fstdin, fstdout, fstderr;
 +#endif
-+#if GTK
++#if (GTK && !__APPLE__)
 +  GIOChannel *cstdout, *cstderr;
 +#endif
 +  int stdout_cb, stderr_cb, exit_cb;

+
+  // Spawn the process, connecting to stdin, stdout, stderr, and exit.
+#if !_WIN32
+#if GTK
+  GSpawnFlags flags = G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH;
+  if (g_spawn_async_with_pipes(cwd, argv, envp, flags, NULL, NULL, &p->pid,
+                               &p->fstdin, &p->fstdout, &p->fstderr, &error)) {

+  lua_pop(L, 1); // spawn_procs
+  return n;
+}
+
+#if (GTK && __APPLE__)
+static int monitoring_fds = 0;
+/**
+ * Monitors spawned fds when GTK is idle.
+ * This is necessary because at the moment, using GLib on Mac OSX to spawn
+ * and monitor file descriptors mostly blocks when attempting to poll those fds.
+ */
+static int monitor_fds(void *data) {
+  lua_State *L = (lua_State *)data;
+  struct timeval timeout = {0, 1e5}; // 0.1s
+  int nfds = os_spawn_pushfds(L);
+  fd_set *fds = (fd_set *)lua_touserdata(L, -1);
+  if (select(nfds, fds, NULL, NULL, &timeout) > 0) os_spawn_readfds(L);
+  lua_pop(L, 1); // fd_set
+  if (nfds == 1) monitoring_fds = 0;
+  return nfds > 1;
+}
+#endif
+#endif
+
+/** spawn() Lua function. */
