 +}
 +
 +/** p:wait() Lua function. */
-+static int lp_wait(lua_State *L) {
-+  PStream *p = (PStream *)luaL_checkudata(L, 1, "ta_spawn");
++static int proc_wait(lua_State *L) {
++  PStream *p = luaL_checkudata(L, 1, "ta_spawn");
 +  if (!p->pid) return (lua_pushinteger(L, p->exit_status), 1);
 +#if !_WIN32
 +  int status;

+    stdout_write, stderr_write
+  };
+  PROCESS_INFORMATION proc_info = {0, 0, 0, 0};
+  if (CreateProcessW(NULL, argv, NULL, NULL, TRUE, CREATE_NEW_PROCESS_GROUP,
+                     envp, *cwd ? cwd : NULL, &startup_info, &proc_info)) {
+    p->pid = proc_info.hProcess;
+    p->fstdin = proc_stdin, p->fstdout = proc_stdout, p->fstderr = proc_stderr;
+    p->cstdout = new_channel(FD(proc_stdout), p, p->stdout_cb > 0);
+    p->cstderr = new_channel(FD(proc_stderr), p, p->stderr_cb > 0);
+    if (p->exit_cb != LUA_REFNIL) g_child_watch_add(p->pid, p_exit, p);
+    // Close unneeded handles.
+    CloseHandle(proc_info.hThread);
+    CloseHandle(stdin_read);

+  if (status != G_IO_STATUS_NORMAL) {
+    lua_pushnil(L);
+    if (status == G_IO_STATUS_EOF) return 1;
+    lua_pushinteger(L, error->code);
+    lua_pushstring(L, error->message);
+    return 3;
+  } else return 1;
+#else
