lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


you can adjust it.

src/lstrlib.c
static int str_format (lua_State *L) {
...
        case 's': {
          size_t l;
          const char *s = luaL_checklstring(L, arg, &l);
          if (!strchr(form, '.') && l >= 100) {
            /* no precision and string is too long to be formatted;
               keep original string */
            lua_pushvalue(L, arg);
            luaL_addvalue(&b);
            continue;  /* skip the `addsize' at the end */
          }
...
}





---- Em Qua, 18 jan 2023 15:33:23 -0300 Andreas Falkenhahn <andreas@falkenhahn.com> escreveu ---

Hi,

I was wondering why Lua's string.format() limits the width and precision fields to two digits. E.g. this doesn't work in Lua because we use a width of 100 (99 works fine):

string.format('%100s', 'hello world')

Is there any particular reason why Lua imposes this limit on string.format()? I'm just wondering because this restriction sometimes makes it difficult to port C code to Lua.

--
Best regards,
Andreas Falkenhahn mailto:andreas@falkenhahn.com