Forums » StepMania Development » On reflection (code snippets that may be useful to other themers)

1
These first few functions are really simple and intended for examining the structure of something. Use the recursive ones with care, as they can produce a lot of output in your log.txt.


-- Usage: Pass in an ActorFrame to print all the children of.
function print_children(a)
local aname= a:GetName()
Trace("Printing child list for " .. aname)
if a.GetChildren then
local children= a:GetChildren()
for k, v in pairs(children) do
Trace(" " .. v:GetName())
end
else
Trace("Not an ActorFrame or other thing with children.")
end
Trace("Done.")
end

-- Usage: Pass in an ActorFrame and a string to put in front of every line.
-- indent will be appended to at each level of the recursion, to indent each
-- generation further.

function rec_print_children(parent, indent)
if not indent then indent= "" end
local pname= parent:GetName()
if parent.GetChildren then
local children= parent:GetChildren()
Trace(indent .. pname .. " children:")
for k, v in pairs(children) do
--Trace(indent .. pname .. "->" .. v:GetName())
rec_print_children(v, indent .. pname .. "->")
end
Trace(indent .. pname .. " children over.")
else
Trace(indent .. pname)
end
end

-- Usage: Pass in a table and a string to indent each line with.
function print_table(t, indent)
if not indent then indent= "" end
for k, v in pairs(t) do
Trace(indent .. k .. ": " .. tostring(v))
end
Trace(indent .. "end")
end

-- Usage: Pass in a table and a string to indent each line with.
-- indent will be appended to at each level of the recursion, to indent each
-- generation further.
-- DO NOT pass in a table that contains a reference loop.
-- A reference loop is a case where a table contains a member that is a
-- reference to itself, or contains a table that contains a reference to
-- itself.
-- Short reference loop example: a= {} a[1]= a
-- Longer reference loop example: a= {b= {c= {}}} a.b.c[1]= a
function rec_print_table(t, indent)
if not indent then indent= "" end
for k, v in pairs(t) do
if type(v) == "table" then
Trace(indent .. k .. ": table")
rec_print_table(v, indent .. " ")
else
Trace(indent .. k .. ": " .. tostring(v))
end
end
Trace(indent .. "end")
end
< cybik> til Kyzentun fixes bugs for breakfast
--
< maxvg1> shakesoda: then why do i still play lol
<@shakesoda> because you're an ITG player. And thus, a masochist
--
<@shakesoda> Kyzentun: I think you might need to put down the meshes for a bit
Reply