Author: Upstream
Description: Patch restores processing EOF (Ctrl+D), when readline()
 returns NULL, distinguishable from an empty string.
Debian-Bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1034078

--- a/C-readline.c
+++ b/C-readline.c
@@ -65,7 +65,13 @@
 	/* rl_cleanup_after_signal(); rl_clear_signals();  no effect :-( 1.3 */
 	/* lua_pushstring(L, line); */
 	/* 3.2 did lua_pushstring create a copy of the string ? */
-	lua_pushfstring(L, "%s", line);   /* 3.2 */
+	/* lua_pushfstring(L, "%s", line);   3.2 */
+	if (line == NULL) { /* 3.3 fix by zash.se, Prosody developer */
+		lua_pushnil(L);
+	} else {
+		lua_pushfstring(L, "%s", line);
+		// lua_pushstring(L, line); should be fine as well
+	}
 	if (tty_stream != NULL) { fclose(tty_stream); }
 	free(line);  /* 3.2 fixes memory leak */
 	return 1;
@@ -135,13 +141,15 @@
 	return 0;
 }
 
-static int c_write_history(lua_State *L) {  /* filename in, returncode out */
+/* unused ...
+static int c_write_history(lua_State *L) {  //  filename in, returncode out
 	size_t len;
 	const char *filename  = lua_tolstring(L, 1, &len);
     lua_Integer rc = write_history(filename);
 	lua_pushinteger(L, rc);
 	return 1;
 }
+*/
 
 static int c_history_truncate_file(lua_State *L) { /* filename,num in rc out */
 	size_t len;
