Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the following lua code does not make sense

Tags:

lua

I have the following bit of lua code. I am not sure what it is doing

width = aspectRatio > 1.5 and 320 or math.ceil( 480 / aspectRatio )

is it a short circuit?

like image 405
user2206329 Avatar asked May 03 '26 03:05

user2206329


1 Answers

It is indeed a short circuit. It's equivalence in c would be:

width = aspectRatio > 1.5 ? 320 : math.ceil( 480 / aspectRatio )

Or in english: if the aspect ratio is greater than 1.5, set the width to 320, otherwise set the width to the smallest integral value that is greater than or equal to the division of 480 and the aspect ratio.

Reference

http://www.lua.org/pil/3.3.html

like image 89
Zach Spencer Avatar answered May 06 '26 19:05

Zach Spencer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!