Table checker .. (debuger)
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Table checker .. (debuger)

Started by Herodes, 07 August, 2004, 18:16:37

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Herodes

I have this that is also posted in the how to section in Scripting utilities Central ...

tTable = { ["theFirstvalue"] = {
					["level"] = "AAA1",
					["nrvalues"] = 33300000,
					["goodarray"] = { "array A1", "array A2", "array A3", 123 },
					},
		["theSecond"] = {
					["2level"] = "AAA2",
					["2nrvalues"] = 3,
					["2goodarray"] = { "array B1", "array B2", "array B3", 456},
					},
		};
function DataArrival(user,data)
	if strsub(data, 1, 1) == "<" then
		local s, e, cmd = strfind(data, "%b<>%s+(%S+)")
		SendToAll(cmd)
		if strsub(cmd, 1 ,3) == "!do" then 
			ShowTable(tTable)
		end
	end
end
	
function ShowTable(table)
	if count == nil then
		count = 1
	else 
		count = count + 1
	end

	for index, val in table do 
		if type(val) == "table" then
				SendToAll("--------> Table/Array STARTS here ...")
				ShowTable(val)
				SendToAll("<-------- Table/Array ENDS here ...")
		elseif type(val) == "string" or type(val) == "number" then
				if count ~= nil then
					SendToAll(strrep("- ", count*2)..">  "..index.."  >?<  "..val.."    it is a "..type(val))
				else 
					SendToAll( ">  "..index.."  >?<  "..val.."   it is a "..type(val))
				end
		end
	end

end

I need some help to make it display the values like

tTable["theFirstvalue"]["level"] == "AAA1"

Is it ever possible ?
I dont know how to get even the ' ["TheFirstvalue"] ' displayed ... :(

Also I cant figure out a way to show (for index, val) the val if it is a function ... can someone think of something ?

thanks in advance for any input ..

plop

yw in advance. lol
i changed it a bit so it works on the lua command line.
this kind of things you shouldn't try on ptokax because the command line is much handyer.
tTable = { 
   ["theFirstvalue"] = {
      ["level"] = "AAA1",
      ["nrvalues"] = 33300000,
      ["goodarray"] = { "array A1", "array A2", "array A3", 123 },
      ["function1"] = function() 
         print("function1")
      end,
   },
   ["theSecond"] = {
      ["2level"] = "AAA2",
      ["2nrvalues"] = 3,
      ["2goodarray"] = { "array B1", "array B2", "array B3", 456},
      ["function2"] = function() 
         print("function2")
      end,
   },
};

function ShowTable(table, count)
   if count == nil then
      count = 0
   else
      count = count + 1
   end

   for index, val in table do
      if type(val) == "table" then
         print(strrep("--", count*2).."-> Table/Array: "..index.." STARTS here ...")
         ShowTable(val, count)
         print("<-"..strrep("--", count*2).." Table/Array: "..index.." ENDS here ...")
      elseif type(val) == "string" or type(val) == "number" then
         if count ~= nil then
            print(strrep("- ", count*2).."> "..index.." >?< "..val.." it is a "..type(val))
         else
            print( "> "..index.." >?< "..val.." it is a "..type(val))
         end
      elseif type(val) == "function" then
         print(strrep("- ", count*2).."> "..index.." >?< "..tostring(val).." it is a "..type(val))
      end
   end
end

ShowTable(tTable)
plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Herodes

#2
pro-thank u to plop ...

after his input I manage to add "a mustache and a beard" try this
tTable = { 

	["theFirstvalue"] = {
		["level"] = "AAA1",
		["nrvalues"] = 33300000,
		["goodarray"] = { "array A1", "array A2", "array A3", 123 },
		["function1"] = function() 
			return "function1"
		end,
	},
	["theSecond"] = {
		["2level"] = "AAA2",
		["2nrvalues"] = 3,
		["2goodarray"] = { ["array B1"] = {"a", "b", "c", "d", "e", "f", "g"}, prey = "array B2", ["1"] = function() return "ok" end,  ["3"] = 456},
		["function2"] = function() 
			return "function2"
		end,
	},
	["andanother"] = { "true", "false", "maybe", "could have" , "impossible", "dont think so" },
};


function DataArrival(user,data)
	if strsub(data, 1, 1) == "<" then
		local s, e, cmd = strfind(data, "%b<>%s+(%S+)")
		SendToAll(cmd)
		if strsub(cmd, 1 ,3) == "!do" then 
			ShowTable(tTable)
		end
	end
end
	
	
function ShowTable(table, count)
	if (count == nil) then
		count = 0
	else
		count = count + 1
	end

	for index, val in table do
		if (type(val) == "table") then
			if getn(val) ~= 0 then
				SendToAll(strrep("--", count*2).."-> start of ' "..index.." ' ( - array of "..getn(val).." - ) "..strrep("--", count*2))
			else
				SendToAll(strrep("--", count*2).."-> start of ' "..index.." ' ( - associative "..type(val).." - ) "..strrep("--", count*2))
			end
			ShowTable(val, count)
			SendToAll("<-"..strrep("--", count*2).." end of ' "..index.." ' ( - "..type(val).." - ) "..strrep("--", count*2))
		elseif ( (type(val) == "string") or (type(val) == "number") ) then
			if (count ~= nil) then
				SendToAll(" ? "..strrep("- ", count*2)..">  ( - "..type(val).." - ) \t"..index.." >?< "..val)
			else
				SendToAll(">  ( - "..type(val).." - ) \t"..index.." >?< "..val)
			end
		elseif (type(val) == "function") then
			SendToAll(" ? "..strrep("- ", count*2).."> ( - "..type(val).." - ) \t"..index.." >?< "..tostring(val))
		end
	end
end

Theis will give out the following ...
-> start of ' theFirstvalue ' ( - associative table - ) 
-----> start of ' goodarray ' ( - array of 4 - ) ----
 ? - - - - >  ( - string - ) 	1 >?< array A1
 ? - - - - >  ( - string - ) 	2 >?< array A2
 ? - - - - >  ( - string - ) 	3 >?< array A3
 ? - - - - >  ( - number - ) 	4 >?< 123
<----- end of ' goodarray ' ( - table - ) ----
 ? - - > ( - function - ) 	function1 >?< function: 00EEEF40
 ? - - >  ( - number - ) 	nrvalues >?< 33300000
 ? - - >  ( - string - ) 	level >?< AAA1
<- end of ' theFirstvalue ' ( - table - ) 
-> start of ' andanother ' ( - array of 6 - ) 
 ? - - >  ( - string - ) 	1 >?< true
 ? - - >  ( - string - ) 	2 >?< false
 ? - - >  ( - string - ) 	3 >?< maybe
 ? - - >  ( - string - ) 	4 >?< could have
 ? - - >  ( - string - ) 	5 >?< impossible
 ? - - >  ( - string - ) 	6 >?< dont think so
<- end of ' andanother ' ( - table - ) 
-> start of ' theSecond ' ( - associative table - ) 
 ? - - >  ( - string - ) 	2level >?< AAA2
 ? - - > ( - function - ) 	function2 >?< function: 00EEE508
-----> start of ' 2goodarray ' ( - associative table - ) ----
 ? - - - - > ( - function - ) 	1 >?< function: 00EE7690
 ? - - - - >  ( - number - ) 	3 >?< 456
---------> start of ' array B1 ' ( - array of 7 - ) --------
 ? - - - - - - >  ( - string - ) 	1 >?< a
 ? - - - - - - >  ( - string - ) 	2 >?< b
 ? - - - - - - >  ( - string - ) 	3 >?< c
 ? - - - - - - >  ( - string - ) 	4 >?< d
 ? - - - - - - >  ( - string - ) 	5 >?< e
 ? - - - - - - >  ( - string - ) 	6 >?< f
 ? - - - - - - >  ( - string - ) 	7 >?< g
<--------- end of ' array B1 ' ( - table - ) --------
 ? - - - - >  ( - string - ) 	prey >?< array B2
<----- end of ' 2goodarray ' ( - table - ) ----
 ? - - >  ( - number - ) 	2nrvalues >?< 3
<- end of ' theSecond ' ( - table - )

Now I think it is quite messy ... it doesnt really help to have this so some1 sees a table ... I was wondering if I could get the function: 00EE7690 parts a bit more clear to understand ...
Also , is it possible to Display how is the name of the table we are viewing ? in this case ' tTable' ...
I noted that the tTable["theSecond"]["function2"] appears before tTable["theSecond"]["2nrvalues"] and tTable["theSecond"]["2goodarray"] but not before tTable["theSecond"]["2level"]  ... how does that happen ?
Are functions processed earlier from other types ?

plop

array's are indexed by numbers, so everytime you loop them they appear in the same order.
if you sort them they are re-indexed.
the vallue's of a table are always on the move, it's some weird mix of sorting and checking which is used most/last.
array's are tables as you know and i said that they appear in the same order, the indexing makes them really show in the right order.
if you check freshstuff you can see that i'm using this same trick on a table.
and yes it looks a bit messy, i personaly rather save the table to file.
if tabbed correct it looks really clean (just like you typed it in the script itself).

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

SMF spam blocked by CleanTalk