-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClock.cs
37 lines (33 loc) · 995 Bytes
/
Clock.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Collections.Generic;
// group members: Peter Zhang, Madeline Moore, Cara Cannarozzi
// Crafting Interpreters book by Robert Nystrom used as a reference
// https://craftinginterpreters.com/contents.html
namespace LoxInterpreter
{
/// <summary>
/// implements Clock, a native function of lox
/// </summary>
public class Clock : ILoxCallable
{
public int Arity()
{
return 0;
}
/// <summary>
/// gets current time
/// </summary>
/// <param name="interpreter"></param>
/// <param name="arguments"></param>
/// <returns>time in milliseconds</returns>
public object Call(Interpreter interpreter, List<object> arguments)
{
var millisec = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
return millisec / 1000.0;
}
public override string ToString()
{
return "<native fn>";
}
}
}