Package: dh-lua
Version: 23
Severity: normal
Tags: patch

While the packaging for lua-luv was being worked on, it was noticed that
dh-lua's test-app-* test targets fail if the app is called like "app -".

The attached patch adds support for loading the lua script from stdin if
the test app is run with no arguments or with the "-" argument, like
lua.

-- System Information:
Debian Release: stretch/sid
  APT prefers unstable-debug
  APT policy: (500, 'unstable-debug'), (500, 'unstable'), (1, 
'experimental-debug'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.6.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages dh-lua depends on:
ii  dctrl-tools             2.24-2
ii  debhelper               9.20160709
ii  libfile-find-rule-perl  0.34-1
ii  liblua5.1-0-dev         5.1.5-8
ii  liblua5.2-dev           5.2.4-1
ii  liblua5.3-dev           5.3.1-1
ii  libtool                 2.4.6-0.1
ii  libtool-bin             2.4.6-0.1
ii  lua5.1                  5.1.5-8
ii  lua5.2                  5.2.4-1
ii  lua5.3                  5.3.1-1
ii  perl                    5.22.2-2
ii  pkg-config              0.29-4

dh-lua recommends no packages.

dh-lua suggests no packages.

-- no debconf information
>From 3a88c2e0d580bf2c19e0e16494229a1a8f223878 Mon Sep 17 00:00:00 2001
From: James McCoy <james...@debian.org>
Date: Thu, 21 Jul 2016 22:35:58 -0400
Subject: [PATCH] app.c: Emulate lua's ability to run a script from stdin

If the arg "-" is given, or there are no arguments supplied, tell
luaL_loadfile to load from stdin.

Signed-off-by: James McCoy <james...@debian.org>
---
 test/5.1/app.c | 10 ++++++++--
 test/5.2/app.c | 10 ++++++++--
 test/5.3/app.c | 10 ++++++++--
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/test/5.1/app.c b/test/5.1/app.c
index e5e3da6..781b683 100644
--- a/test/5.1/app.c
+++ b/test/5.1/app.c
@@ -3,6 +3,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <lauxlib.h>
 #include <lualib.h>
@@ -41,7 +42,12 @@ int main(int argn,char** argv){
 	app_open(L);
 
 	// LOAD
-	rc = luaL_loadfile(L,argv[1]);
+	if (argn < 2 || !strcmp("-", argv[1])) {
+		rc = luaL_loadfile(L, NULL);
+	}
+	else {
+		rc = luaL_loadfile(L,argv[1]);
+	}
 
 	// check for errors
 	if (rc != 0){
@@ -61,7 +67,7 @@ int main(int argn,char** argv){
 	lua_setglobal(L,"arg");
 
 	for(i=2;i<argn;i++) lua_pushstring(L,argv[i]);
-	rc = lua_pcall(L,argn-2,LUA_MULTRET,0);
+	rc = lua_pcall(L,(argn > 2 ? argn-2 : 0),LUA_MULTRET,0);
 	
 	// check for errors
 	if (rc != 0){
diff --git a/test/5.2/app.c b/test/5.2/app.c
index 690751c..669d6b3 100644
--- a/test/5.2/app.c
+++ b/test/5.2/app.c
@@ -3,6 +3,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <lauxlib.h>
 #include <lualib.h>
@@ -41,7 +42,12 @@ int main(int argn,char** argv){
 	app_open(L);
 
 	// LOAD
-	rc = luaL_loadfile(L,argv[1]);
+	if (argn < 2 || !strcmp("-", argv[1])) {
+		rc = luaL_loadfile(L, NULL);
+	}
+	else {
+		rc = luaL_loadfile(L,argv[1]);
+	}
 
 	// check for errors
 	if (rc != 0){
@@ -61,7 +67,7 @@ int main(int argn,char** argv){
 	lua_setglobal(L,"arg");
 
 	for(i=2;i<argn;i++) lua_pushstring(L,argv[i]);
-	rc = lua_pcall(L,argn-2,LUA_MULTRET,0);
+	rc = lua_pcall(L,(argn > 2 ? argn-2 : 0),LUA_MULTRET,0);
 	
 	// check for errors
 	if (rc != 0){
diff --git a/test/5.3/app.c b/test/5.3/app.c
index 690751c..669d6b3 100644
--- a/test/5.3/app.c
+++ b/test/5.3/app.c
@@ -3,6 +3,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <lauxlib.h>
 #include <lualib.h>
@@ -41,7 +42,12 @@ int main(int argn,char** argv){
 	app_open(L);
 
 	// LOAD
-	rc = luaL_loadfile(L,argv[1]);
+	if (argn < 2 || !strcmp("-", argv[1])) {
+		rc = luaL_loadfile(L, NULL);
+	}
+	else {
+		rc = luaL_loadfile(L,argv[1]);
+	}
 
 	// check for errors
 	if (rc != 0){
@@ -61,7 +67,7 @@ int main(int argn,char** argv){
 	lua_setglobal(L,"arg");
 
 	for(i=2;i<argn;i++) lua_pushstring(L,argv[i]);
-	rc = lua_pcall(L,argn-2,LUA_MULTRET,0);
+	rc = lua_pcall(L,(argn > 2 ? argn-2 : 0),LUA_MULTRET,0);
 	
 	// check for errors
 	if (rc != 0){
-- 
2.8.1

Reply via email to