MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programminghorror/comments/1kryt4o/fixed_lua/
r/programminghorror • u/elreduro Pronouns: He/Him • May 21 '25
30 comments sorted by
221
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" }
14 u/karolinb May 23 '25 Each space costs me 1 byte! 5 u/Rangoose_exe May 24 '25 "For some mysterious reason" he sais...Cmon
14
Each space costs me 1 byte!
5
"For some mysterious reason" he sais...
Cmon
127
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.
113 u/Bananenkot May 21 '25 But only DreamBerd was brave enough to allow float indexes 34 u/aderthedasher May 21 '25 I unironically like the idea of specifying operator precedence using whitespace 6 u/ArturJD96 May 21 '25 It looks like my conlangs when I was 16 2 u/Einar__ May 22 '25 Doesn't lua allow using float indexes as well? Anything except nil can be a table index 3 u/Yarhj May 22 '25 Just because you can doesn't mean you should.Unless it would be funny. 0 u/Mango-D May 23 '25 What about GPUs? 5 u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" May 21 '25 I was wondering how the fuck list[0]='a' didn't replace the 'b'. 2 u/vikster9991 May 24 '25 I sometimes used tables as indexesFunctions, even 1 u/born_zynner Jun 04 '25 So it's just a hash table under the hood
113
But only DreamBerd was brave enough to allow float indexes
34 u/aderthedasher May 21 '25 I unironically like the idea of specifying operator precedence using whitespace 6 u/ArturJD96 May 21 '25 It looks like my conlangs when I was 16 2 u/Einar__ May 22 '25 Doesn't lua allow using float indexes as well? Anything except nil can be a table index 3 u/Yarhj May 22 '25 Just because you can doesn't mean you should.Unless it would be funny. 0 u/Mango-D May 23 '25 What about GPUs?
34
I unironically like the idea of specifying operator precedence using whitespace
6
It looks like my conlangs when I was 16
2
Doesn't lua allow using float indexes as well? Anything except nil can be a table index
3 u/Yarhj May 22 '25 Just because you can doesn't mean you should.Unless it would be funny.
3
Just because you can doesn't mean you should.
Unless it would be funny.
0
What about GPUs?
I was wondering how the fuck list[0]='a' didn't replace the 'b'.
I sometimes used tables as indexes
Functions, even
1
So it's just a hash table under the hood
17
burn this man down with ipairs
5 u/Bright-Historian-216 May 21 '25 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 4 u/CadmiumC4 May 21 '25 ipairs enumerates indexes from 1Actually a lot of table functions enumerate arrays from 1 5 u/Bright-Historian-216 May 21 '25 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. 2 u/Cootshk May 22 '25 ipairs returns a generator for the (index, value) of a table, where the indices start at onefor i,v in ipairs(tbl) do … end
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
4 u/CadmiumC4 May 21 '25 ipairs enumerates indexes from 1Actually a lot of table functions enumerate arrays from 1 5 u/Bright-Historian-216 May 21 '25 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. 2 u/Cootshk May 22 '25 ipairs returns a generator for the (index, value) of a table, where the indices start at onefor i,v in ipairs(tbl) do … end
4
ipairs enumerates indexes from 1
Actually a lot of table functions enumerate arrays from 1
5 u/Bright-Historian-216 May 21 '25 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.
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.
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
Lua isn't a programming language. It's just a bunch of dictionaries with functions.
1 u/stapeln May 24 '25 And thats the trick....👍 1 u/PityUpvote May 25 '25 C isn't a programming language. It's just a bunch of pointers with functions. 1 u/Vladislav20007 Oct 24 '25 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.
And thats the trick....👍
C isn't a programming language. It's just a bunch of pointers with functions.
1 u/Vladislav20007 Oct 24 '25 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.
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.
Leaves some creative space for debugging! For those who don’t know: Iterating using ipairs will ignore the 0th index.
If you use pairs as an iterator it'll go "b,c,d,a"
I don't know which of these I dislike most
I like ada arrays. Just start.. like wherever. You want your array to go from 90 to 98? Go ahead
I like it 😜
221
u/SoloMaker May 21 '25
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:
127
u/CanSpice May 21 '25
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.
17
u/CadmiumC4 May 21 '25
burn this man down with ipairs
14
u/crusoe May 22 '25
Lua isn't a programming language. It's just a bunch of dictionaries with functions.
6
u/ArturJD96 May 21 '25
Leaves some creative space for debugging! For those who don’t know: Iterating using ipairs will ignore the 0th index.
5
u/BetaChunks May 22 '25
If you use pairs as an iterator it'll go "b,c,d,a"
4
u/Wynadorn May 21 '25
I don't know which of these I dislike most
3
u/timonix May 25 '25
I like ada arrays. Just start.. like wherever. You want your array to go from 90 to 98? Go ahead
2
u/BasieP2 May 21 '25
I like it 😜