--[[ check.lua by blastbeat - this script does a script analysis to find hints for possible errors - WARNING: very bad quick and dirty code ( vbqadc ) - this script will probably work only with my scripting style more or less well - TODO: check patterns like "local a, b" ]]-- local files = { --"startup.lua", --"adc.lua", "out.lua", --"hub.lua", --"luadch.lua", "signal.lua", --"main.lua", "util.lua", "const.lua", "cfg.lua", "server.lua", } local check = function( file ) local locals = { } local std = { } local func = { } print( "\nanalysis of " .. file .. "\n" ) local chunk = io.open( file, "r" ) local count = 0 local block for line in chunk:lines( ) do count = count + 1 if line:find( "^%-%-%[%[" ) and block ~= 0 then block = 1 elseif block ~= 1 then local found = count .. " " local _, __, str = line:find( "local (%S+)" ) if str then locals[ str ] = 1 end for str2, i in pairs( locals ) do local a, b, _ = line:find( "" .. str2 .. "[%.%s%(]" ) if a and str ~= str2 then locals[ str2 ] = locals[ str2 ] + 1 end end for w in string.gmatch( line, "%a+" ) do if _G[ w ] and not line:find( "%-%-.*" .. w ) then std[ w ] = ( std[ w ] and ( std[ w ] .. found ) ) or found end end for w in string.gmatch( line, "(%a+)%(" ) do if w ~= "function" and not line:find( "%-%-.*" .. w ) then func[ w ] = ( func[ w ] and ( func[ w ] .. found ) ) or found end end elseif line:find( "%]%]%-%-" ) then block = 0 end end print( "- probably unused locals:" ) for str, i in pairs( locals ) do if i == 1 then print( " ", str, i ) end end print( "- probably undeclared lua stuff:" ) for str, lines in pairs( std ) do if not locals[ str ] then print( " ", str, "in line " .. lines ) end end print( "- probably undeclared functions:" ) for str, lines in pairs( func ) do if not locals[ str ] then print( " ", str, "in line " .. lines ) end end end for i, file in ipairs( files ) do check( file ) end