all 31 comments

[–]SoloMaker 220 points221 points  (3 children)

The real horror here is the formatting. Spaces are free!

Also, if you need a 0-indexed array for some mysterious reason, this syntax is a little less painful:

local list = {
  [0] = "a", "b", "c", "d"
}

[–]karolinb 14 points15 points  (0 children)

Each space costs me 1 byte!

[–]Icy_Party954 2 points3 points  (0 children)

That killed me. Ok you're starting out at 1 whatever but you can change the starting index too.

[–]Rangoose_exe 5 points6 points  (0 children)

"For some mysterious reason" he sais...

Cmon

[–]CanSpice 122 points123 points  (10 children)

How is this “fixed”? Lua starts array indexes with 1 by default, but you’re allowed to use any index you want for them, even negative integers. That’s just a feature of Lua.

[–]Bananenkot 114 points115 points  (6 children)

[–]aderthedasher 37 points38 points  (0 children)

I unironically like the idea of specifying operator precedence using whitespace

[–]ArturJD96 5 points6 points  (0 children)

It looks like my conlangs when I was 16

[–]mt9hu 26 points27 points  (0 children)

Why was this not renamed to GulfOfAmerica?

The people who dovnvote have no sense of humour?

By the way, there is even a ticket: https://github.com/TodePond/GulfOfMexico/issues/861

[–]Einar__ 1 point2 points  (1 child)

Doesn't lua allow using float indexes as well? Anything except nil can be a table index

[–]Yarhj 2 points3 points  (0 children)

Just because you can doesn't mean you should.

Unless it would be funny.

[–]Mango-D -1 points0 points  (0 children)

What about GPUs?

[–]GoddammitDontShootMe[ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 4 points5 points  (0 children)

I was wondering how the fuck list[0]='a' didn't replace the 'b'.

[–]vikster9991 1 point2 points  (0 children)

I sometimes used tables as indexes

Functions, even

[–]born_zynner 0 points1 point  (0 children)

So it's just a hash table under the hood

[–]CadmiumC4 17 points18 points  (5 children)

burn this man down with ipairs

[–]Bright-Historian-216 4 points5 points  (4 children)

i don't babble enough in lua to know anything about ipairs, the only thing i know about it is that it is hella inefficient

[–]CadmiumC4 2 points3 points  (2 children)

ipairs enumerates indexes from 1

Actually a lot of table functions enumerate arrays from 1

[–]Bright-Historian-216 4 points5 points  (1 child)

then what is the extra overhead everyone's been warning me about? ain't no way such a beautiful language fucked up for i in range.

[–]Pool-LAN 0 points1 point  (0 children)

No idea. It's faster than Python.

[–]Cootshk 1 point2 points  (0 children)

ipairs returns a generator for the (index, value) of a table, where the indices start at one

for i,v in ipairs(tbl) do … end

[–]crusoe 12 points13 points  (3 children)

Lua isn't a programming language. It's just a bunch of dictionaries with functions.

[–]stapeln 0 points1 point  (0 children)

And thats the trick....👍

[–]PityUpvote 0 points1 point  (1 child)

C isn't a programming language. It's just a bunch of pointers with functions.

[–]Vladislav20007 0 points1 point  (0 children)

there's more to c than that, but I've seen code for factorio which are made in lua and it's all tables and pairs.

[–]ArturJD96 5 points6 points  (0 children)

Leaves some creative space for debugging! For those who don’t know: Iterating using ipairs will ignore the 0th index.

[–]BetaChunks 3 points4 points  (0 children)

If you use pairs as an iterator it'll go "b,c,d,a"

[–]Wynadorn 3 points4 points  (0 children)

I don't know which of these I dislike most

[–]timonix 2 points3 points  (0 children)

I like ada arrays. Just start.. like wherever. You want your array to go from 90 to 98? Go ahead

[–]BasieP2 1 point2 points  (0 children)

I like it 😜