teknoraver / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame 0001-Finish-lua-5.2-support-trac-865.patch

Tom Callaway 52532d
From 96807d2f3dcec583ca54b503e7fc70014115e308 Mon Sep 17 00:00:00 2001
Tom Callaway 52532d
From: Johannes Dewender <rpm@JonnyJD.net>
Tom Callaway 52532d
Date: Thu, 4 Apr 2013 17:23:43 +0200
Tom Callaway 52532d
Subject: [PATCH] Finish lua 5.2 support, trac #865
Tom Callaway 52532d
Tom Callaway 52532d
Lua52 support was started with ac959fed0082cb253d45c7a04866e8654e962442.
Tom Callaway 52532d
Tom Callaway 52532d
Compilation tested with Lua 5.2.1 and Lua 5.1.5.
Tom Callaway 52532d
Tom Callaway 52532d
The short typerror() snippet is taken from luaL_typerror in Lua 5.1.5
Tom Callaway 52532d
(MIT license)
Tom Callaway 52532d
Tom Callaway 52532d
Signed-off-by: Johannes Dewender <rpm@JonnyJD.net>
Tom Callaway 52532d
---
Tom Callaway 52532d
 luaext/lposix.c | 21 +++++++++++++++------
Tom Callaway 52532d
 rpmio/rpmlua.c  |  8 ++++++++
Tom Callaway 52532d
 2 files changed, 23 insertions(+), 6 deletions(-)
Tom Callaway 52532d
Tom Callaway 52532d
diff --git a/luaext/lposix.c b/luaext/lposix.c
Tom Callaway 52532d
index f3c787e..a59be3e 100644
Tom Callaway 52532d
--- a/luaext/lposix.c
Tom Callaway 52532d
+++ b/luaext/lposix.c
Tom Callaway 52532d
@@ -58,6 +58,15 @@ static const char *filetype(mode_t m)
Tom Callaway 52532d
 
Tom Callaway 52532d
 typedef int (*Selector)(lua_State *L, int i, const void *data);
Tom Callaway 52532d
 
Tom Callaway 52532d
+/* implemented as luaL_typerror until lua 5.1, dropped in 5.2
Tom Callaway 52532d
+ * (C) 1994-2012 Lua.org, PUC-Rio. MIT license
Tom Callaway 52532d
+ */
Tom Callaway 52532d
+static int typerror (lua_State *L, int narg, const char *tname) {
Tom Callaway 52532d
+	const char *msg = lua_pushfstring(L, "%s expected, got %s",
Tom Callaway 52532d
+					  tname, luaL_typename(L, narg));
Tom Callaway 52532d
+	return luaL_argerror(L, narg, msg);
Tom Callaway 52532d
+}
Tom Callaway 52532d
+
Tom Callaway 52532d
 static int doselection(lua_State *L, int i, const char *const S[], Selector F, const void *data)
Tom Callaway 52532d
 {
Tom Callaway 52532d
 	if (lua_isnone(L, i))
Tom Callaway 52532d
@@ -139,7 +148,7 @@ static uid_t mygetuid(lua_State *L, int i)
Tom Callaway 52532d
 		return (p==NULL) ? -1 : p->pw_uid;
Tom Callaway 52532d
 	}
Tom Callaway 52532d
 	else
Tom Callaway 52532d
-		return luaL_typerror(L, i, "string or number");
Tom Callaway 52532d
+		return typerror(L, i, "string or number");
Tom Callaway 52532d
 }
Tom Callaway 52532d
 
Tom Callaway 52532d
 static gid_t mygetgid(lua_State *L, int i)
Tom Callaway 52532d
@@ -154,7 +163,7 @@ static gid_t mygetgid(lua_State *L, int i)
Tom Callaway 52532d
 		return (g==NULL) ? -1 : g->gr_gid;
Tom Callaway 52532d
 	}
Tom Callaway 52532d
 	else
Tom Callaway 52532d
-		return luaL_typerror(L, i, "string or number");
Tom Callaway 52532d
+		return typerror(L, i, "string or number");
Tom Callaway 52532d
 }
Tom Callaway 52532d
 
Tom Callaway 52532d
 
Tom Callaway 52532d
@@ -573,7 +582,7 @@ static int Pgetpasswd(lua_State *L)		/** getpasswd(name or id) */
Tom Callaway 52532d
 	else if (lua_isstring(L, 1))
Tom Callaway 52532d
 		p = getpwnam(lua_tostring(L, 1));
Tom Callaway 52532d
 	else
Tom Callaway 52532d
-		luaL_typerror(L, 1, "string or number");
Tom Callaway 52532d
+		typerror(L, 1, "string or number");
Tom Callaway 52532d
 	if (p==NULL)
Tom Callaway 52532d
 		lua_pushnil(L);
Tom Callaway 52532d
 	else
Tom Callaway 52532d
@@ -590,7 +599,7 @@ static int Pgetgroup(lua_State *L)		/** getgroup(name or id) */
Tom Callaway 52532d
 	else if (lua_isstring(L, 1))
Tom Callaway 52532d
 		g = getgrnam(lua_tostring(L, 1));
Tom Callaway 52532d
 	else
Tom Callaway 52532d
-		luaL_typerror(L, 1, "string or number");
Tom Callaway 52532d
+		typerror(L, 1, "string or number");
Tom Callaway 52532d
 	if (g==NULL)
Tom Callaway 52532d
 		lua_pushnil(L);
Tom Callaway 52532d
 	else
Tom Callaway 52532d
@@ -709,10 +718,10 @@ static int Puname(lua_State *L)			/** uname([string]) */
Tom Callaway 52532d
 	luaL_buffinit(L, &b);
Tom Callaway 52532d
 	for (s=luaL_optstring(L, 1, "%s %n %r %v %m"); *s; s++)
Tom Callaway 52532d
 		if (*s!='%')
Tom Callaway 52532d
-			luaL_putchar(&b, *s);
Tom Callaway 52532d
+			luaL_addchar(&b, *s);
Tom Callaway 52532d
 		else switch (*++s)
Tom Callaway 52532d
 		{
Tom Callaway 52532d
-			case '%': luaL_putchar(&b, *s); break;
Tom Callaway 52532d
+			case '%': luaL_addchar(&b, *s); break;
Tom Callaway 52532d
 			case 'm': luaL_addstring(&b,u.machine); break;
Tom Callaway 52532d
 			case 'n': luaL_addstring(&b,u.nodename); break;
Tom Callaway 52532d
 			case 'r': luaL_addstring(&b,u.release); break;
Tom Callaway 52532d
diff --git a/rpmio/rpmlua.c b/rpmio/rpmlua.c
Tom Callaway 52532d
index 86d0408..0576318 100644
Tom Callaway 52532d
--- a/rpmio/rpmlua.c
Tom Callaway 52532d
+++ b/rpmio/rpmlua.c
Tom Callaway 52532d
@@ -7,14 +7,22 @@
Tom Callaway 52532d
 #include <lposix.h>
Tom Callaway 52532d
 #include <lrexlib.h>
Tom Callaway 52532d
 
Tom Callaway 52532d
+/* replaced in 5.1 */
Tom Callaway 52532d
 #ifndef lua_open
Tom Callaway 52532d
 #define lua_open()	luaL_newstate()
Tom Callaway 52532d
 #endif
Tom Callaway 52532d
 
Tom Callaway 52532d
+/* defined as lua_objlen in 5.1 */
Tom Callaway 52532d
 #ifndef lua_strlen
Tom Callaway 52532d
 #define lua_strlen(L,i)	lua_rawlen(L, (i))
Tom Callaway 52532d
 #endif
Tom Callaway 52532d
 
Tom Callaway 52532d
+/* deprecated in 5.1, defined as lua_objlen in 5.1 */
Tom Callaway 52532d
+#ifndef luaL_getn
Tom Callaway 52532d
+#define luaL_getn(L,i)	((int)lua_rawlen(L, i))
Tom Callaway 52532d
+#endif
Tom Callaway 52532d
+
Tom Callaway 52532d
+/* define added in 5.2 */
Tom Callaway 52532d
 #ifndef lua_pushglobaltable
Tom Callaway 52532d
 #define lua_pushglobaltable(L)	lua_pushvalue(L, LUA_GLOBALSINDEX)
Tom Callaway 52532d
 #endif
Tom Callaway 52532d
-- 
Tom Callaway 52532d
1.8.1.3
Tom Callaway 52532d