lua-users home
lua-l archive

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


Hi All!

I already asked the opinion of Lua Team about this when work2 came out, I got some remarks from lua-l members, but I got no "official" response, so I dare bump it up.

A couple of features I'd like to see implemented would be:

1. Binary literals, such as 0b100101101, or something like that.

2. A non-significant digit separator (say "_") for better readability of long numbers:

1111_222_333_4444 would be parsed (lexed?) as 1111222333444,
of course banning the underscore from the beginning and the end.

Even more useful for 64bit hex literals or binary literals (if implemented):

0xaabef_bee1_1230_aabb
0b1001_1100_1111_001_1_111

(useful when representing some register or binary data structure layout).

The digit separator thing seems almost zero-cost (skip a char in the lexer, I guess). Binary literal may be a little more expensive, but since tonumber already handles the translation in the language, maybe some code reuse under the hood could make this change very lightweight.

Do Lua Team think they could be added to a next version? I think the convenience is very high (now that "bit fiddling" in Lua has been graced with 64bit ints and binops) with very few drawbacks.

BTW, I would find that much more useful than the currently supported hexadecimal float literals (in my use cases, of course).


Thanks!

-- Lorenzo

P.s: I know both features can be emulated somehow in the language, but having them built-in, with no runtime overhead, would be nice, especially when handling large tables of values in such form.