Range
A wrapper for a range of numbers. Used for storing the start and end positions of a selection, and providing utility functions for working with ranges. This class is accessible by accessing the range
field on the main module.
Types
range
interface range { startPosition: number, -- The start position of the range. endPosition: number, -- The end position of the range.}
Functions
new constructor
Range.new( startPosition: number, -- The start position of the range. endPosition: number -- The end position of the range.) → Range
Creates a new range object.
clone
Range:clone() → Range
Clones the range.
fitsInRange
Range:fitsInRange( passedRange: Range -- The range to check if it fits within the range.) → (boolean, -- Whether the range fits within the range.number?, -- The start position of the range if it fits within the range.number? -- The end position of the range if it fits within the range.)
Checks if the passed range fits within the range. If it does, it returns true, and the start and end positions of the range.
get
Range:get() → (number, -- The start position of the range.number -- The end position of the range.)
Gets the start and end positions of the range.
getEnd
Range:getEnd() → number
Gets the end position of the range.
getStart
Range:getStart() → number
Gets the start position of the range.
looselyFitsInRange
Range:looselyFitsInRange( passedRange: Range -- The range to check if it loosely fits within the range.) → (boolean, -- Whether the range loosely fits within the range.number?, -- The start position of the range if it loosely fits within the range.number? -- The end position of the range if it loosely fits within the range.)
Checks if the passed range loosely fits within the range. If it does, it returns true, and the start and end positions of the range.
"Loosely fits" refers to whether any part fits within the range: for example, when passed (10, 20) and (15, 25), it will return true. You'd use this when you want to check whether ranges are overlapping, but not necessarily fully contained within each other.
merge
Range:merge( otherRange: Range -- The range to merge with.) → Range
Merges the range with another range, returning a new range that contains both ranges.
set
Range:set( startPosition: number, -- The new start position of the range. endPosition: number -- The new end position of the range.)
Sets the start and end positions of the range.