Patchwork [4/4] lua: support linenoise

login
register
mail settings
Submitter Francois Perrad
Date Dec. 3, 2012, 4:12 p.m.
Message ID <1354551135-30056-4-git-send-email-francois.perrad@gadz.org>
Download mbox | patch
Permalink /patch/203394/
State Accepted
Commit 635bebf559f4f76bc4fa49c3ccb468476a654151
Headers show

Comments

Francois Perrad - Dec. 3, 2012, 4:12 p.m.
Signed-off-by: Francois Perrad <francois.perrad@gadz.org>
---
 package/lua/Config.in              |   17 +++++++++++++++++
 package/lua/lua-11-linenoise.patch |   24 ++++++++++++++++++++++++
 package/lua/lua.mk                 |    8 +++++++-
 3 files changed, 48 insertions(+), 1 deletion(-)
 create mode 100644 package/lua/lua-11-linenoise.patch
Peter Korsgaard - Dec. 5, 2012, 7 p.m.
>>>>> "Francois" == Francois Perrad <fperrad@gmail.com> writes:

 Francois> Signed-off-by: Francois Perrad <francois.perrad@gadz.org>

Committed, thanks (but see below).

 Francois> @@ -16,10 +16,16 @@ LUA_MYLIBS += -ldl
 Francois>  ifeq ($(BR2_PACKAGE_LUA_INTERPRETER_READLINE),y)
 Francois>  	LUA_DEPENDENCIES = readline ncurses
 Francois>  	LUA_MYLIBS += -lreadline -lhistory -lncurses
 Francois> -	LUA_CFLAGS += -DLUA_USE_LINUX
 Francois> +	LUA_CFLAGS += -DLUA_USE_POSIX -DLUA_USE_DLOPEN -DLUA_USE_READLINE

Why did you change LUA_USE_LINUX to LUA_USE_POSIX?

Patch

diff --git a/package/lua/Config.in b/package/lua/Config.in
index 8233e2a..4166730 100644
--- a/package/lua/Config.in
+++ b/package/lua/Config.in
@@ -7,6 +7,15 @@  config BR2_PACKAGE_LUA
 
 if BR2_PACKAGE_LUA
 
+choice
+	prompt "Lua Interpreter command-line editing"
+	default BR2_PACKAGE_LUA_INTERPRETER_EDITING_NONE
+
+config BR2_PACKAGE_LUA_INTERPRETER_EDITING_NONE
+	bool "none"
+	help
+	  None.
+
 config BR2_PACKAGE_LUA_INTERPRETER_READLINE
 	bool "readline support"
 	select BR2_PACKAGE_READLINE
@@ -14,4 +23,12 @@  config BR2_PACKAGE_LUA_INTERPRETER_READLINE
 	help
 	  Enables command-line editing in the lua interpreter.
 
+config BR2_PACKAGE_LUA_INTERPRETER_LINENOISE
+	bool "linenoise support"
+	select BR2_PACKAGE_LINENOISE
+	help
+	  Enables command-line editing in the lua interpreter.
+
+endchoice
+
 endif
diff --git a/package/lua/lua-11-linenoise.patch b/package/lua/lua-11-linenoise.patch
new file mode 100644
index 0000000..488c080
--- /dev/null
+++ b/package/lua/lua-11-linenoise.patch
@@ -0,0 +1,24 @@ 
+Add support of linenoise (replace readline)
+
+see discussion, http://lua-users.org/lists/lua-l/2010-03/msg00879.html
+
+Signed-off-by: Francois Perrad <francois.perrad@gadz.org>
+
+Index: b/src/luaconf.h
+===================================================================
+--- a/src/luaconf.h
++++ b/src/luaconf.h
+@@ -279,6 +279,13 @@
+ 	if (lua_strlen(L,idx) > 0)  /* non-empty line? */ \
+ 	  add_history(lua_tostring(L, idx));  /* add it to history */
+ #define lua_freeline(L,b)	((void)L, free(b))
++#elif defined(LUA_USE_LINENOISE)
++#include <linenoise.h>
++#define lua_readline(L,b,p)	((void)L, ((b)=linenoise(p)) != NULL)
++#define lua_saveline(L,idx) \
++	if (lua_strlen(L,idx) > 0)  /* non-empty line? */ \
++	  linenoiseHistoryAdd(lua_tostring(L, idx));  /* add it to history */
++#define lua_freeline(L,b)	((void)L, free(b))
+ #else
+ #define lua_readline(L,b,p)	\
+ 	((void)L, fputs(p, stdout), fflush(stdout),  /* show prompt */ \
diff --git a/package/lua/lua.mk b/package/lua/lua.mk
index 9e0d387..32acc99 100644
--- a/package/lua/lua.mk
+++ b/package/lua/lua.mk
@@ -16,10 +16,16 @@  LUA_MYLIBS += -ldl
 ifeq ($(BR2_PACKAGE_LUA_INTERPRETER_READLINE),y)
 	LUA_DEPENDENCIES = readline ncurses
 	LUA_MYLIBS += -lreadline -lhistory -lncurses
-	LUA_CFLAGS += -DLUA_USE_LINUX
+	LUA_CFLAGS += -DLUA_USE_POSIX -DLUA_USE_DLOPEN -DLUA_USE_READLINE
+else
+ifeq ($(BR2_PACKAGE_LUA_INTERPRETER_LINENOISE),y)
+	LUA_DEPENDENCIES = linenoise
+	LUA_MYLIBS += -llinenoise
+	LUA_CFLAGS += -DLUA_USE_POSIX -DLUA_USE_DLOPEN -DLUA_USE_LINENOISE
 else
 	LUA_CFLAGS += -DLUA_USE_POSIX -DLUA_USE_DLOPEN
 endif
+endif
 
 # We never want to have host-readline and host-ncurses as dependencies
 # of host-lua.