Io.read() | What does it do?

I can’t find any specific documentation for the function

io.read()

I believe it reads the input and the output? It’s a bit confusing, if you do know, please do educate me! :joy:

For documentation if you are still curious you can google it.

tl;dr: it doesn’t exist in Roblox

1 Like

To understand ‘io.read’ you’ll need to understand how the io library operates, what ‘file handles’ are and how the OOP paradigm works in Lua. I will give you a quick rundown nevertheless.

It is worth noting that this function and the library itself have been redacted from Roblox’s sandboxed version of Lua named ‘Luau’.

When called as a class function (standalone function), the ‘io’ library function named ‘read’, reads/parses the current default input file (defined by Lua internally) according to the specified formats (or if unspecified the default format), when called as an instance method (method) through/on a file handle (an object that allows the script to interface with the file it represents), the particular file is read/parsed according to the method’s formats (options/modes).

Formats are represented by string values (literals) passed as arguments to the function/method, any number of formats can be provided, if no formats are given a single default format is used instead, this default format is represented by the value ‘l’ (lowercase ‘L’). There are a total of five available formats, represented by the values ‘a’, ‘l’, ‘L’, ‘n’ and number (any integer value). For each format the function/method attempts to read/parse the corresponding data/text from the file, if at any point one of the given formats fails to read/parse any data/text it returns a string value (literal) containing the word “fail” and any further formats are ignored.

Format ‘a’:
This format never fails, this format reads/parses through the file in its entirety (returning the read/parsed data/text).

Format ‘l’:
This format fails returning ‘fail’ if the current file position is at the end of the file, this format reads/parses the file’s following/proceeding line of text (from the current file position) excluding any end of line (EOL) character.

Format ‘L’:
This format fails returning ‘fail’ if the current file position is at the end of the file, this format reads/parses the file’s following/proceeding line of text (from the current file position) including any end of line (EOL) character.

Format number:
This format fails returning ‘fail’ if the current file position is at the end of the file, this format reads/parses a string of size (measured in bytes of memory) less than or equal to (as large as possible) the number specified, if 'a value of 0 is specified it returns an empty string value (literal).

Format ‘n’:
This format reads/parses a numeral (numeric value) and returns it (handles integers and floats), the numeral may be signed, i.e; ‘-123’ and may have leading whitespaces, i.e; ’ 123’, this format always attempts to read/parse the longest character sequence (string with greatest character count) that constitutes a valid numeral, if the format cannot read/parse a numeral or the numeral is too large (over 200 characters) it fails returning ‘fail’.

Files can contain content in the form of text and in the form of data (binary), the formats represented by the string values (literals) ‘l’ and ‘L’ should only be used on text files. Lines in text files can have meaning/purpose, lines in binary files never have meaning/purpose.

1 Like

So. To understand the IO library we must understand the language C.

In C there is this thing called “std” short for “standard input output”.

Usually the output is the console. In C there is a function called printf(...) in vanilla Lua the equievelant would be io.write(string.format(...)), so io.write is like printf but without formatting.

The difference between io.write and print in Lua is that print appends a newline. So basically a std is just a long text, and when new test gets added to the std its just appended to it. What io.read does it it allows a user to just type text in to the CLI and when they press enter io.read returns what text they typed. (Well actually it just checks if there is a newline, meaning if you paste text with a newline, it assumes you pressed enter)

In Roblox Lua things work a bit differently, unlike a normal std enviroment. Lua doesn’t use an IO system for the console. Instead each message exists on its own. This effe

notice there is still possibility of inputting unlimited data into your experience in runtime by using exotic ways such as automacros toggling screen UI elements in-game (like a modem, but using your mouse instead)
the fastest way i can think of is polling your mouse position, calculating screen-space raycast each time it changes; rumors say this allows for a 2000 Hz input rate, and depending on the encoding mechanism you will be using, this potentially allows for hundreds of unicode characters per second, yielding almost 25 kBytes of data per minute; this will definitely allow for inputting simple bitmaps such as QR matrices, and together this yields 2-4 megabytes of data input per minute, combined

this unveils endless possibilities, possibly modding games, changing textures on-the-fly, loading new level packs, and so on… or maybe just use HttpService for this