News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
Exploring tables
Author Message
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #1
RE: Exploring tables

New changes:
Added a "back" button to make navigation more rational
Much better sorting of the table: rather than sorting the table itself (which doesn't really work with string indexes) it uses a temporary table to presort the strings that will eventually go into the browser.

I haven't had a crash with it lately, so that must have been fixed =o)

I still want to try to figure out if I can get more information about selected functions, but so far it doesn't look promising. Ideally I would like to be able to display the contents of the functions, which I think should be possible at least with the Lua (non-C) functions.

I tried adding "thread" and "boolean" to the syntax highlighting, but there seems to be an issue when separating those two types (only one or the other displays). I'll need to look into that in the future.

Code:
#!/usr/bin/murgaLua

Fl:set_boxtype(fltk.FL_UP_BOX,fltk.FL_THIN_UP_BOX)
Fl:set_boxtype(fltk.FL_DOWN_BOX,fltk.FL_THIN_DOWN_BOX)

my_depth=0
my_level={}
my_title={}
my_line={}

-- text colors
col_tab="@b"
col_func="@C1"
col_str="@C4"
col_num="@C13"
col_usr="@C8@B17"
--col_thr="@C9"
--col_bool="@C5"

function lookittable()
  outpoot:clear()
  local my_value,my_string
  local tmptab={} -- temporary table for alphabetizing the list of my_string's
  for k,v in pairs(current_table) do
    my_value=tostring(k).."\t\t"..tostring(v)
    if     type(v)=="table" then my_string=col_tab..tostring(k)
    elseif type(v)=="function" then my_string=col_func..my_value
    elseif type(v)=="number" then my_string=col_num..my_value
    elseif type(v)=="userdata" then my_string=col_usr..my_value
    elseif type(v)=="string" then my_string=col_str..my_value
    --elseif type(v)=="thread" then my_string=col_thr..my_value
    --elseif type(v)=="boolean" then my_string=col_bool..my_value
    else my_string=tostring(k)
    end
    table.insert(tmptab,my_string)
  end
  table.sort(tmptab) -- alphabetize
  for i,v in ipairs(tmptab) do outpoot:add(v) end -- add the sorted list to the browser
  title:label(my_title[my_depth])
  if my_depth==0 then backbutt:deactivate() else backbutt:activate() end
  outpoot:middleline(my_line[my_depth])
end

function move_forward(k,v)
  my_depth=my_depth+1 -- move up a level
  my_level[my_depth]=current_table
  my_title[my_depth]=tostring(k).." ("..type(v)..")"
  my_line[my_depth]=1
  lookittable()
end

function move_back()
if my_depth > 0 then
  current_table=my_level[my_depth-1]
  my_depth=my_depth-1
  lookittable()
end
end

function which_is_it()
  local this_text=outpoot:text(outpoot:value())
  if outpoot:value() > 0 and type(current_table) == "table" then
    my_line[my_depth]=outpoot:value()
    -- Compare the browser text with each key in current_table until a match is found
    -- This could probably be streamlined
    for k,v in pairs(current_table) do
      -- it's a table
      if this_text == col_tab..tostring(k) then
        my_level[my_depth]=current_table --set a table to return to with "back"
        current_table=v
    move_forward(k,v)
        break
      end
      -- it's a function
      if string.find(this_text,"^"..col_func..tostring(k)) then
        -- is there a way to get more useful info?
        my_level[my_depth]=current_table
        current_table=debug.getinfo(v,"nSlufL")
    move_forward(k,v)
        break
      end
    end
  end
end

ww=400
wh=360

w=fltk:Fl_Double_Window(ww,wh,"view murga tables")

outpoot=fltk:Fl_Select_Browser(10,40,ww-20,wh-50)
--outpoot:column_widths((ww-20)/2) -- not supported?
outpoot:selection_color(0)
outpoot:callback(which_is_it)

--[[
butt=fltk:Fl_Button(ww-90,10,80,30,"view table")
butt:callback(which_is_it)
butt:deactivate()
]]

title=fltk:Fl_Box(90,10,ww-100,30)
title:box(fltk.FL_THIN_UP_BOX)

backbutt=fltk:Fl_Button(10,10,80,30,"@<- back")
backbutt:callback(move_back)

w:resizable(outpoot)
current_table=_G
my_title[my_depth]="Global Environment (table: _G)"
my_line[my_depth]=1
lookittable()
w:show()
Fl:run()

09-08-2007 09:22 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Messages In This Thread
Exploring tables - mikshaw - 09-07-2007, 06:53 AM
RE: Exploring tables - chrimo - 09-07-2007, 07:28 AM
RE: Exploring tables - mikshaw - 09-07-2007, 01:18 PM
RE: Exploring tables - mikshaw - 09-08-2007 09:22 AM
RE: Exploring tables - mikshaw - 09-12-2007, 09:40 AM
RE: Exploring tables - mikshaw - 01-22-2008, 05:23 AM
RE: Exploring tables - mikshaw - 03-24-2008, 11:36 AM
RE: Exploring tables - mikshaw - 04-24-2008, 06:07 AM
RE: Exploring tables - petermac - 08-05-2008, 10:05 AM

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: