local type,table,io,string = type,table,io,string module "file" -- file exists ------------------------ function exists(filename) local f = io.open(filename, "r") if f==nil then return false else f:close() return true end end -- file saver ------------------------- function save(filename, rbuf) if rbuf==nil then return false end local f = io.open(filename, "w+b") if f==nil then return false end f:write(rbuf) f:flush() f:close() return true end -- file append ------------------------ function append(filename, rbuf) if rbuf==nil then return false end local f = io.open(filename, "a+") if f==nil then return false end f:write(rbuf) f:flush() f:close() return true end -- file loader ------------------------ function load(filename) local f = io.open(filename, "r") if f==nil then return nil end local cmdbuf = f:read("*all") f:close() return(cmdbuf) end function loadastable(filename) local f = io.open(filename, "r") if f==nil then return nil end local cmdbuf = {} while true do local line = f:read("*l") if line == nil then break end table.insert(cmdbuf,line) end f:close() return cmdbuf, table.getn(cmdbuf) end -- file extension --------------------- function getext(filename) local file_ext = nil for w in string.gfind(filename,"(%.%a*)") do file_ext = string.lower(string.sub(w,2,10)) end return file_ext end -- table/file to html --------------------- function tohtml(f) if type(f)=="table" then local hr = "" table.foreach(f, function(k,v) hr = hr .. v.."
" end) return hr else return ""..tohtml(loadastable(f)).."" end end