Code: Select all
[h/w-check]
Measure=Script
ScriptFile=wc.lua
function wc(C:\Users\Sam\Documents\Rainmeter\Skins\Mine\Blank2\homework.txt)
if words= >1 then
Excecute [!ShowMeter Checkn] [!HideMeter Checkp] [!Redraw]
else
Excecute [!ShowMeter Checkp] [!HideMeter Checkn] [!Redraw]
return
end
Code: Select all
#!/usr/bin/env lua
-- Copyright (c) 2013 the authors listed at the following URL, and/or
-- the authors of referenced articles or incorporated external code:
-- http://en.literateprograms.org/Word_count_(Lua)?action=history&offset=20070621060029
--
-- Permission is hereby granted, free of charge, to any person obtaining
-- a copy of this software and associated documentation files (the
-- "Software"), to deal in the Software without restriction, including
-- without limitation the rights to use, copy, modify, merge, publish,
-- distribute, sublicense, and/or sell copies of the Software, and to
-- permit persons to whom the Software is furnished to do so, subject to
-- the following conditions:
--
-- The above copyright notice and this permission notice shall be
-- included in all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--
-- Retrieved from: http://en.literateprograms.org/Word_count_(Lua)?oldid=10564
tot_chars=0
tot_words=0
tot_lines=0
opts=""
function printwc(lines, words, chars, fname)
if(string.find(opts, "l")) then io.write(string.format("% 8d", lines)) end
if(string.find(opts, "w")) then io.write(string.format("% 8d", words)) end
if(string.find(opts, "c")) then io.write(string.format("% 8d", chars)) end
if(fname~="-") then io.write(" "); print(fname)
else print() end
end
function wc(fname)
chars=0
words=0
lines=0
if(fname=="-") then it=io.lines()
else it=io.lines(fname) end
for line in it do
lines=lines+1
for word in string.gfind(line, "[^%s]+") do words=words+1 end
chars=chars+string.len(line)+1
end
printwc(lines, words, chars, fname)
tot_chars=tot_chars+chars
tot_words=tot_words+words
tot_lines=tot_lines+lines
end
nfiles=0
for i=1,table.getn(arg) do
if(nfiles==0 and string.sub(arg[i], 1, 1)=='-') then
opts=opts .. arg[i]
else
if(string.len(opts)==0) then opts="lwc" end
wc(arg[i])
nfiles=nfiles+1
end
end
if(string.len(opts)==0) then opts="lwc" end
if nfiles<1 then wc("-") end
if nfiles>1 then printwc(tot_lines, tot_words, tot_chars, "total") end