"*all*" 格式在 Lua 中 file:read() 函数中的含义是什么?

我在维护一些使用 LUA 写的旧代码,其中有一些片段我不理解,

    local f = io.open("someFile.lua", "r");
    local szFileContent = "return {};";
    if f then
        szFileContent = f:read("*all");
        f:close();
    end

read 函数中使用的格式有些奇怪,我在 lua51 手册中看到了 *a 和 *l 格式https://www.lua.org/manual/5.1/manual.html#pdf-file:read,但没有看到 *all 格式

点赞
用户7504558
用户7504558

在 liolib.c 中的 read 函数中,只检查字符串的前两个字符 ('*' 和 'a'),字符串的其余部分将被忽略:

// ...
const char *p = lua_tostring(L, n);
luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
switch (p[1]) {
  case 'n':  /* number */
    success = read_number(L, f);
    break;
  case 'l':  /* line */
    success = read_line(L, f);
    break;
  case 'a':  /* file */
    read_chars(L, f, ~((size_t)0));  /* read MAX_SIZE_T chars */
    success = 1; /* always success */
    break;
  default:
    return luaL_argerror(L, n, "invalid format");
 //...
2017-11-14 05:23:50