love.graphics.newImage() returns userdata instead of Image
Posted: Tue Oct 31, 2023 1:36 am
It may be obvious by the question, but I am new to the lua language. I am not new to programming, however I am far more familiar with traditional OOP as opposed to procedural coding. I am assuming this is just a misunderstanding of the lua language but I don't know.
According to the documentation love.graphics.newImage should return an 'Image' type. However it appears to be returning type of 'userdata' and I can not call the image methods on it. here is a minimal example from my attempt to learn love by making a simple breakout game.
According to the documentation love.graphics.newImage should return an 'Image' type. However it appears to be returning type of 'userdata' and I can not call the image methods on it. here is a minimal example from my attempt to learn love by making a simple breakout game.
Code: Select all
Rect = require'rect'
function love.load()
love.window.setMode(400,500)
-- make block grid
Blocks = {}
local pinkBlock = love.graphics.newImage('assets/block.png') -- output is 'userdata'
print(type(pinkBlock));
for i=0, 20 do
local nextRow = {}
for c=0, 10 do
table.insert(nextRow, {Rect.createRect(pinkBlock)})
end
table.insert(Blocks, nextRow)
end
--set Window Size
love.window.setMode(CalculateGridWidth(Blocks[1]), CalculateGridHeight(Blocks)+200)
end