Table explorer (Dev Tool)


**NOW WORKS WITH UPVALUES TOO:v:**

So this is a tool for exploring tables in gmod (duh). Original idea by CapsAdmin.

http://errur.com/i/images/1112_gm_construct0000.jpg

The window will pop up when you open the file.

Syntax for search is



<tablename> [[-]<type1>,<type2>,...]
Ex: hook -function,table --shows all content of the hook table that aren't of type function or table

where the type are datatypes (Ex. string,number,function) and the optional - represents the complement of those datatypes.

[lua]
local iconTranslate = {

["function"] = "gui/silkicons/page_white",
["string"] = "gui/silkicons/text_bold",
["number"] = "vgui/col-blue",
["boolean"] = "vgui/col-green",
["table"] = "gui/silkicons/exclamation"

}

local panel = vgui.Create(“DFrame”)
panel:SetPos(50,50)
panel:SetSize(400,400)
panel:SetTitle(“Table Explorer”)
panel:SetVisible(true)
panel:SetDraggable(true)
panel:ShowCloseButton(true)
panel:MakePopup()

local tree = vgui.Create(“DTree”,panel)
tree:SetPos(20,80)
tree:SetSize(360,300)

local function addNodes(parent,tbl,done,filter,inv)

if (type(tbl) == "function") then

	local f = tbl
	tbl = {}
	
	local i = 1
	
	while true do
	
		local k,v = debug.getupvalue(f,i)
		
		if (!k) then
		
			break
		end
		
		tbl[k] = v
		
		i = i+1
	end

elseif (type(tbl) != "table") then

	print("("..type(tbl)..")"..tostring(tbl).." is not a valid table!")
	return
end

done = done or {}
filter = filter or {}
		
for k,v in pairs(tbl) do

	if (table.HasValue(filter,type(v)) == util.tobool(inv)) then

		if (type(v) == "table" and !done[v]) then
		
			done[v] = true
			
			node = parent:AddNode(tostring(k))
			node.Icon:SetImage("gui/silkicons/folder")
			if (table.Count(v) &gt; 0) then
			
				node.Icon:SetImage("gui/silkicons/folder_go")
				node.DoClick = function(self)
					
					if (!self.loadOnce) then
						
						addNodes(node,v,done,filter,inv)
						self.loadOnce = true
					end
				end
			end
		else
		
			local node = parent:AddNode(tostring(k))
			node.Icon:SetImage(iconTranslate[type(v)] or "vgui/spawnmenu/file")
			node.DoClick = function(self)
			
				self.lastClick = self.lastClick or 0
				self.clickCount = self.clickCount or 0
				
				self.clickCount = self.clickCount+1
				
				if (RealTime() - self.lastClick &lt; 1 and self.clickCount == 2) then
				
					if (type(v) == "table") then
					
						PrintTable(v)
					else
					
						print(v)
					end
					
					self.clickCount = 0
				
				elseif (RealTime() - self.lastClick &gt; 1) then
				
					self.clickCount = 1
				end
				
				self.lastClick = RealTime()
								
				panel:SetTitle("Value: "..tostring(v).." Type: "..type(v))
												
				if (!self.loadOnce and type(v) == "function" and debug.getupvalue(v,1)) then
				
					addNodes(node,v,done,filter,inv)
					self.loadOnce = true
				end
			end
			
			if (type(v) == "function" and debug.getupvalue(v,1)) then
			
				node.Icon:SetImage("gui/silkicons/page_white_go")
			end
		end
	end
end

end

local input = vgui.Create(“DTextEntry”,panel)
input:SetPos(20,35)
input:SetSize(360,20)
input:RequestFocus()

input.OnEnter = function(self)

--debug.sethook() THIS SHIT IS FUCKING DANGEROUS D=

tree = vgui.Create("DTree",panel)
tree:SetPos(20,80)
tree:SetSize(360,300)

local tokens = string.Explode(" ",self:GetValue())

RunString("_="..tokens[1]) --Noone uses _ as a global var do they? :s

if (#tokens == 1) then

	addNodes(tree,_)
	return
end

local filter = string.Explode(",",tokens[2])

local inv = true

if (filter[1]:sub(0,1) == "-") then

	filter[1] = filter[1]:sub(2,-1)
	inv = false
end

addNodes(tree,_,nil,filter,inv)

end
[/lua]

Enjoy!

Pretty cool, could be useful.

I love your releases.

looks pretty useful!

Usefull’d

Might not be very useful as it is now, but I plan on making functions expandable too so you can explore the upvalues:buddy:

You should pick one from here:

http://www.garrysmod.org/img/?t=dll&id=54170

It’s gonna be clientside anyway, so don’t feel bad about having custom content!

SQL Explorer next.

SQL Explorer

Works, but can’t handle queries bigger than the console command character limit.

Too tired to fix it.