Mining Lua Code |
|
-- usage: clone LuaDist repo [1] and then do lua findescape.lua `find /tmp/Repository -name '*.lua'` -- [1] github.com/LuaDist/Repository -- DavidManura lexer = require 'lxsh.lexers.lua' -- https://github.com/xolox/lua-lxsh local function readfile(filename) local fh = io.open(filename, 'r') local text; if fh then text = fh:read'*a':gsub('\r','\n') end fh:close() return text end local counts = {} for _, filename in ipairs{...} do --print(filename) local text = readfile(filename) for kind, text in lexer.gmatch(text) do if kind ~= 'comment' and kind ~= 'whitespace' and kind ~= "string" and kind ~= "number" then counts[text] = (counts[text] or 0) + 1 end end end local names = {} for name, count in pairs(counts) do names[#names+1] = {name, count} end table.sort(names, function(a,b) return a[2] < b[2] end) for _, pair in ipairs(names) do print(pair[1], pair[2]) end
lua test.lua `find /tmp/Repository/ -name '*.lua'`|grep '^string\.' ... string.gfind 27 string.dump 35 string.lower 41 string.upper 41 string.gmatch 46 string.char 83 string.match 106 string.byte 139 string.rep 148 string.len 159 string.sub 332 string.find 400 string.gsub 492 string.format 722
It's string.reverse.
(Caveat: the above ignores string method calls.)
See LuaList:2010-10/msg00449.html .