diff --git a/playdate/imagetable.lua b/playdate/imagetable.lua index 34823cc..4ac8121 100644 --- a/playdate/imagetable.lua +++ b/playdate/imagetable.lua @@ -4,11 +4,20 @@ local module = {} playdate.graphics.imagetable = module local meta = {} -meta.__index = meta -module.__index = meta --- TODO: overload the `[]` array index operator to return an image --- TODO: overload the `#` length operator to return the number of images +meta.__index = function(table, key) + if type(key) == "number" then + return table:getImage(key) + else + return rawget(meta, key) + end +end + +meta.__len = function(table) + return table.length +end + +module.__index = meta -- TODO: handle overloaded signature (count, cellsWide, cellSize) function module.new(path, cellsWide, cellsSize)