lua-users home
lua-l archive

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


> I disagree. It would feel odd to parameterize tostring() just for
> adding a base, and not in arbitrary other extensible ways too, which I
> feel would overcomplicate the function.

I also dislikes adding a base argument to such a general function like
tostring. That function can be called with any Lua type, not just
numbers, and can be even overloaded by __tostring metamethod.

However, the feature itself would be interesting. Even in C, I miss
some simple way to display a number in binary. string.format in Lua,
like sprintf in C, propose a partial way to convert a number to a
string given a base. But that base can only be 10 (%d,%i), 8 (%o) or
16 (%x).
What about a %b for binary, or better, something like %.12b for base 12?