Page 1 of 1

[SOLVED] Pass a canvas (userdata) to a function

Posted: Wed Mar 22, 2023 1:41 pm
by DjPoke
Hi,

I'm trying to pass a canvas id to a function. The canvas id is an userdata, but inside the function, it become a number.
So i get an error. Sorry for the noob question but what should i do to keep my canvas id usable by my function ?

Code: Select all

function draw_9slice(num, width, height, canvas)
    love.graphics.setCanvas(canvas)

[...]

Re: Pass a canvas (userdata) to a function

Posted: Wed Mar 22, 2023 2:39 pm
by pgimeno
I don't even know what you mean by a canvas id, because canvases are objects and can be used the way you're trying to use them. If you get a number instead of an object, maybe you're passing one number too much to your function and the canvas is in the fifth parameter instead of fourth. This code does not give any error:

Code: Select all

function draw_9slice(num, width, height, canvas)
    love.graphics.setCanvas(canvas)

    love.graphics.setCanvas()
end

local canvas = love.graphics.newCanvas()
draw_9slice(1, 2, 3, canvas)
(first two lines copied verbatim from your post)

Re: Pass a canvas (userdata) to a function

Posted: Wed Mar 22, 2023 3:13 pm
by DjPoke
Hi pgimeno,
I've checked but its not the case. This is the source code...
minGUI.zip
(3.57 KiB) Downloaded 26 times

Re: Pass a canvas (userdata) to a function

Posted: Wed Mar 22, 2023 3:19 pm
by DjPoke
Sorry, you are right. I've not checked the right place... :)
Thank you !