Cottient
Cottient

Reputation: 164

Why can't I reference to a table without variables in lua?

The following code works as expected:

local t = {}
print(t[1])

The above will print nil. How come the following code results in an error?

print({}[1])

What is the logic behind this?

Upvotes: 1

Views: 73

Answers (1)

DarkWiiPlayer
DarkWiiPlayer

Reputation: 7064

You can:

print(({"a", "b", "c"})[2]) -- "b"

Upvotes: 1

Related Questions