I think there may be some confusion.
local paint1 = { type = "image", filename = "images/paint1.png" }
Creates a table with two string elements in it. It’s using zero texture memory.
local paint = {} paint[1] = { type = "image", filename = "images/paint1.png" paint[2] = { type = "image", filename = "images/paint2.png"
would create a table of sub-tables. Texture memory isn’t allocated until you update the “.fill” attribute.
So now the question is 36 tables more efficient than one table with 36 sub-tables. I would say it would be purely on memory consumption, the 36 individual tables would save a few bytes of memory. But Lua only allows you to have 200 local variables and using the 36 takes a chunk of those. Then you have the concept of upvalues, which are where you, inside a function reference a value at a scope higher than that function. You can only have 60 upvalues referenced in any one Lua block, so if you in your function write:
local function button( event ) if id == 1 then square.fill = paint1 elseif id == 2 then square.fill = paint2 else id == 3 then square.fill = paint3 end end
Your reference to paint1, paint2 and paint3 in this example are upvalues. Since you will have 36 of them, you’ve used 36 of your 60 upvalues. If you do a table of sub-tables, you use 1 upvalue. So from that perspective, I would suggest a table of sub-tables. Then you can use a simple index to access it. A table of sub-tables is easily put into an external module.
Rob