Skip to content

Instantly share code, notes, and snippets.

@error454
Created September 19, 2014 10:07
Show Gist options
  • Select an option

  • Save error454/e4e9c2f7620374baf283 to your computer and use it in GitHub Desktop.

Select an option

Save error454/e4e9c2f7620374baf283 to your computer and use it in GitHub Desktop.
Shiva Code File Count
--
-- Put at the root of your project and run
--
lfs = require "lfs"
function findAllAI ( )
local t = {}
count = 1
for file in lfs.dir('./Resources/AIModels') do
local sName, sExt = getFileNameAndExtension ( file )
if sExt ~= nil then
if hasExtension ( file, "aim" ) then
t[count] = sName
count = count + 1
end
end
end
return t
end
function hasExtension ( sFilename, sExt )
if sFilename then
return string.match ( string.lower ( sFilename ), "." .. string.lower( sExt ) ) ~= nil
end
return false
end
function getFileNameAndExtension ( sFilename )
if sFilename then
-- match (anything not a .).(anything not a .)
if not string.find( sFilename, ".ccz") then
for k, v in string.gmatch ( sFilename, "([^\.]+)\.([^\.]+)" ) do
return k, v
end
end
end
return nil, nil
end
function file_exists(name)
local f=io.open(sPath .. name,"r")
if f~=nil then io.close(f) return true else return false end
end
function findAIFiles(sAI)
local tFuncs = {}
local tHandlers = {}
local tStates = {}
local funcCount = 1
local handlerCount = 1
local stateCount = 1
for file in lfs.dir('./Resources/Scripts') do
local sName, sExt = getFileNameAndExtension ( file )
if sExt ~= nil then
if hasExtension ( file, "lua" ) then
-- Look for "AINAME_"
if string.find( sName, sAI .. "_Function") then
tFuncs[funcCount] = file
funcCount = funcCount + 1
elseif string.find( sName, sAI .. "_Handler") then
tHandlers[handlerCount] = file
handlerCount = handlerCount + 1
elseif string.find( sName, sAI .. "_State") then
tStates[stateCount] = file
stateCount = stateCount + 1
end
end
end
end
return tFuncs, tHandlers, tStates
end
local t = findAllAI()
print ("Found ", #t, " AI models")
local outputFile = io.open('analysis-.csv', "w+")
io.output(outputFile)
io.write("AI,Functions,Handlers,States,Lines\n")
--print("AI,Functions,Handlers,States,Lines")
for iAI = 1, #t do
local tFuncs, tHandlers, tStates = findAIFiles(t[iAI])
local lines = 0
for iFuncs = 1, #tFuncs do
for _ in io.lines("./Resources/Scripts/" .. tFuncs[iFuncs]) do
lines = lines + 1
end
end
for iHandlers = 1, #tHandlers do
for _ in io.lines("./Resources/Scripts/" .. tHandlers[iHandlers]) do
lines = lines + 1
end
end
for iStates = 1, #tStates do
for _ in io.lines("./Resources/Scripts/" .. tStates[iStates]) do
lines = lines + 1
end
end
io.write(t[iAI] .. "," .. (#tFuncs or "0") .. "," .. (#tHandlers or "0") .. "," .. (#tStates or "0") .. "," .. lines .. "\n")
--print (t[iAI] .. "," .. (#tFuncs or "0") .. "," .. (#tHandlers or "0") .. "," .. (#tStates or "0") .. "," .. lines)
end
io.close(outputFile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment