Why a "*" in Lua's file:read("*a")?

Viewed 89

Here is a code chunk to read the contents of a file at the given path which seems widely used

local file = open(path, "r")
local content = file:read("*a")
file:close()

People say that "*a" allows to read the whole file but I find no mention of it in the 5.4 reference manual contrary to the "a" format specifier.

What is the meaning of the *?

1 Answers

Asterisk was used in formats in versions before 5.3 (e.g. 4.0 or 5.2).

Currently it's supported for the sake of compatibility: g_read. Formats with and without * are equivalent.

Related