Changeset

11150:0cfa36fa707e

util.startup: Include arguments in function string representation Improves usability of the console when digging around the internals. No specific rationale for the function<file:line>(args) format, it looked best of the variants I tried.
author Kim Alvefur <zash@zash.se>
date Fri, 09 Oct 2020 17:41:10 +0200
parents 11149:28add4b22a74
children 11151:498b3ab49b9c
files util/startup.lua
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/util/startup.lua	Fri Oct 09 17:34:04 2020 +0200
+++ b/util/startup.lua	Fri Oct 09 17:41:10 2020 +0200
@@ -197,8 +197,14 @@
 		end
 	end
 	function mt.__tostring(f)
-		local info = debug.getinfo(f, "S");
-		return ("function(%s:%d)"):format(info.short_src:match("[^\\/]*$"), info.linedefined);
+		local info = debug.getinfo(f, "Su");
+		for i = 1, info.nparams do
+			info[i] = debug.getlocal(f, i);
+		end
+		if info.isvararg then
+			info[info.nparams+1] = "...";
+		end
+		return ("function<%s:%d>(%s)"):format(info.short_src:match("[^\\/]*$"), info.linedefined, table.concat(info, ", "));
 	end
 	debug.setmetatable(function() end, mt);
 end