util.startup: Handle missing nparams field from debug info (not present in 5.1)
authorMatthew Wild <mwild1@gmail.com>
Sun, 11 Oct 2020 20:25:32 +0100
changeset 11156 89162d27e1b1
parent 11155 498b3ab49b9c
child 11157 e4075ca84a1a
util.startup: Handle missing nparams field from debug info (not present in 5.1)
util/startup.lua
--- a/util/startup.lua	Sun Oct 11 14:27:28 2020 +0200
+++ b/util/startup.lua	Sun Oct 11 20:25:32 2020 +0100
@@ -198,11 +198,12 @@
 	end
 	function mt.__tostring(f)
 		local info = debug.getinfo(f, "Su");
-		for i = 1, info.nparams do
+		local n_params = info.nparams or 0;
+		for i = 1, n_params do
 			info[i] = debug.getlocal(f, i);
 		end
 		if info.isvararg then
-			info[info.nparams+1] = "...";
+			info[n_params+1] = "...";
 		end
 		return ("function<%s:%d>(%s)"):format(info.short_src:match("[^\\/]*$"), info.linedefined, table.concat(info, ", "));
 	end