Software / code / prosody
Comparison
plugins/mod_admin_shell.lua @ 11891:6a241e66eec5
mod_admin_shell: Respect metatables in output serialization
Makes it so that returning e.g. util.cache :table() produces useful
output, which otherwise would look like empty tables.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 12 Nov 2021 11:33:09 +0100 |
| parent | 11889:df76802dc09c |
| child | 11892:e712133b4de1 |
comparison
equal
deleted
inserted
replaced
| 11890:b9aab1962a2b | 11891:6a241e66eec5 |
|---|---|
| 284 | 284 |
| 285 -- Session environment -- | 285 -- Session environment -- |
| 286 -- Anything in def_env will be accessible within the session as a global variable | 286 -- Anything in def_env will be accessible within the session as a global variable |
| 287 | 287 |
| 288 --luacheck: ignore 212/self | 288 --luacheck: ignore 212/self |
| 289 local serialize_defaults = module:get_option("console_prettyprint_settings", { fatal = false, unquoted = true, maxdepth = 2}) | 289 local serialize_defaults = module:get_option("console_prettyprint_settings", |
| 290 { fatal = false; unquoted = true; maxdepth = 2; table_iterator = "pairs" }) | |
| 290 | 291 |
| 291 def_env.output = {}; | 292 def_env.output = {}; |
| 292 function def_env.output:configure(opts) | 293 function def_env.output:configure(opts) |
| 293 if type(opts) ~= "table" then | 294 if type(opts) ~= "table" then |
| 294 opts = { preset = opts }; | 295 opts = { preset = opts }; |
| 299 end | 300 end |
| 300 for k,v in pairs(serialize_defaults) do | 301 for k,v in pairs(serialize_defaults) do |
| 301 if opts[k] == nil then | 302 if opts[k] == nil then |
| 302 opts[k] = v; | 303 opts[k] = v; |
| 303 end | 304 end |
| 305 end | |
| 306 if opts.table_iterator == "pairs" then | |
| 307 opts.table_iterator = pairs; | |
| 308 elseif type(opts.table_iterator) ~= "function" then | |
| 309 opts.table_iterator = nil; -- rawpairs is the default | |
| 304 end | 310 end |
| 305 self.session.serialize = serialization.new(opts); | 311 self.session.serialize = serialization.new(opts); |
| 306 end | 312 end |
| 307 | 313 |
| 308 def_env.server = {}; | 314 def_env.server = {}; |