Io.read: Difference between revisions

From GiderosMobile
m Text replacement - "</source>" to "</syntaxhighlight>"
No edit summary
Line 10: Line 10:


=== Parameters ===
=== Parameters ===
'''format1''': (string) reading format<br/>
'''format1''': (string) reading format, possible values:
*''"*all"'' reads the whole file
*''"*line"'' reads the next line, '''default'''
*''"*number"'' reads a number
*''num'' reads a string with up to num characters
'''...''': (string) more optional formats '''optional'''<br/>
'''...''': (string) more optional formats '''optional'''<br/>


=== Return values ===
=== Return values ===
'''Returns''' (string) returns read values or nil<br/>
'''Returns''' (string) returns read values or nil<br/>
=== Example ===
<syntaxhighlight lang="lua">
local fd = io.open(path.."/"..file, "rb")
local header = fd:read(27) -- reads a string with up to 27 characters
</syntaxhighlight>


{{Io}}
{{Io}}

Revision as of 12:33, 20 August 2026

Available since: Gideros 2011.6
Class: io

Description

Reading from default input, basically equivalent to io.input():read.

(string) = io.read(format1,...)

Parameters

format1: (string) reading format, possible values:

  • "*all" reads the whole file
  • "*line" reads the next line, default
  • "*number" reads a number
  • num reads a string with up to num characters

...: (string) more optional formats optional

Return values

Returns (string) returns read values or nil

Example

local fd = io.open(path.."/"..file, "rb")
local header = fd:read(27) -- reads a string with up to 27 characters