#include "unix-std.h"
#include "contrib/zstd/zstd.h"
#include "libmime/email_addr.h"
+#include "linenoise.h"
#include <math.h>
#include <glob.h>
*/
LUA_FUNCTION_DEF (util, is_valid_utf8);
+/***
+ * @function util.readline([prompt])
+ * Returns string read from stdin with history and editing support
+ * @return {boolean} true if a string is spoofed
+ */
+LUA_FUNCTION_DEF (util, readline);
+
/***
* @function util.pack(fmt, ...)
*
LUA_INTERFACE_DEF (util, caseless_hash_fast),
LUA_INTERFACE_DEF (util, is_utf_spoofed),
LUA_INTERFACE_DEF (util, is_valid_utf8),
+ LUA_INTERFACE_DEF (util, readline),
LUA_INTERFACE_DEF (util, get_hostname),
LUA_INTERFACE_DEF (util, pack),
LUA_INTERFACE_DEF (util, unpack),
return 1;
}
+static gint
+lua_util_readline (lua_State *L)
+{
+ const gchar *prompt = NULL;
+ gchar *input;
+
+ if (lua_type (L, 1) == LUA_TSTRING) {
+ prompt = lua_tostring (L, 1);
+ }
+
+ input = linenoise (prompt);
+
+ if (input) {
+ lua_pushstring (L, input);
+ linenoiseHistoryAdd (input);
+ linenoiseFree (input);
+ }
+ else {
+ lua_pushnil (L);
+ }
+
+ return 1;
+}
+
/* Backport from Lua 5.3 */
/******************************************************************************