Io: Difference between revisions
m Text replacement - "</source>" to "</syntaxhighlight>" |
No edit summary |
||
| Line 7: | Line 7: | ||
Manages main input/output operations. | Manages main input/output operations. | ||
=== | === Examples === | ||
'''Create a file with default values''' | |||
<syntaxhighlight lang="lua"> | |||
local hex1 | |||
local hex2 | |||
local hex3 | |||
local file = io.open("|D|theme.txt", "r") | |||
if not file then | |||
hex1 = 0x280d1d | |||
hex2 = 0x581422 | |||
hex3 = 0x622334 | |||
file = io.open("|D|theme.txt", "w+") | |||
file:write(hex1.."\n") | |||
file:write(hex2.."\n") | |||
file:write(hex3.."\n") | |||
file:close() | |||
else | |||
hex1 = file:read("*line") | |||
hex2 = file:read("*line") | |||
hex3 = file:read("*line") | |||
file:close() | |||
end | |||
print(hex1, hex2, hex3) | |||
</syntaxhighlight> | |||
'''To copy a file''' | '''To copy a file''' | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
Latest revision as of 06:50, 7 August 2025
Supported platforms: ![]()
![]()
![]()
![]()
![]()
![]()
![]()
Available since: Gideros 2011.6
Description
Manages main input/output operations.
Examples
Create a file with default values
local hex1
local hex2
local hex3
local file = io.open("|D|theme.txt", "r")
if not file then
hex1 = 0x280d1d
hex2 = 0x581422
hex3 = 0x622334
file = io.open("|D|theme.txt", "w+")
file:write(hex1.."\n")
file:write(hex2.."\n")
file:write(hex3.."\n")
file:close()
else
hex1 = file:read("*line")
hex2 = file:read("*line")
hex3 = file:read("*line")
file:close()
end
print(hex1, hex2, hex3)
To copy a file
local function copy(src, dst)
local srcf = io.open(src, "rb")
local dstf = io.open(dst, "wb")
local size = 2^13 -- good buffer size (8K)
while true do
local block = srcf:read(size)
if not block then break end
dstf:write(block)
end
srcf:close()
dstf:close()
end
Methodsio.close closes file, or the default output file |
EventsConstants |