The first option is the Lua way. It's what you will find in code written by people familiar with Lua. It takes less vertical space to express the same concept. It is the one I recommend in general.
The second option is more easily understood by people not familiar with Lua, or new to programming. I would use that style if I were doing a tutorial for those people, but not in general.
So decide what your audience is, and choose your style accordingly.
I would also like to say that one-liners are not always the best option - there is a complexity limit below witch it makes sense to split it up in several lines and/or instructions. I think this implementation of clamp is near the limit:
Code: Select all
function clamp(x, min, max)
return math.max(math.min(max, x), min)
Even to those experienced with Lua, it takes some seconds to understand what this does. If this was a bit more complex I would split it.