text
stringlengths 0
15.7k
| source
stringlengths 6
112
|
---|---|
set theValue to v of _front
|
lns3.scpt
|
set _front to nextItem of _front
|
lns3.scpt
|
if _front is missing value then set _back to missing value
|
lns3.scpt
|
set _back to missing value
|
lns3.scpt
|
set _front to missing value
|
lns3.scpt
|
to getItem() -- return the value at the front of the queue without removing it
|
lns3.scpt
|
return v of _front
|
lns3.scpt
|
return "«queue collection (" & _count & " items)»"
|
lns3.scpt
|
set newObject to queue collection
|
lns3.scpt
|
set newFront to {v:_front's v, nextItem:missing value}
|
lns3.scpt
|
set newObject's _front to newFront
|
lns3.scpt
|
set oldFront to _front's nextItem
|
lns3.scpt
|
repeat while oldFront is not missing value
|
lns3.scpt
|
set tmp to {v:oldFront's v, nextItem:missing value}
|
lns3.scpt
|
set newFront's nextItem to tmp
|
lns3.scpt
|
set newFront to tmp
|
lns3.scpt
|
set oldFront to oldFront's nextItem
|
lns3.scpt
|
set newObject's _back to newFront
|
lns3.scpt
|
end queue collection
|
lns3.scpt
|
to timer object named nameText : ("")
|
lns3.scpt
|
set nameText to _support's asTextParameter(nameText, "")
|
lns3.scpt
|
script TimerObject
|
lns3.scpt
|
property _startTime : missing value -- because AS can't serialize ASOC objects when saving or autosaving scripts, this object stores start and end times as NSTimeInterval - i.e. AS real - rather than NSDate instances.
|
lns3.scpt
|
property _totalSeconds : 0.0
|
lns3.scpt
|
property _isRunning : false
|
lns3.scpt
|
to timerName()
|
lns3.scpt
|
return nameText
|
lns3.scpt
|
end timerName
|
lns3.scpt
|
to startTimer()
|
lns3.scpt
|
if _isRunning then return
|
lns3.scpt
|
set _isRunning to true
|
lns3.scpt
|
set _startTime to current application's NSDate's timeIntervalSinceReferenceDate()
|
lns3.scpt
|
end startTimer
|
lns3.scpt
|
to stopTimer()
|
lns3.scpt
|
if not _isRunning then return 0
|
lns3.scpt
|
set elapsedTime to (current application's NSDate's timeIntervalSinceReferenceDate()) - _startTime
|
lns3.scpt
|
set _totalSeconds to _totalSeconds + elapsedTime
|
lns3.scpt
|
set _isRunning to false
|
lns3.scpt
|
return elapsedTime
|
lns3.scpt
|
end stopTimer
|
lns3.scpt
|
to elapsedTime()
|
lns3.scpt
|
if _isRunning then
|
lns3.scpt
|
return (NSDate's timeIntervalSinceReferenceDate()) - _startTime
|
lns3.scpt
|
end elapsedTime
|
lns3.scpt
|
to totalTime()
|
lns3.scpt
|
return _totalSeconds + elapsedTime()
|
lns3.scpt
|
return _totalSeconds
|
lns3.scpt
|
end totalTime
|
lns3.scpt
|
set infoText to "elapsed time: " & elapsedTime() & "s"
|
lns3.scpt
|
set infoText to "total time: " & totalTime() & "s"
|
lns3.scpt
|
if nameText's length ≠ 0 then set infoText to "“" & nameText & "” " & infoText
|
lns3.scpt
|
return "«timer object (" & infoText & ")»"
|
lns3.scpt
|
set newObject to timer object named nameText
|
lns3.scpt
|
set newObject's _startTime to _startTime
|
lns3.scpt
|
set newObject's _totalSeconds to _totalSeconds
|
lns3.scpt
|
set newObject's _isRunning to _isRunning
|
lns3.scpt
|
end timer object
|
lns3.scpt
|
_support's throwCommandError("Number", handlerName, eText, eNumber, eFrom, eTo)
|
lns3.scpt
|
property __e__ : 2.71828182846 -- the mathematical constant e (natural logarithm base)
|
lns3.scpt
|
property _isEqualDelta : 1.0E-12 -- multiplier used by `cmp` to allow for slight differences due to floating point's limited precision
|
lns3.scpt
|
property _minDecimalRange : 1.0E-3
|
lns3.scpt
|
property _maxDecimalRange : 1.0E+4
|
lns3.scpt
|
to _asIntegerProperty(theValue, propertyName, minValue) -- note that this doesn't set an upper bound, though very large (silly) numbers may or may not work as intended, depending on what NSNumberFormatter decides to make of them
|
lns3.scpt
|
set n to theValue as integer
|
lns3.scpt
|
if n ≠ theValue as real or n < minValue then error number -1703
|
lns3.scpt
|
on error number -1703
|
lns3.scpt
|
error "The ‘number format definition’ record’s ‘" & propertyName & "’ property is not a non-negative integer." number -1703
|
lns3.scpt
|
end _asIntegerProperty
|
lns3.scpt
|
to _makeNumberFormatter(formatStyle, localeCode, theNumber) -- theNumber is either the number being formatted or `missing value` when parsing; determines appropriate formatting style based on number's type and value when `native format` is specified
|
lns3.scpt
|
set asocFormatter to current application's NSNumberFormatter's alloc()'s init() -- (note that while NSFormatter provides a global +setDefaultFormatterBehavior: option to change all NSNumberFormatters to use pre-10.4 behavior, we don't bother to call setFormatterBehavior: as it's very unlikely nowadays that a host process would change this)
|
lns3.scpt
|
if (count {formatStyle} each record) = 1 then
|
lns3.scpt
|
set formatRecord to _support's asOptionalRecordParameter(formatStyle, {class:(number format record), basicFormat:_support's RequiredValue, minimumDecimalPlaces:missing value, maximumDecimalPlaces:missing value, minimumSignificantDigits:missing value, maximumSignificantDigits:missing value, decimalSeparator:missing value, groupingSeparator:missing value, roundingBehavior:missing value}, "using")
|
lns3.scpt
|
_setBasicFormat(asocFormatter, formatRecord's basicFormat, theNumber)
|
lns3.scpt
|
if formatRecord's minimumDecimalPlaces is not missing value then
|
lns3.scpt
|
asocFormatter's setMinimumFractionDigits:_asIntegerProperty(formatRecord's minimumDecimalPlaces, "minimumDecimalPlaces", 0)
|
lns3.scpt
|
asocFormatter's setMaximumFractionDigits:999 -- kludge for NSNumberFormatterBug; see notes in _setBasicFormat() below
|
lns3.scpt
|
if formatRecord's maximumDecimalPlaces is not missing value then
|
lns3.scpt
|
asocFormatter's setMaximumFractionDigits:_asIntegerProperty(formatRecord's maximumDecimalPlaces, "maximumDecimalPlaces", 0)
|
lns3.scpt
|
if formatRecord's minimumSignificantDigits is not missing value then
|
lns3.scpt
|
asocFormatter's setMinimumSignificantDigits:_asIntegerProperty(formatRecord's minimumSignificantDigits, "minimumSignificantDigits", 0)
|
lns3.scpt
|
asocFormatter's setUsesSignificantDigits:true
|
lns3.scpt
|
if formatRecord's maximumSignificantDigits is not missing value then
|
lns3.scpt
|
asocFormatter's setMaximumSignificantDigits:_asIntegerProperty(formatRecord's maximumSignificantDigits, "maximumSignificantDigits", 0)
|
lns3.scpt
|
if formatRecord's decimalSeparator is not missing value then
|
lns3.scpt
|
set s to formatRecord's decimalSeparator as text
|
lns3.scpt
|
if s's length = 0 then error number -1703
|
lns3.scpt
|
asocFormatter's setDecimalSeparator:s
|
lns3.scpt
|
error "The ‘number format definition’ record’s ‘decimalSeparator’ property is not non-empty text." number -1703
|
lns3.scpt
|
if formatRecord's groupingSeparator is not missing value then
|
lns3.scpt
|
set s to formatRecord's groupingSeparator as text
|
lns3.scpt
|
if s's length = 0 then
|
lns3.scpt
|
asocFormatter's setUsesGroupingSeparator:false
|
lns3.scpt
|
asocFormatter's setUsesGroupingSeparator:true
|
lns3.scpt
|
asocFormatter's setGroupingSeparator:s
|
lns3.scpt
|
error "The ‘number format definition’ record’s ‘groupingSeparator’ property is not text." number -1703
|
lns3.scpt
|
if formatRecord's roundingBehavior is not missing value then
|
lns3.scpt
|
if formatRecord's roundingBehavior is (rounding halves to even) then
|
lns3.scpt
|
asocFormatter's setRoundingMode:(current application's NSNumberFormatterRoundHalfEven)
|
lns3.scpt
|
else if formatRecord's roundingBehavior is (rounding halves toward zero) then
|
lns3.scpt
|
asocFormatter's setRoundingMode:(current application's NSNumberFormatterRoundHalfDown)
|
lns3.scpt
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.