 +}
 +
 +/** p:read() Lua function. */
-+static int lp_read(lua_State *L) {
-+  PStream *p = (PStream *)luaL_checkudata(L, 1, "ta_spawn");
++static int proc_read(lua_State *L) {
++  PStream *p = luaL_checkudata(L, 1, "ta_spawn");
 +  luaL_argcheck(L, p->pid, 1, "process terminated");
 +  char *c = (char *)luaL_optstring(L, 2, "l");
 +  if (*c == '*') c++; // skip optional '*' (for compatibility)
-+  luaL_argcheck(L, *c == 'l' || *c == 'L' || *c == 'a' || lua_isnumber(L, 2), 2,
-+                   "invalid option");
++  luaL_argcheck(
++    L, *c == 'l' || *c == 'L' || *c == 'a' || lua_isnumber(L, 2), 2,
++    "invalid option");
 +#if (GTK && !__APPLE__)
 +  char *buf;
 +  size_t len;
 +  GError *error = NULL;
 +  GIOStatus status = G_IO_STATUS_NORMAL;
 +  if (!g_io_channel_get_buffered(p->cstdout))
-+    g_io_channel_set_buffered(p->cstdout, TRUE); // needed for functions below
++    g_io_channel_set_buffered(p->cstdout, true); // needed for functions below
 +  if (!lua_isnumber(L, 2)) {
 +    if (*c == 'l' || *c == 'L') {
 +      GString *s = g_string_new(NULL);
 +      status = g_io_channel_read_line_string(p->cstdout, s, NULL, &error);
-+      len = s->len, buf = g_string_free(s, FALSE);
++      len = s->len, buf = g_string_free(s, false);
 +    } else if (*c == 'a') {
 +      status = g_io_channel_read_to_end(p->cstdout, &buf, &len, &error);
 +      if (status == G_IO_STATUS_EOF) status = G_IO_STATUS_NORMAL;

+
+  // Create process object to be returned and link callback functions from
+  // optional fourth, fifth, and sixth function params.
+  PStream *p = (PStream *)lua_newuserdata(L, sizeof(PStream));
+  p->L = L, p->ref = 0;
+  p->stdout_cb = l_reffunction(L, narg), narg++;
+  p->stderr_cb = l_reffunction(L, narg), narg++;
+  p->exit_cb = l_reffunction(L, narg), narg++;
+  if (luaL_newmetatable(L, "ta_spawn")) {
+    l_setcfunction(L, -1, "status", lp_status);
+    l_setcfunction(L, -1, "wait", lp_wait);
+    l_setcfunction(L, -1, "read", lp_read);
+    l_setcfunction(L, -1, "write", lp_write);
+    l_setcfunction(L, -1, "close", lp_close);
+    l_setcfunction(L, -1, "kill", lp_kill);
+    l_setcfunction(L, -1, "__tostring", lp_tostring);
+#if (GTK && !__APPLE__)
+    l_setcfunction(L, -1, "__gc", lp_gc);
+#endif
+    lua_pushvalue(L, -1), lua_setfield(L, -2, "__index");
+  }

+#define read(fd, buf, len) read((int)fd, buf, len)
+#endif
+#endif
+
+typedef struct {
+  lua_State *L;
