lua-users home
lua-l archive

Re: Enterring Hex Number

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


glenn-edgar@onyxengr.com wrote:
I have been involved recently in embedding lua in settop products for debug and testing purposes. Working in a hardware environment, there is the need to work with hex numbers. I worked around it by using helper functions, but it is still sort of clumsy in the user had to enter a= hex("0xff00ff") instead of a = 0xff 00
Well, given Lua syntax sugar, you can write:
a = x"FF00FF" or a = h'FF00FF'
which is almost as succint and quite readable too.
Of course, x or h is the function that convert a string to a decimal number. Can be in Lua (I think there are examples around) or in C.
I read previous posting an it appears that the lex part of lua could be extended to do that, but it would mean that I would have modified version away from the baseline.
Any suggestions on the correct approach to handling hex numbers.
You can change Lua to have a syntax familiar to C programmers, but it looks a bit like an overkill to me.
--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --

AltStyle によって変換されたページ (->オリジナル) /