User:Rapidgame7/iodocs
Feel free to edit this page
static const luaL_Reg iolib[] = {
{"close", io_close},
{"open", io_open},
{"openlocal", io_openlocal},
{"tmpfile", io_tmpfile},
{"type", io_type},
{NULL, NULL}
};
static const luaL_Reg flib[] = {
{"close", io_close},
{"flush", f_flush},
{"lines", f_lines},
{"read", f_read},
{"seek", f_seek},
{"setvbuf", f_setvbuf},
{"write", f_write},
{"__gc", io_gc},
{"__tostring", io_tostring},
{NULL, NULL}
};
For reference ^
FOR /USERDATA
file*
This userdata type represents a file handle, obtained by calling io.openlocal
.
General | |
---|---|
Accessibility | Read-only |
Allows custom variables | No |
file* does not have any attributes.
|
---|
In the below examples, file refers to a file handle.
file* methods
| |||
---|---|---|---|
Method | Return value(s) | Description | |
file:close()
|
nil | Closes the file. | |
file:flush()
|
nil | Saves any written data to file .
| |
file:lines()
|
function | Returns an iterator function that, each time it is called, returns a new line from the file as a string. Therefore, the construction
for line in file:lines() do
-- body
end
will iterate over all lines of the file. | |
file:read([* format])
|
various | Reads the file file , according to the given formats, which specify what to read. For each format, the function returns a string (or a number) with the characters read, or nil if it cannot read data with the specified format. When called without formats, it uses a default format that reads the entire next line (see below).
The available formats are:
| |
file:seek([string whence], [int offset])
|
string or nil | Sets and gets the file position, measured from the beginning of the file, to the position given by offset plus a base specified by the string whence , as follows:
In case of success, function seek returns the final file position, measured in bytes from the beginning of the file. If this function fails, it returns nil, plus a string describing the error. The default value for | |
file:setvbuf(string mode, [int size])
|
TODO | Sets the buffering mode for an output file. There are three available modes:
For the last two cases, | |
file:write(...)
|
? | Writes the value of each of its arguments to the file. The arguments must be strings or numbers. To write other values, use tostring or string.format before write.
If the file size surpasses 1 megabyte after a write operation, BLua will raise an error and discard any pending changes. |