Software /
code /
prosody
Comparison
util/startup.lua @ 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 |
parent | 11149:28add4b22a74 |
child | 11152:89162d27e1b1 |
comparison
equal
deleted
inserted
replaced
11149:28add4b22a74 | 11150:0cfa36fa707e |
---|---|
195 if name then | 195 if name then |
196 debug.setupvalue(f, i, value); | 196 debug.setupvalue(f, i, value); |
197 end | 197 end |
198 end | 198 end |
199 function mt.__tostring(f) | 199 function mt.__tostring(f) |
200 local info = debug.getinfo(f, "S"); | 200 local info = debug.getinfo(f, "Su"); |
201 return ("function(%s:%d)"):format(info.short_src:match("[^\\/]*$"), info.linedefined); | 201 for i = 1, info.nparams do |
202 info[i] = debug.getlocal(f, i); | |
203 end | |
204 if info.isvararg then | |
205 info[info.nparams+1] = "..."; | |
206 end | |
207 return ("function<%s:%d>(%s)"):format(info.short_src:match("[^\\/]*$"), info.linedefined, table.concat(info, ", ")); | |
202 end | 208 end |
203 debug.setmetatable(function() end, mt); | 209 debug.setmetatable(function() end, mt); |
204 end | 210 end |
205 | 211 |
206 function startup.detect_platform() | 212 function startup.detect_platform() |