[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A useful useless fact about Lua keywords
- From: Flyer31 Test <flyer31@...>
- Date: Thu, 16 Sep 2021 12:43:21 +0200
Hi Nicola,
as I understand it, this is a smart trick to write something like
C['A'], and then you get 0x41.
So to check the first string character of str to be 'A', you can then
write str.byte(1,1)== C['A'], and this somehow looks much more nice
than str.byte(1,1)==0x41.. .
And it avoids the memory "mini alloc" if you write str.sub(1,1)== 'a'.
On Thu, Sep 16, 2021 at 8:06 AM Fontana Nicola <ntd@entidi.it> wrote:
>
> Il giorno mer, 15/09/2021 alle 15.16 -0300, Luiz Henrique de Figueiredo ha
> scritto:
> > ...
> > do
> > local C={}
> > for i=0,255 do C[i]=string.char(i); C[C[i]]=i end
> > function char(s,i) return C[s:byte(i)] end
> > end
> > ...
>
> What's the purpose of `C[C[i]]=i`? Can `string.byte` return a string?
>
> Ciao.
> --
> Nicola
>
- References:
- A useful useless fact about Lua keywords, Hugo Musso Gualandi
- Re: A useful useless fact about Lua keywords, Marc Balmer
- Re: A useful useless fact about Lua keywords, Hugo Musso Gualandi
- Re: A useful useless fact about Lua keywords, Flyer31 Test
- Re: A useful useless fact about Lua keywords, Viacheslav Usov
- Re: A useful useless fact about Lua keywords, Philippe Verdy
- Re: A useful useless fact about Lua keywords, Flyer31 Test
- Re: A useful useless fact about Lua keywords, Francisco Olarte
- Re: A useful useless fact about Lua keywords, Flyer31 Test
- Re: A useful useless fact about Lua keywords, Luiz Henrique de Figueiredo
- Re: A useful useless fact about Lua keywords, Fontana Nicola