Page 1 of 1
Creating an instance of the Image class from C++ and pushing it to Lua
Posted: Fri Jun 29, 2018 4:25 pm
by Whatthefuck
Hello, I am trying to create an instance of the Image class with raw data read from downloading an image file from a URL on the C/C++ side of things and push it to Lua when needed. I am looking through the C code, but I see no clear way of doing this. Can someone help me out here?
Re: Creating an instance of the Image class from C++ and pushing it to Lua
Posted: Sat Jun 30, 2018 2:49 am
by pgimeno
One way would be to pass the raw image data to Lua as a string, so you can use
love.image.newImageData from Lua to turn it into an ImageData object that you can easily convert to Image.
Re: Creating an instance of the Image class from C++ and pushing it to Lua
Posted: Sat Jun 30, 2018 7:54 am
by bartbes
This is kind of vague, what do you want to know? You can definitely just instantiate an Image. Are you looking for luax_pushtype?
Re: Creating an instance of the Image class from C++ and pushing it to Lua
Posted: Sun Jul 01, 2018 10:43 am
by Whatthefuck
pgimeno wrote: ↑Sat Jun 30, 2018 2:49 am
One way would be to pass the raw image data to Lua as a string, so you can use
love.image.newImageData from Lua to turn it into an ImageData object that you can easily convert to Image.
Yeah, this is what I'm starting thinking of doing since I don't see a clear way of doing that on the C side of things. Maybe I'm just blind.
bartbes wrote: ↑Sat Jun 30, 2018 7:54 am
This is kind of vague, what do you want to know? You can definitely just instantiate an Image. Are you looking for luax_pushtype?
I download an image from a URL via C, and it gets stored on the memory as raw data, which I then would like to use to create an Image object. The downloaded image can be either a .jpg or .png file. I'm having trouble finding an easy way of creating an image from the data I've downloaded that isn't pushing the string to Lua and then calling the necessary methods from there.
Re: Creating an instance of the Image class from C++ and pushing it to Lua
Posted: Sun Jul 01, 2018 11:33 am
by bartbes
Well, you create a FileData from the downloaded data, then create an ImageData from that, you then use that ImageData to create an Image::Slices object, and use that to create an Image.
Re: Creating an instance of the Image class from C++ and pushing it to Lua
Posted: Mon Jul 02, 2018 11:02 am
by zorg
To be honest, my first question would be why exactly are you going the C route for downloading the images? That should be possible from löve as well.