1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-30 21:23:00 +00:00

Some fs examples

See #566
This commit is contained in:
Jonathan Coates
2021-07-03 14:05:41 +01:00
parent 0d22270f8b
commit 61eb67849d
4 changed files with 318 additions and 28 deletions

View File

@@ -253,28 +253,32 @@ function input(file)
return currentInput
end
--- Opens the given file name in read mode and returns an iterator that,
-- each time it is called, returns a new line from the file.
--
-- This can be used in a for loop to iterate over all lines of a file:
--
-- ```lua
-- for line in io.lines(filename) do print(line) end
-- ```
--
-- Once the end of the file has been reached, @{nil} will be
-- returned. The file is automatically closed.
--
-- If no file name is given, the @{io.input|current input} will be used
-- instead. In this case, the handle is not used.
--
-- @tparam[opt] string filename The name of the file to extract lines from
-- @param ... The argument to pass to @{Handle:read} for each line.
-- @treturn function():string|nil The line iterator.
-- @throws If the file cannot be opened for reading
--
-- @see Handle:lines
-- @see io.input
--[[- Opens the given file name in read mode and returns an iterator that,
each time it is called, returns a new line from the file.
This can be used in a for loop to iterate over all lines of a file
Once the end of the file has been reached, @{nil} will be returned. The file is
automatically closed.
If no file name is given, the @{io.input|current input} will be used instead.
In this case, the handle is not used.
@tparam[opt] string filename The name of the file to extract lines from
@param ... The argument to pass to @{Handle:read} for each line.
@treturn function():string|nil The line iterator.
@throws If the file cannot be opened for reading
@see Handle:lines
@see io.input
@usage Iterate over every line in a file and print it out.
```lua
for line in io.lines("/rom/help/intro.txt") do
print(line)
end
```
]]
function lines(filename, ...)
expect(1, filename, "string", "nil")
if filename then