Semior001

range function lua

Jan 6th, 2020
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.49 KB | None | 0 0
  1. function range(a, b, step)
  2.   if not b then
  3.     b = a
  4.     a = 1
  5.   end
  6.   step = step or 1
  7.   local f =
  8.     step > 0 and
  9.       function(_, lastvalue)
  10.         local nextvalue = lastvalue + step
  11.         if nextvalue <= b then return nextvalue end
  12.       end or
  13.     step < 0 and
  14.       function(_, lastvalue)
  15.         local nextvalue = lastvalue + step
  16.         if nextvalue >= b then return nextvalue end
  17.       end or
  18.       function(_, lastvalue) return lastvalue end
  19.   return f, nil, a - step
  20. end
Add Comment
Please, Sign In to add comment