lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Try this tool.

-- find duplicated keys in table constructors
-- typical usage: luac -p -l *.lua | lua keys.lua

local F,K
while true do
 local s=io.read()
 if s==nil then break end
 local ok,_,f=string.find(s,"^[mf].-<(.-):[%d,]+>")
 if ok then F=f end
 local ok,_,l,op=string.find(s,"%[%-?(%d*)%]%s+(%S+)")
 if ok then
  if op=="NEWTABLE" then 
   K={}
  elseif op=="SETTABLE" then 
   local _,_,k=string.find(s,';%s*(".-")')
   if K[k] then 
    io.write(F,":",l,": duplicate key ",k," in table constructor\n")
   else
    K[k]=true
   end
  end
 end
end