ex5.lua 328 B

123456789101112131415
  1. function source.empty(err)
  2. return function()
  3. return nil, err
  4. end
  5. end
  6. function source.file(handle, io_err)
  7. if handle then
  8. return function()
  9. local chunk = handle:read(20)
  10. if not chunk then handle:close() end
  11. return chunk
  12. end
  13. else return source.empty(io_err or "unable to open file") end
  14. end