lua-users home
lua-l archive

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


> On Mar 31, 2018, at 10:31 AM, Enrico Colombini <erix@erix.it> wrote:
> 
> I started with 6502 assembly (0-based) then learned BASIC (1-based) then C (0-based) then Pascal (1-based) then... well, you get the idea :-)
> 
> After a while you just get used to think in the context of the language you are writing in, even when you are mixing them in the same project.
> 
> As Marc Balmer said, it is the same as for human languages.
> 
> -- 
>  Enrico
> 

You can use lua table with arbitrary base by using the hash part:

local k = {[0]=0, 1}   -- 0-based table

Above is actual code of my primepi.lua (line 20)
Doing it in 1-based array is messy and slower.

https://github.com/achan001/PrimePi/blob/master/primepi.lua