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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
DjPoke
Prole
Posts: 11
Joined: Fri Apr 15, 2022 10:41 am
Location: Corsica (France)
Contact:

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

Post 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)

[...]
Last edited by DjPoke on Wed Mar 22, 2023 3:20 pm, edited 1 time in total.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Pass a canvas (userdata) to a function

Post 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)
DjPoke
Prole
Posts: 11
Joined: Fri Apr 15, 2022 10:41 am
Location: Corsica (France)
Contact:

Re: Pass a canvas (userdata) to a function

Post 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
DjPoke
Prole
Posts: 11
Joined: Fri Apr 15, 2022 10:41 am
Location: Corsica (France)
Contact:

Re: Pass a canvas (userdata) to a function

Post by DjPoke »

Sorry, you are right. I've not checked the right place... :)
Thank you !
Post Reply

Who is online

Users browsing this forum: No registered users and 39 guests