I am very new to Lua and am trying to write a short script using the Aseprite API.
The API uses the Image object to represent images.
My understanding of OOP in Lua is that everything is simply a table. There are no classes or objects, just functions that return tables.
I thought, then that I would be able to view all the attributes of an Image object just iterating through it using pairs(table).
-- `image` is and Image object
for attribute, value in pairs(image) do
app.alert(k..": "..v) -- creates an alert window in the Aseprite app
end
I would expect this to show me each attribute and method name available for use. Instead, I just get an error:
lua:2: bad argument #1 to 'for iterator' (table expected, got ImageObj)
How is it possible that this is not just a table? What is this? How might I print all attributes and method names available to me in this 'object'?
userdatalua.org/pil/28.1.html you can make a table with a list of the attribute names, and get the value fromimageusing them in a for loop - Nifimimageis of typeuserdata—or, more specifically, it is anImageObjtype. One can iterate through a userdata type if it has a__pairsmetamethod. - Personage