Ancestors

Toot

Written by Marc on 2025-01-23 at 12:26

I'm sorry for imparting this cursed knowledge on you today. You already knew lua arrays start at 1 right? Well...

=> View attached media

=> More informations about this toot | More toots from mdiluz@mastodon.gamedev.place

Descendants

Written by Marc on 2025-01-23 at 12:29

Tbf this is only weird when you're thinking of lua as having arrays at all, which it doesn't. It's basically the same in python and doesn't look so weird.

a = {}
for i in range(-5, 5):
    a[i] = i
for i in range(-5, 5):
    print(a[i])

=> More informations about this toot | More toots from mdiluz@mastodon.gamedev.place

Written by RobLoach on 2025-01-23 at 13:13

@mdiluz Thanks, I hate this.

=> More informations about this toot | More toots from RobLoach@fosstodon.org

Written by Dan Schuller on 2025-01-23 at 14:25

@mdiluz @mdiluz To go way into it :D that's the abstraction Lua provides but the -5 to 0 would come out of the dictionary part of the table using their hash value as a key, whereas 1-5 come out the array part of the table. So if you're using the tables as arrays it's treated a little differently underneath to be faster.

=> More informations about this toot | More toots from danschuller@mastodon.gamedev.place

Written by Marc on 2025-01-23 at 16:51

@danschuller Yeah exactly, it's fascinating the path they went there - "Hey you know we could just use a table as an array and special case internally when it looks like you're using it like an array"

Quite elegant imho, in a cursed way.

=> More informations about this toot | More toots from mdiluz@mastodon.gamedev.place

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113877661180853128
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
532.206672 milliseconds
Gemini-to-HTML Time
1.751868 milliseconds

This content has been proxied by September (3851b).