lua-users home
lua-l archive

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


That code is creating a table C mapping byte values 0 to 255 into a string, and mapping back that string to the highest byte value that generated it (so aftercthe loop there's no warranty that C[C[100]]==100, it could be C[C[100]]==228 on a 7-bit machine.


String:byte() never returns a string but but numeric values.
When you get C[string:byte(...)], You could get an error if byte() does not returns any value because you trybto read at a nil Key in table C.


Le jeu. 16 sept. 2021 à 08:06, Fontana Nicola <ntd@entidi.it> a écrit :
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