From 0b82bcc53e6027c74fae2c972d5d9fff54d95d6c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi>
Date: Mon, 30 Dec 2019 16:15:44 +0200
Subject: [PATCH] lua: fix build and update to lua5.3

Fixes #8360
---
 .gitlab-ci.yml |  4 ++--
 .travis.yml    |  2 +-
 src/Makefile   |  2 +-
 src/lua-apk.c  | 35 ++++++++++++++++++++---------------
 4 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 10d1ec81..1201d835 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -6,7 +6,7 @@ test:alpine:
     stage: test
     script:
         - apk update
-        - apk add make gcc git musl-dev openssl-dev linux-headers zlib-dev lua5.2-dev
+        - apk add make gcc git musl-dev openssl-dev linux-headers zlib-dev lua5.3-dev
         - make -j$(nproc) check
     tags:
         - docker-alpine
@@ -16,7 +16,7 @@ test:debian:
     stage: test
     script:
         - apt-get update
-        - apt-get install -y make gcc git libssl-dev zlib1g-dev lua5.2-dev sudo
+        - apt-get install -y make gcc git libssl-dev zlib1g-dev lua5.3-dev sudo
         - unlink /bin/sh
         - ln -s /bin/bash /bin/sh
         - make -j$(nproc) check
diff --git a/.travis.yml b/.travis.yml
index 7c53cb4c..470f3b15 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -15,7 +15,7 @@ before_install:
   - alpine() { /alpine/enter-chroot -u "$USER" "$@"; }
 install:
   - sudo sh alpine-chroot-install -a "$ARCH" -b v3.10
-        -p 'build-base alpine-sdk linux-headers lua5.2-dev openssl openssl-dev zlib-dev'
+        -p 'build-base alpine-sdk linux-headers lua5.3-dev openssl openssl-dev zlib-dev'
 before_script:
   - /alpine/enter-chroot sh -c "addgroup $USER wheel && addgroup $USER abuild"
   - alpine abuild-keygen -ain
diff --git a/src/Makefile b/src/Makefile
index e307ceba..52ea1b25 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -9,7 +9,7 @@ ZLIB_LIBS		:= $(shell $(PKG_CONFIG) --libs zlib)
 
 # lua module
 ifneq ($(LUAAPK),)
-LUA_VERSION		?= 5.2
+LUA_VERSION		?= 5.3
 LUA_PC			?= lua$(LUA_VERSION)
 LUA_LIBDIR		?= /usr/lib/lua/$(LUA_VERSION)
 LIBAPK			:= YesPlease
diff --git a/src/lua-apk.c b/src/lua-apk.c
index 532577af..2f365b22 100644
--- a/src/lua-apk.c
+++ b/src/lua-apk.c
@@ -17,24 +17,24 @@
 #endif
 
 struct flagmap {
-       const char *name;
-       int flag;
+	const char *name;
+	int flag;
 };
 
 struct flagmap opendb_flagmap[] = {
-       {"read",                APK_OPENF_READ},
-       {"write",               APK_OPENF_WRITE},
-       {"create",              APK_OPENF_CREATE},
-       {"no_installed",        APK_OPENF_NO_INSTALLED},
-       {"no_scripts",          APK_OPENF_NO_SCRIPTS},
-       {"no_world",            APK_OPENF_NO_WORLD},
-       {"no_sys_repos",        APK_OPENF_NO_SYS_REPOS},
-       {"no_installed_repo",   APK_OPENF_NO_INSTALLED_REPO},
-       {"no_repos",            APK_OPENF_NO_REPOS},
-       {"no_state",            APK_OPENF_NO_STATE},
-       {"no_scripts",          APK_OPENF_NO_SCRIPTS},
-       {"no_world",            APK_OPENF_NO_WORLD},
-       {NULL, 0}
+	{"read",                APK_OPENF_READ},
+	{"write",               APK_OPENF_WRITE},
+	{"create",              APK_OPENF_CREATE},
+	{"no_installed",        APK_OPENF_NO_INSTALLED},
+	{"no_scripts",          APK_OPENF_NO_SCRIPTS},
+	{"no_world",            APK_OPENF_NO_WORLD},
+	{"no_sys_repos",        APK_OPENF_NO_SYS_REPOS},
+	{"no_installed_repo",   APK_OPENF_NO_INSTALLED_REPO},
+	{"no_repos",            APK_OPENF_NO_REPOS},
+	{"no_state",            APK_OPENF_NO_STATE},
+	{"no_scripts",          APK_OPENF_NO_SCRIPTS},
+	{"no_world",            APK_OPENF_NO_WORLD},
+	{NULL, 0}
 };
 
 /* implemented as luaL_typerror until lua 5.1, dropped in 5.2
@@ -46,6 +46,11 @@ static int typerror (lua_State *L, int narg, const char *tname) {
 	return luaL_argerror(L, narg, msg);
 }
 
+time_t apk_time(void)
+{
+	return time(NULL);
+}
+
 static apk_blob_t check_blob(lua_State *L, int index)
 {
 	apk_blob_t blob;
-- 
GitLab