Lua associative arrays
Posted: Fri Aug 24, 2012 7:18 am
I have this code.
Why can't I access this using indices? Am I doing something wrong?
I could access it through indices using this declaration
However I would like to be able to access it using
Code: Select all
local colors = {
red = { r = 255,g = 0,b = 0 },
green = { r = 0,g = 128,b = 0 },
blue = { r = 0,g = 0,b = 255},
}
Code: Select all
colors[1].r
Code: Select all
local colors = {
{ r = 255,g = 0,b = 0 },
{ r = 0,g = 128,b = 0 },
{ r = 0,g = 0,b = 255},
}
Code: Select all
colors[1].r
-- and
color.red.r