Enterring Hex Number

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Enterring Hex Number

Glenn edgar
Hi everyone

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

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.

Glenn Edgar

Reply | Threaded
Open this post in threaded view
|

Re: Enterring Hex Number

Ben Sunshine-Hill
Modifying the lexer is the standard method.... I think there's even a
standard patch for it, on the lua-users Wiki
(http://lua-users.org/wiki). Don't worry too much about having a
modified version if you're embedding the thing anyway. Lua is easy to
modify, and your changes are unlikely to break it in any way.

On 7/2/05, [hidden email] <[hidden email]> wrote:
> 
> Hi everyone
> 
> 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
> 
> 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.
> 
> Glenn Edgar
>


Reply | Threaded
Open this post in threaded view
|

Re: Enterring Hex Number

Philippe Lhoste
In reply to this post by Glenn edgar
[hidden email] 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
--  --  --  --  --  --  --  --  --  --  --  --  --  --