-
-
Save nikolamin/08e4a5d512feaebc7751 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------------ | |
-- Author: Nikola Minoski - June 2014 | |
-- Done in competition with Kex | |
-- Competition: Swift vs Lua | |
------------------------------------ | |
require("lfs") | |
if #arg < 2 then print "Usange: count_src_lines.lua <path_to_project_src_dir> <src_code_ext1> [<src_code_ext2 [...]]" os.exit() end | |
local dst, allowedFiles, sourceLinesCount, sourceFiles = arg[1], {}, 0, 0 | |
for i=2,#arg do allowedFiles[arg[i]:lower()] = true end | |
if not lfs.chdir(dst) then print("Wrong src directory: '" .. dst .. "'") os.exit() end | |
function checkDir(folder) | |
for file in lfs.dir(folder) do | |
if file:sub(1, 1) ~= "." then | |
local path = folder .. "/" .. file | |
if lfs.attributes(path,"mode") == "file" then | |
if allowedFiles[file:match(".(%w-)$"):lower()] then --check for allowed extensions | |
sourceFiles = sourceFiles + 1 | |
for line in io.lines(path) do | |
if line:gsub("%s+", ""):len() > 0 then sourceLinesCount = sourceLinesCount + 1 end | |
end | |
end | |
elseif lfs.attributes(path,"mode")== "directory" then checkDir(path) end | |
end | |
end | |
end | |
checkDir(dst) | |
print("Files: ", sourceFiles) | |
print("Source Lines: ", sourceLinesCount) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Playground - noun: a place where people can play | |
// Done in competition with Nikola | |
// Competition: Swift vs Lua | |
import Cocoa | |
let fileManager:NSFileManager = NSFileManager.defaultManager() | |
let currentFilePath = "/Users/aleksandartrpeski/Documents/TMP/smashicons/BadIcons/BadIcons" | |
let paths:AnyObject[] = fileManager.subpathsAtPath(currentFilePath) | |
var linesOfCode = 0; | |
var files = 0; | |
for path:AnyObject in paths { | |
let filePath = currentFilePath.stringByAppendingPathComponent(path as String) | |
if filePath.pathExtension == "h" || | |
filePath.pathExtension == "m" || | |
filePath.pathExtension == "plist"{ | |
let text:AnyObject = NSString.stringWithContentsOfFile(filePath) | |
let count = text.componentsSeparatedByString("\n").count | |
linesOfCode += count | |
files++ | |
// println("\(count)\t\(text)") | |
} | |
} | |
println("\nLines of Code: \(linesOfCode)\n Files:\(files)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment