lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


вт, 30 июл. 2019 г. в 20:44, Soni "They/Them" L. <fakedme@gmail.com>:

> compare to:
> io.open("filename"):read("*a")

You can write simple function

function file_get_contents(name,mode)
  local f,r=io.open(name,mode or "rb")
  if f then r=f:read"a" else error(r) end
  f:close()
  return r
end

And read whole file just in one call file_get_contents

mydata=file_get_contents "myfile"