this post was submitted on 11 Feb 2025
913 points (96.9% liked)

Programmer Humor

20039 readers
1048 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 8 points 2 days ago (1 children)

That's slightly misleading, I think. There are no arrays in Lua, every Lua data structure is a table (sometimes pretending to be something else) and you can have anything as a key as long as it's not nil. There's also no integers, Lua only has a single number type which is floating point. This is perfectly valid:

local tbl = {}
local f = function() error(":(") end

tbl[tbl] = tbl
tbl[f] = tbl
tbl["tbl"] = tbl

print(tbl)
-- table: 0x557a907f0f40
print(tbl[tbl], tbl[f], tbl["tbl"])
-- table: 0x557a907f0f40	table: 0x557a907f0f40	table: 0x557a907f0f40

for key,value in pairs(tbl) do
  print(key, "=", value)
end
-- tbl	=	table: 0x557a907f0f40
-- function: 0x557a907edff0	=	table: 0x557a907f0f40
-- table: 0x557a907f0f40	=	table: 0x557a907f0f40

print(type(1), type(-0.5), type(math.pi), type(math.maxinteger))
-- number	number	number	number