libvips / lua-vips

Lua binding for the libvips image processing library
MIT License
127 stars 10 forks source link

Optimizations / fixes #25

Closed kleisauke closed 6 years ago

kleisauke commented 6 years ago

Hi John,

I had some time to cook up a PR (as requested in https://github.com/jcupitt/lua-vips/issues/24). For easier reviewing, I've split up the changes in multiple commits.

You could also consider to remove the vips_argument_map callback and change it to a pull-style API in libvips (because callbacks are slow in LuaJIT, see here). I already tried to do this (see https://github.com/kleisauke/lua-vips/commit/6d451f0493b788007fafeaf5a53c74547a0430d6), but haven't included it in this PR, because I'm not sure how the API should look like (and I'm not happy with that VipsArgumentNameFlagsArray struct, I think you'll find a better way).

This PR includes

Code improvements

Bug fixes

Unit tests improvements

jcupitt commented 6 years ago

Oh wow, that was quick. OK, I'll try to read through this.

jcupitt commented 6 years ago

That's great! It looks a lot better for you having polished it a bit.

I made some small comments -- the only big thing is "should get() / set() throw an exception?"

Exception handling is a little awkward in Lua, so I can see an argument for a simple error return. The idea was to have get_typeof() and set_type() as the error-return ones, andget()/set()` as the exception ones, but that's a bit awkward too.

kleisauke commented 6 years ago

The reason I removed the exception that was thrown from get() and set() was because voperation assumes that it returns a boolean, see: https://github.com/jcupitt/lua-vips/blob/master/src/vips/voperation.lua#L217-L220 https://github.com/jcupitt/lua-vips/blob/master/src/vips/voperation.lua#L231-L234

In retrospect, this change isn't correct, because get() does not check for return type, see: https://github.com/jcupitt/lua-vips/blob/master/src/vips/voperation.lua#L254 https://github.com/jcupitt/lua-vips/blob/master/src/vips/voperation.lua#L262 https://github.com/jcupitt/lua-vips/blob/master/src/vips/voperation.lua#L273

jcupitt commented 6 years ago

Yes, I think get/set need revising to be more consistent.

Shall we merge this, then do a second pass to fix that up?

kleisauke commented 6 years ago

Sure, you may merge this. I've tried to fix the get/set on a different branch, see commit: https://github.com/kleisauke/lua-vips/commit/2211a4dc36e496a5ae6572bb0318bd49850a15de

Let me know if that looks better.

By the way, I saw that this repo is missing Travis CI. If you want, I could create a new PR to integrate Travis CI into this repo.

jcupitt commented 6 years ago

Sure, Travis would be great!

I'll have a look at your other branch.

kleisauke commented 6 years ago

Thanks for reviewing and merging this PR!

I've just made a PR for Travis CI integration, see: https://github.com/jcupitt/lua-vips/pull/26.