[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- 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
two details:
- 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.
-- Roberto
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
execution.
Also it seems it would make sense to keep the syntax symmetric. eg.:
0xFF and 0b11111111
rather than
0xFF and b'11111111'
That just triggers my OCD :-)
--
S pozdravem
Best regards
Tomáš Mudruňka - SPOJE.NET s.r.o.