Creating an instance of the Image class from C++ and pushing it to Lua

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
Whatthefuck
Party member
Posts: 106
Joined: Sat Jun 21, 2014 3:45 pm

Creating an instance of the Image class from C++ and pushing it to Lua

Post by Whatthefuck » Fri Jun 29, 2018 4:25 pm

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?

User avatar
pgimeno
Party member
Posts: 2305
Joined: Sun Oct 18, 2015 2:58 pm

Re: Creating an instance of the Image class from C++ and pushing it to Lua

Post by pgimeno » 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.

User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Creating an instance of the Image class from C++ and pushing it to Lua

Post by bartbes » 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?

Whatthefuck
Party member
Posts: 106
Joined: Sat Jun 21, 2014 3:45 pm

Re: Creating an instance of the Image class from C++ and pushing it to Lua

Post by Whatthefuck » Sun Jul 01, 2018 10:43 am

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.

User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Creating an instance of the Image class from C++ and pushing it to Lua

Post by bartbes » Sun Jul 01, 2018 11:33 am

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.

User avatar
zorg
Party member
Posts: 2992
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Creating an instance of the Image class from C++ and pushing it to Lua

Post by zorg » Mon Jul 02, 2018 11:02 am

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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests