[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Binary and octal literals not currently supported by lua
- From: Tomas Mudrunka <mudrunka@...>
- Date: Wed, 26 Jan 2022 11:09:11 +0100
There is nothing wrong with this approach, quite the opposite. Just
- You can write b'00101010' instead of b('00101010').
- You can use 'tonumber' to do the conversion.
Thanks for your insight, i will use this wrapper (tostring() is optional
or even redundant) as a workaround:
function b(str); return tonumber(tostring(str),2); end;
About performance, as with most constants in programs, it is good
practice to predefine them, so that these conversions are done
only once for each constant.
Exactly. That is why i think it would make sense to have support for
binary literals directly in Lua.
To make it clear i use Lua embedded in C software to provide some
flexibility and scripting to users. The overall design is such that
there is no place for user to predefine constants outside of the Lua
script which gets called from C loop quite often including such base
conversion in each cycle. So i think it would be bit faster if this gets
converted when script gets parsed (or compiled) rather than during
Also it seems it would make sense to keep the syntax symmetric. eg.:
0xFF and 0b11111111
0xFF and b'11111111'
That just triggers my OCD :-)
Tomáš Mudruňka - SPOJE.NET s.r.o.