Qr code generation: what's a callback?

,

I was trying to make an arcade using playdate.graphics.generateQRCode() however it requires a callback. I only know the basics of Lua, Im new to the sdk and I don't know what a callback is. Can anyone please show me an example of what a callback is and how to implement one to the function? thanks

Sincerely, Louq

A callback is just a function that will be called asynchronously, in this case after the QR code image has been generated (see docs). You can pass a function by name and define it elsewhere, or you can just define it anonymously when you pass it in, something like this…

playdate.graphics.generateQRCode(”hello”, 100, function(image, error)
    if image then
        image:drawCentered(200, 120)
    else
        print(error)
    end
end)

You could also store a reference to the image so you can draw it anytime without needing to regenerate it.