factor out dump() function, handle reference loops

The dump() function is a generic thing, so no need to have it in docsettings.lua, which is about something else.

Also have dump() handle reference loops like "local t={}; t.loop = t". It will output "nil" plus a comment string that will show where the reference points to.