display()

Share your scripts and packages with other Mudlet users.
Phoenix
Posts: 92
Joined: Tue Feb 15, 2011 3:23 am

display()

Post by Phoenix »

I've just finished rewriting display() so that it doesn't crash Mudlet with recursive tables - it goes as deep as it needs to, but never displays a recursion. Handy!! I pulled the base code out of the lua files, and then added the bits to make it not crash.

It also now displays the 'id' (I'm sure there's a different term for the actual nonsense that defines where the table is), which comes in handy as display is technically a 'debugging' tool!
Code: [show] | [select all] lua
oldDisplay = display
display = nil
function display(what, numformat, recursion, checked)
    recursion = recursion or 0
    checked = checked or {}
	if recursion == 0 then
		echo("\n")
	end
	echo(printable(what, numformat))

	-- Do all the stuff inside a table
	if type(what) == 'table' then 
        checked[tostring(what)] = true
		echo(tostring(what):gsub("^table:","").." {")
		local firstline = true   -- a kludge so empty tables print on one line
		if getmetatable(what) and getmetatable(what).isPhpTable == true then
			for k, v in what:pairs() do
				if firstline then echo("\n"); firstline = false end
				echo(indent(recursion))
				echo(printable())
				echo(": ")
				if not checked[tostring(v)] then 
					display(v, numformat, recursion + 1, checked)
				else 
					echo("'Recursion of"..tostring(v):gsub("table:","").."'\n") 
				end
			end
		else
			for k, v in pairs(what) do
				if firstline then echo("\n"); firstline = false end
				echo(indent(recursion))
				echo(printable(k))
				echo(": ")
				if not checked[tostring(v)] then 
					display(v, numformat, recursion + 1, checked)
				else 
					echo("'Recursion of"..tostring(v):gsub("table:","").."'\n") 
				end
			end
		end

		-- so empty tables print as {} instead of {..indent..}
		if not firstline then
			echo(indent(recursion - 1))
		end
		echo("}")
	end

	echo("\n")
	if recursion == 0 then
	end
end

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: display()

Post by Vadi »

Works well for me

User avatar
Oneymus
Posts: 321
Joined: Thu Sep 17, 2009 5:24 am

Re: display()

Post by Oneymus »

Using this new display(), I grabbed a text dump of Mudlet's _G. I don't know if anyone else thinks this is handy, but I have used it before to find esoteric, undocumented functions in the past.

I can't guarantee this is the latest version of Mudlet (though I think it is).

At the very least, we could check the Wiki against this list to see what we're missing. I will do so when I have time.
Attachments
Mudlet _G.txt
A text dump of Mudlet's _G table.
(50.48 KiB) Downloaded 435 times

Phoenix
Posts: 92
Joined: Tue Feb 15, 2011 3:23 am

Re: display()

Post by Phoenix »

Oneymus wrote:Using this new display(), I grabbed a text dump of Mudlet's _G. I don't know if anyone else thinks this is handy, but I have used it before to find esoteric, undocumented functions in the past.

I can't guarantee this is the latest version of Mudlet (though I think it is).

At the very least, we could check the Wiki against this list to see what we're missing. I will do so when I have time.
I've got this alias called 'funcfind' that loops the _G using string.find() to find anything matching my parameters, however it just displays top-level functions in _G. Working on a more thorough function...
Last edited by Phoenix on Mon Sep 12, 2011 5:09 am, edited 2 times in total.

User avatar
Omni
Posts: 131
Joined: Fri Feb 12, 2010 10:26 am

Re: display()

Post by Omni »

Oneymus wrote:Using this new display(), I grabbed a text dump of Mudlet's _G. I don't know if anyone else thinks this is handy, but I have used it before to find esoteric, undocumented functions in the past.

I can't guarantee this is the latest version of Mudlet (though I think it is).

At the very least, we could check the Wiki against this list to see what we're missing. I will do so when I have time.
It will be useful in finding unlisted functions for the wiki, though a large number of them I don't know how they're used, but if someone else does okay.

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: display()

Post by Vadi »

It won't be useful in finding those functions, because a good chance is that you don't know where it came from, and would litter the wiki with functions not everyone has in their installation. A much better way to find undocumented functions is by looking at Mudlets source code directly: http://mudlet.git.sourceforge.net/git/g ... HEAD#l8105 and http://mudlet.git.sourceforge.net/git/g ... 58;hb=HEAD, or even the previous manual, mudlet.org/asciidoc/manual.html, which still has a number of functions listed there that aren't in the wiki yet.

Phoenix
Posts: 92
Joined: Tue Feb 15, 2011 3:23 am

Re: display()

Post by Phoenix »

Vadi wrote:It won't be useful in finding those functions, because a good chance is that you don't know where it came from, and would litter the wiki with functions not everyone has in their installation. A much better way to find undocumented functions is by looking at Mudlets source code directly: http://mudlet.git.sourceforge.net/git/g ... HEAD#l8105 and http://mudlet.git.sourceforge.net/git/g ... 58;hb=HEAD, or even the previous manual, mudlet.org/asciidoc/manual.html, which still has a number of functions listed there that aren't in the wiki yet.

There's still a number of functions aren't listed in the manuals at all, and not everyone wants to go through sourcecode. This way is pretty straightfoward... but I'm working on something a bit better. Keep your eyes peeled!

I should HOPE if you're posting a _G dump, that you dumped it from a blank profile, in which case (correct me if I'm wrong) all the functions listed -are- standard Mudlet.

User avatar
Oneymus
Posts: 321
Joined: Thu Sep 17, 2009 5:24 am

Re: display()

Post by Oneymus »

This is from a mostly blank profile. I removed everything that was profile specific; since it was just a barebones profile used for development, it was one table and a couple of minor variables. Admittedly, it may not be perfectly cleaned, but I haven't found anything that shouldn't be there, yet.

I have also spent time browsing the source (both C++ and Lua), and did find undocumented functions there, too.

Sanaki
Posts: 110
Joined: Wed Mar 09, 2011 1:30 am

Re: display()

Post by Sanaki »

Is this or similar at some point going to replace the current display function? I would hope so. I get tired of crashing Mudlet by trying to display something unfriendly.

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: display()

Post by Vadi »

You can add it for yourself to replace the default function. I'm not opposed to adding this one by default though.

Post Reply