On 16.03.2012 21:07, Alexander Yakushev wrote:
> I'm a bit tired of carrying these around my machines so it would be nice
> to see them in gears.debug. It is cold and empty there anyway.
Hehe. :-)
> The function names should definitely be changed. I use "d" because it is
> easy to write, but perhaps something more comprehensible might do better.
Perhaps these should be called "dump"?
> +-- Given a table (or any other data) return a string that contains its
> +-- tag, value and type. If data is a table then recursively call d_raw
> +-- on each of its values.
> +-- @param data Value to inspect.
> +-- @param shift Spaces to indent lines with.
> +-- @param tag The name of the value.
> +-- @return a string which contains tag, value, value type and table key/value
> +-- pairs if data is a table.
> +local function d_raw(data, shift, tag)
> + local result = ""
> +
> + if tag then
> + result = result .. tostring(tag) .. " : "
> + end
> + if not data then
> + result = result .. "nil"
> + else
> + result = result .. tostring(data)
> + end
According to:
$ lua -e 'print(tostring(nil))'
nil
the above "if not data" is not necessary.
> + if type(data) ~= "table" then
> + return result .. " (" .. type(data) .. ")"
> + end
> +
> + shift = (shift ~= nil) and shift .. " " or " "
Personally, I'd prefer:
shift = (shift or "") .. " "
(Because the two spaces are repeated one time less)
> + for k, v in pairs(data) do
> + result = result .. "\n" .. shift .. d_raw(v, shift, k)
> + end
I wonder if this should also print the table keys. If I print e.g. the arguments
to awful.wibox(), that would be helpful.
I guess it isn't easy to come up with a good format for that. Ideas?
> + return result
> +end
> +
> +--- Inspect the value in data.
> +-- @param data Value to inspect.
> +-- @param tag The name of the value.
> +-- @return a string that contains the expanded value of data.
> +function d_return(data, tag)
> + return d_raw(data, nil, tag)
> +end
> +
> +--- Print the table (or any other value) to the console.
> +-- @param data Table to print.
> +-- @param tag The name of the table.
> +function d(data, tag)
> + print(d_return(data, tag))
> +end
> +
> +--- Show the table (or any other value) using Naughty.
> +-- @param data Table to show.
> +-- @param tag The name of the table.
> +function d_show(data, tag)
> + if not naughty then
> + naughty = require("naughty")
> + end
> + naughty.notify( { title = "ETDP",
> + text = log.d_return(s),
> + timeout = 0})
> +end
What's "ETDP"? What is "log.d_return"? I guess this is some old stuff and that
this code was previously called "log"? Which would mean that this does not work
anymore...
Also, I don't really like the idea of require()'ing "naughty" from here. This
leads to a cyclic dependency between "naughty" and "gears.debug". :-(
Yes, this is helpful, but I don't know a good way around this problem (except
for adding e.g. naughty.debug() which uses gears.debug.d_return (which will then
be called dump_return)?)
Cheers,
Uli
--
Q: Because it reverses the logical flow of conversation.
A: Why is putting a reply at the top of the message frowned upon?
--
To unsubscribe, send mail to [email protected].