(53 lines)
1 #!/usr/bin/env nomsu -V7.0.02 ###3 This file defines time-related actions.5 use "core/metaprogramming"6 use "core/operators"7 use "core/control_flow"8 use "core/io"9 use "core/things"11 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~13 external:14 (a Time) is (a thing) with [15 $year, $month, $day, $hour, $min, $sec, $wday, $yday, $isdst16 ]:17 ($self, +$other) means:18 if (($self is "a Time") and ($other is "a Time")):19 fail ("20 Type error: Cannot add two times together.21 Hint: One of these two should be a number, not a time.22 ")24 if ($other isn't "a Number"):25 $other = ($os.time $other)27 if ($self isn't "a Number"):28 $self = ($os.time $self)30 return (a Time ($os.date "*t" ($self + $other, rounded)))32 ($self, -$other) means:33 if ($self isn't "a Time"):34 fail "Type error: Cannot subtract a Time from something that isn't a Time."35 $self = ($os.time $self)36 if ($other is "a Time"):37 return ($os.difftime $self ($os.time $other))38 return (a Time ($os.date "*t" ($self - $other, rounded)))40 ($self, <$other) means (($self, since epoch) < ($other, since epoch))41 ($self, <=$other) means (($self, since epoch) <= ($other, since epoch))42 ($self, as text) means ($os.date "%I:%M%p %a %b %e %Y" ($os.time $self))43 ($self, as text in format $format) means ($os.date $format ($os.time $self))44 ($self, since epoch) means ($os.time $self)46 (now) means:47 return (a Time ($os.date "*t"))49 [sleep for $t seconds, sleep for $t second] all mean:50 ### Lua does not come with a sleep() function, only an os.clock() function,51 so this busy-loop is necessary for cross-platform compatibility.52 $deadline = (($os.clock()) + $t)53 repeat while (($os.clock()) < $deadline): do nothing