-- いわゆるprintf。
function printf(...)
local function wrapper(...) io.write(string.format(...)) end
local status, result = pcall(wrapper, ...)
if not status then error(result, 2) end
end
-- 対象のfilenameのファイルが存在するかどうか。
-- 対象のファイルのフルパス。もしくは、カレントからの相対パス。
function io.file_exists(path)
local fh = io.open(path, "rb")
localif fh then fh:close() end
localreturn fh ~= nil
end
-- 対象のfilenameのファイルのファイルサイズを得る
-- ファイルが存在しなければ、エラーとなる。
function io.file_size(filename)
local fh = assert(io.open(filename, "rb"))
local len = assert(fh:seek("end"))
fh:close()
return len
end