LuaPlatformUtility.cs 809 B

12345678910111213141516171819202122232425262728293031
  1. namespace Lua.Standard.Internal;
  2. public class LuaPlatformUtility
  3. {
  4. public static bool IsSandBox => SupportStdio;
  5. public static bool SupportStdio => _supportStdioTryLazy.Value;
  6. private static Lazy<bool> _supportStdioTryLazy = new Lazy<bool>(() =>
  7. {
  8. try
  9. {
  10. #if NET6_0_OR_GREATER
  11. var isDesktop = System.OperatingSystem.IsWindows() ||
  12. System.OperatingSystem.IsLinux() ||
  13. System.OperatingSystem.IsMacOS();
  14. if (!isDesktop)
  15. {
  16. return false;
  17. }
  18. #endif
  19. _ = Console.OpenStandardInput();
  20. _ = Console.OpenStandardOutput();
  21. return true;
  22. }
  23. catch (Exception)
  24. {
  25. return false;
  26. }
  27. });
  28. }