Skip to content
 
 

Latest commit

 

History

5,849 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

betterlua

A fork of Lua that is 0-based instead of 1-based.

Sequences, the table constructor, #, ipairs/next, the C API integer-key functions, and the standard library (tables, strings, utf8, select) all index from 0:

local t = {10, 20, 30}   -- stored at keys 0, 1, 2
print(t[0], t[2], #t)    --> 10  30  3
for i, v in ipairs(t) do print(i, v) end   --> 0 10 / 1 20 / 2 30

print(string.sub("abcd", 0, 1))   --> "ab"
print(string.find("hello", "ll")) --> 2  3

#t is the element count (so valid indices are 0 .. #t-1); for a dense array its numeric value is unchanged from stock Lua. The arg table keeps the conventional layout (arg[0] = script name, arg[1..] = script arguments).

testes/zerobased.lua is a smoke test for the new semantics. The upstream testes/ suite assumes 1-based indexing and is not compatible. Build the interpreter by compiling the core, library, and lua.c with a C99 compiler (see makefile), or via the single-file onelua.c.


Based on the repository of Lua development code, as seen by the Lua team. It contains the full history of all commits but is mirrored irregularly. For complete information about Lua, visit Lua.org.

Please do not send pull requests. To report issues, post a message to the Lua mailing list.

Download official Lua releases from Lua.org.

About

Lua with indexing starting from 0

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages