From de37e6cb589e0124b93a38721c8ad809ba762b16 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Sat, 29 Jun 2019 16:54:39 +0200
Subject: prosodyctl: Fix extraction of interpreter from arg when additional
 arguments (fixes #1386)

Interpreter goes into the lowest negative index.
See http://www.lua.org/manual/5.2/manual.html#7
---
 prosodyctl | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/prosodyctl b/prosodyctl
index f5786ff9..3809beff 100755
--- a/prosodyctl
+++ b/prosodyctl
@@ -222,7 +222,15 @@ function commands.start(arg)
 	end
 
 	--luacheck: ignore 411/ret
-	local ok, ret = prosodyctl.start(prosody.paths.source, arg[-1]);
+	local lua;
+	do
+		local i = 0;
+		repeat
+			i = i - 1;
+		until arg[i-1] == nil
+		lua = arg[i];
+	end
+	local ok, ret = prosodyctl.start(prosody.paths.source, lua);
 	if ok then
 		local daemonize = configmanager.get("*", "daemonize");
 		if daemonize == nil then
-- 
cgit v1.2.3