Skip to content

Instantly share code, notes, and snippets.

@josefnpat
Created August 22, 2013 21:34
Show Gist options
  • Save josefnpat/6313098 to your computer and use it in GitHub Desktop.
Save josefnpat/6313098 to your computer and use it in GitHub Desktop.
l
local function print_r (t, indent) -- alt version, abuse to http://richard.warburton.it
local indent=indent or ''
for key,value in pairs(t) do
io.write(indent,'[',tostring(key),']')
if type(value)=="table" then io.write(':\n') print_r(value,indent..'\t')
else io.write(' = ',tostring(value),'\n') end
end
end
local function isReserved(fname)
for i = 1,string.len(fname) do
if string.sub(fname,i,i) == "_" then
return true
end
end
return false
end
local collisions = 0
local function shortname(fname,depth,always)
if not always then
always = 1
end
local tmp = string.sub(fname,1,always)
for i = always+1,string.len(fname) do
if string.upper(string.sub(fname,i,i)) == string.sub(fname,i,i) then
tmp = tmp .. string.sub(fname,i,i+always-1)
end
end
return tmp
end
local function render(ftab,depth)
if not depth then
depth = 0
end
local list = {}
for i,v in pairs(ftab) do
if not isReserved(i) then
local tmp
if type(v) == "function" then
tmp = shortname(i,depth)
elseif type(v) == "table" then
tmp = shortname(i,depth)
v = render(v,depth+1)
else
print("Error: Unhandled type: "..type(v).." ["..i.."]")
end
if tmp then
if list[tmp] then
print("Error: Collision on "..i)
collisions = collisions + 1
else
list[tmp] = v
end
end
end
end
return list
end
l= render(love)
print("Collisions: "..collisions)
print_r(l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment