berry-lang / berry

A ultra-lightweight embedded scripting language optimized for microcontrollers.
https://berry-lang.github.io
MIT License
812 stars 97 forks source link

add min/max to `int()` #435

Closed s-hadinger closed 3 months ago

s-hadinger commented 3 months ago

Follow-up on #431

int() has new parameters min and max to guard value between both values.

int(val:any [, min:int, max:int]) -> int or nil: the value is forced to be between min and max (see unit tests)

Example:

var b = int(a, 0, 10)

is more or less equivalent to:

var b = int(a)
if (a < min)    a = min    end
if (a > max)    a = max    end