OsMethods.cs 834 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using MoonSharp.Interpreter.Execution;
  6. namespace MoonSharp.Interpreter.CoreLib
  7. {
  8. [MoonSharpModule(Namespace = "os")]
  9. public class OsMethods
  10. {
  11. static DateTime Time0 = DateTime.UtcNow;
  12. static DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
  13. [MoonSharpMethod]
  14. public static DynValue clock(ScriptExecutionContext executionContext, CallbackArguments args)
  15. {
  16. return DynValue.NewNumber((DateTime.UtcNow - Time0).TotalSeconds);
  17. }
  18. [MoonSharpMethod]
  19. public static DynValue time(ScriptExecutionContext executionContext, CallbackArguments args)
  20. {
  21. DateTime date = DateTime.UtcNow;
  22. if (args.Count > 0)
  23. {
  24. }
  25. return DynValue.NewNumber(Math.Floor(( date - Epoch).TotalSeconds));
  26. }
  27. }
  28. }