From 97161f0c8532accb7f8c03096125c4f1857568bd Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Wed, 19 Apr 2023 22:06:14 +0200 Subject: [PATCH] Timers now use seconds instead of ms. Append "Lib" to all libraries class names. --- .../Lua/CapyOS/sys/bin/fun/mandelbrot.lua | 2 +- Capy64/Assets/Lua/CapyOS/sys/bin/fun/melt.lua | 4 +- Capy64/Assets/Lua/CapyOS/sys/bin/reboot.lua | 2 +- Capy64/Assets/Lua/CapyOS/sys/bin/shutdown.lua | 2 +- .../Lua/CapyOS/sys/boot/autorun/02_timer.lua | 1 - Capy64/Assets/Lua/bios.lua | 2 +- Capy64/Capy64.cs | 6 +- .../Libraries/{Audio.cs => AudioLib.cs} | 8 +- .../Libraries/{Event.cs => EventLib.cs} | 8 +- .../{FileSystem.cs => FileSystemLib.cs} | 8 +- .../Runtime/Libraries/{GPU.cs => GPULib.cs} | 10 +- .../Runtime/Libraries/{HTTP.cs => HTTPLib.cs} | 8 +- .../Libraries/{Machine.cs => MachineLib.cs} | 8 +- .../Runtime/Libraries/{TCP.cs => TCPLib.cs} | 8 +- .../Runtime/Libraries/{Term.cs => TermLib.cs} | 8 +- .../Libraries/{Timer.cs => TimerLib.cs} | 98 ++++++++++--------- Capy64/Runtime/Objects/Task.cs | 2 +- Capy64/Runtime/Objects/WebSocketClient.cs | 2 +- Capy64/Runtime/PanicScreen.cs | 36 +++---- Capy64/Runtime/RuntimeManager.cs | 8 +- Capy64/Runtime/Sandbox.cs | 4 +- 21 files changed, 123 insertions(+), 112 deletions(-) rename Capy64/Runtime/Libraries/{Audio.cs => AudioLib.cs} (97%) rename Capy64/Runtime/Libraries/{Event.cs => EventLib.cs} (97%) rename Capy64/Runtime/Libraries/{FileSystem.cs => FileSystemLib.cs} (98%) rename Capy64/Runtime/Libraries/{GPU.cs => GPULib.cs} (98%) rename Capy64/Runtime/Libraries/{HTTP.cs => HTTPLib.cs} (98%) rename Capy64/Runtime/Libraries/{Machine.cs => MachineLib.cs} (96%) rename Capy64/Runtime/Libraries/{TCP.cs => TCPLib.cs} (94%) rename Capy64/Runtime/Libraries/{Term.cs => TermLib.cs} (99%) rename Capy64/Runtime/Libraries/{Timer.cs => TimerLib.cs} (59%) diff --git a/Capy64/Assets/Lua/CapyOS/sys/bin/fun/mandelbrot.lua b/Capy64/Assets/Lua/CapyOS/sys/bin/fun/mandelbrot.lua index 1dcbf6c..5d4268b 100644 --- a/Capy64/Assets/Lua/CapyOS/sys/bin/fun/mandelbrot.lua +++ b/Capy64/Assets/Lua/CapyOS/sys/bin/fun/mandelbrot.lua @@ -51,7 +51,7 @@ local function draw() end -- no idea why it's needed -timer.sleep(1) +timer.sleep(0) draw() diff --git a/Capy64/Assets/Lua/CapyOS/sys/bin/fun/melt.lua b/Capy64/Assets/Lua/CapyOS/sys/bin/fun/melt.lua index fd2adc4..f059b09 100644 --- a/Capy64/Assets/Lua/CapyOS/sys/bin/fun/melt.lua +++ b/Capy64/Assets/Lua/CapyOS/sys/bin/fun/melt.lua @@ -30,7 +30,7 @@ local function melt() end gpu.setBuffer(buffer) - timer.delay(10):await() + timer.delay(0):await() end end @@ -66,7 +66,7 @@ local function random() ) end - timer.delay(100):await() + timer.delay(0.1):await() end end diff --git a/Capy64/Assets/Lua/CapyOS/sys/bin/reboot.lua b/Capy64/Assets/Lua/CapyOS/sys/bin/reboot.lua index 3dfbb5a..78cf97d 100644 --- a/Capy64/Assets/Lua/CapyOS/sys/bin/reboot.lua +++ b/Capy64/Assets/Lua/CapyOS/sys/bin/reboot.lua @@ -3,6 +3,6 @@ local machine = require("machine") print("Goodbye!") -timer.sleep(1000) +timer.sleep(1) machine.reboot() diff --git a/Capy64/Assets/Lua/CapyOS/sys/bin/shutdown.lua b/Capy64/Assets/Lua/CapyOS/sys/bin/shutdown.lua index b1fb35b..cb3016e 100644 --- a/Capy64/Assets/Lua/CapyOS/sys/bin/shutdown.lua +++ b/Capy64/Assets/Lua/CapyOS/sys/bin/shutdown.lua @@ -3,6 +3,6 @@ local machine = require("machine") print("Goodbye!") -timer.sleep(1000) +timer.sleep(1) machine.shutdown() diff --git a/Capy64/Assets/Lua/CapyOS/sys/boot/autorun/02_timer.lua b/Capy64/Assets/Lua/CapyOS/sys/boot/autorun/02_timer.lua index ae933fc..a33ad60 100644 --- a/Capy64/Assets/Lua/CapyOS/sys/boot/autorun/02_timer.lua +++ b/Capy64/Assets/Lua/CapyOS/sys/boot/autorun/02_timer.lua @@ -5,7 +5,6 @@ local range = require("expect").range function timer.sleep(n) expect(1, n, "number") - range(1, 1) local timerId = timer.start(n) repeat diff --git a/Capy64/Assets/Lua/bios.lua b/Capy64/Assets/Lua/bios.lua index 541278d..0b9ad22 100644 --- a/Capy64/Assets/Lua/bios.lua +++ b/Capy64/Assets/Lua/bios.lua @@ -21,7 +21,7 @@ local machine = require("machine") local audio = require("audio") local event = require("event") -local bootSleep = 2000 +local bootSleep = 2 local bg = 0x0 local fg = 0xffffff diff --git a/Capy64/Capy64.cs b/Capy64/Capy64.cs index 006f3d0..8eb8642 100644 --- a/Capy64/Capy64.cs +++ b/Capy64/Capy64.cs @@ -89,6 +89,7 @@ public class Capy64 : Game, IGame public LuaState LuaRuntime { get; set; } public Eventing.EventEmitter EventEmitter { get; private set; } public DiscordIntegration Discord { get; set; } + public int TickRate => tickrate; public Color BorderColor { get; set; } = Color.Black; public Borders Borders = new() @@ -106,7 +107,8 @@ public class Capy64 : Game, IGame private readonly GraphicsDeviceManager _graphics; private IServiceProvider _serviceProvider; private ulong _totalTicks = 0; - private ulong tickrate = 0; + private int tickrate = 0; + private int everyTick => 60 / tickrate; public Capy64() { @@ -274,7 +276,7 @@ public class Capy64 : Game, IGame { GameTime = gameTime, TotalTicks = _totalTicks, - IsActiveTick = _totalTicks % (60 / tickrate) == 0, + IsActiveTick = (int)_totalTicks % everyTick == 0, }); Drawing.End(); diff --git a/Capy64/Runtime/Libraries/Audio.cs b/Capy64/Runtime/Libraries/AudioLib.cs similarity index 97% rename from Capy64/Runtime/Libraries/Audio.cs rename to Capy64/Runtime/Libraries/AudioLib.cs index c22ab8d..7168a62 100644 --- a/Capy64/Runtime/Libraries/Audio.cs +++ b/Capy64/Runtime/Libraries/AudioLib.cs @@ -21,18 +21,18 @@ using static Capy64.Core.Audio; namespace Capy64.Runtime.Libraries; -public class Audio : IComponent +public class AudioLib : IComponent { private const int queueLimit = 8; private static IGame _game; - public Audio(IGame game) + public AudioLib(IGame game) { _game = game; _game.EventEmitter.OnClose += OnClose; } - private static readonly LuaRegister[] AudioLib = new LuaRegister[] + private static readonly LuaRegister[] Library = new LuaRegister[] { new() { @@ -85,7 +85,7 @@ public class Audio : IComponent private static int OpenLib(IntPtr state) { var L = Lua.FromIntPtr(state); - L.NewLib(AudioLib); + L.NewLib(Library); return 1; } diff --git a/Capy64/Runtime/Libraries/Event.cs b/Capy64/Runtime/Libraries/EventLib.cs similarity index 97% rename from Capy64/Runtime/Libraries/Event.cs rename to Capy64/Runtime/Libraries/EventLib.cs index e1ab522..2170596 100644 --- a/Capy64/Runtime/Libraries/Event.cs +++ b/Capy64/Runtime/Libraries/EventLib.cs @@ -20,7 +20,7 @@ using System; namespace Capy64.Runtime.Libraries; -public class Event : IComponent +public class EventLib : IComponent { private const int MaxPushQueue = 64; private static int PushQueue = 0; @@ -30,12 +30,12 @@ public class Event : IComponent private static bool FrozenTaskAwaiter = false; private static IGame _game; - public Event(IGame game) + public EventLib(IGame game) { _game = game; } - private static readonly LuaRegister[] EventLib = new LuaRegister[] + private static readonly LuaRegister[] Library = new LuaRegister[] { new() { @@ -88,7 +88,7 @@ public class Event : IComponent private static int OpenLib(IntPtr state) { var L = Lua.FromIntPtr(state); - L.NewLib(EventLib); + L.NewLib(Library); return 1; } diff --git a/Capy64/Runtime/Libraries/FileSystem.cs b/Capy64/Runtime/Libraries/FileSystemLib.cs similarity index 98% rename from Capy64/Runtime/Libraries/FileSystem.cs rename to Capy64/Runtime/Libraries/FileSystemLib.cs index 1dcda59..af93c48 100644 --- a/Capy64/Runtime/Libraries/FileSystem.cs +++ b/Capy64/Runtime/Libraries/FileSystemLib.cs @@ -24,11 +24,11 @@ using System.Linq; namespace Capy64.Runtime.Libraries; -public class FileSystem : IComponent +public class FileSystemLib : IComponent { public static string DataPath = Path.Combine(Capy64.AppDataPath, "data"); - public FileSystem() + public FileSystemLib() { if (!Directory.Exists(DataPath)) { @@ -37,7 +37,7 @@ public class FileSystem : IComponent } // functions to add to the library, always end libraries with null - private readonly LuaRegister[] FsLib = new LuaRegister[] { + private readonly LuaRegister[] Library = new LuaRegister[] { new() { name = "list", @@ -120,7 +120,7 @@ public class FileSystem : IComponent private int Open(IntPtr state) { var l = Lua.FromIntPtr(state); - l.NewLib(FsLib); + l.NewLib(Library); return 1; } diff --git a/Capy64/Runtime/Libraries/GPU.cs b/Capy64/Runtime/Libraries/GPULib.cs similarity index 98% rename from Capy64/Runtime/Libraries/GPU.cs rename to Capy64/Runtime/Libraries/GPULib.cs index 5e97b8b..8dc8986 100644 --- a/Capy64/Runtime/Libraries/GPU.cs +++ b/Capy64/Runtime/Libraries/GPULib.cs @@ -25,16 +25,16 @@ using System.Threading.Tasks; namespace Capy64.Runtime.Libraries; -public class GPU : IComponent +public class GPULib : IComponent { private static IGame _game; - public GPU(IGame game) + public GPULib(IGame game) { _game = game; } - private readonly LuaRegister[] gpuLib = new LuaRegister[] { + private readonly LuaRegister[] Library = new LuaRegister[] { new() { name = "getSize", @@ -141,7 +141,7 @@ public class GPU : IComponent public int OpenLib(IntPtr state) { var l = Lua.FromIntPtr(state); - l.NewLib(gpuLib); + l.NewLib(Library); return 1; } @@ -483,7 +483,7 @@ public class GPU : IComponent var path = L.CheckString(1); - path = FileSystem.Resolve(path); + path = FileSystemLib.Resolve(path); if (!File.Exists(path)) { diff --git a/Capy64/Runtime/Libraries/HTTP.cs b/Capy64/Runtime/Libraries/HTTPLib.cs similarity index 98% rename from Capy64/Runtime/Libraries/HTTP.cs rename to Capy64/Runtime/Libraries/HTTPLib.cs index 8dc0df5..5abb155 100644 --- a/Capy64/Runtime/Libraries/HTTP.cs +++ b/Capy64/Runtime/Libraries/HTTPLib.cs @@ -28,7 +28,7 @@ using System.Threading; namespace Capy64.Runtime.Libraries; #nullable enable -public class HTTP : IComponent +public class HTTPLib : IComponent { private static IGame _game; private static HttpClient _httpClient; @@ -38,7 +38,7 @@ public class HTTP : IComponent public static readonly string UserAgent = $"Capy64/{Capy64.Version}"; private static IConfiguration _configuration; - private readonly LuaRegister[] HttpLib = new LuaRegister[] + private readonly LuaRegister[] Library = new LuaRegister[] { new() { @@ -57,7 +57,7 @@ public class HTTP : IComponent }, new(), }; - public HTTP(IGame game, IConfiguration configuration) + public HTTPLib(IGame game, IConfiguration configuration) { _game = game; _requestId = 0; @@ -75,7 +75,7 @@ public class HTTP : IComponent private int Open(IntPtr state) { var L = Lua.FromIntPtr(state); - L.NewLib(HttpLib); + L.NewLib(Library); return 1; } diff --git a/Capy64/Runtime/Libraries/Machine.cs b/Capy64/Runtime/Libraries/MachineLib.cs similarity index 96% rename from Capy64/Runtime/Libraries/Machine.cs rename to Capy64/Runtime/Libraries/MachineLib.cs index 02b3342..e92b502 100644 --- a/Capy64/Runtime/Libraries/Machine.cs +++ b/Capy64/Runtime/Libraries/MachineLib.cs @@ -22,15 +22,15 @@ using System; namespace Capy64.Runtime.Libraries; -public class Machine : IComponent +public class MachineLib : IComponent { private static IGame _game; - public Machine(IGame game) + public MachineLib(IGame game) { _game = game; } - private static readonly LuaRegister[] MachineLib = new LuaRegister[] + private static readonly LuaRegister[] Library = new LuaRegister[] { new() { @@ -83,7 +83,7 @@ public class Machine : IComponent private static int OpenLib(IntPtr state) { var L = Lua.FromIntPtr(state); - L.NewLib(MachineLib); + L.NewLib(Library); return 1; } diff --git a/Capy64/Runtime/Libraries/TCP.cs b/Capy64/Runtime/Libraries/TCPLib.cs similarity index 94% rename from Capy64/Runtime/Libraries/TCP.cs rename to Capy64/Runtime/Libraries/TCPLib.cs index ff2b1da..0663b68 100644 --- a/Capy64/Runtime/Libraries/TCP.cs +++ b/Capy64/Runtime/Libraries/TCPLib.cs @@ -19,17 +19,17 @@ using System.Net.Sockets; namespace Capy64.Runtime.Libraries; -public class TCP : IComponent +public class TCPLib : IComponent { private static int Counter = 0; private static IGame _game; - public TCP(IGame game) + public TCPLib(IGame game) { _game = game; Counter = 0; } - private static readonly LuaRegister[] TCPLib = new LuaRegister[] + private static readonly LuaRegister[] Library = new LuaRegister[] { new() { @@ -47,7 +47,7 @@ public class TCP : IComponent public int OpenLib(nint state) { var L = Lua.FromIntPtr(state); - L.NewLib(TCPLib); + L.NewLib(Library); return 1; } diff --git a/Capy64/Runtime/Libraries/Term.cs b/Capy64/Runtime/Libraries/TermLib.cs similarity index 99% rename from Capy64/Runtime/Libraries/Term.cs rename to Capy64/Runtime/Libraries/TermLib.cs index bf305fd..5460471 100644 --- a/Capy64/Runtime/Libraries/Term.cs +++ b/Capy64/Runtime/Libraries/TermLib.cs @@ -23,7 +23,7 @@ using static Capy64.Utils; namespace Capy64.Runtime.Libraries; -internal class Term : IComponent +internal class TermLib : IComponent { private struct Char { @@ -53,7 +53,7 @@ internal class Term : IComponent private static bool cursorState = false; private static bool enableCursor = true; private static Texture2D cursorTexture; - public Term(IGame game) + public TermLib(IGame game) { _game = game; @@ -72,7 +72,7 @@ internal class Term : IComponent _game.EventEmitter.OnScreenSizeChange += OnScreenSizeChange; } - private readonly LuaRegister[] TermLib = new LuaRegister[] + private readonly LuaRegister[] Library = new LuaRegister[] { new() { @@ -170,7 +170,7 @@ internal class Term : IComponent public int Open(IntPtr state) { var l = Lua.FromIntPtr(state); - l.NewLib(TermLib); + l.NewLib(Library); return 1; } diff --git a/Capy64/Runtime/Libraries/Timer.cs b/Capy64/Runtime/Libraries/TimerLib.cs similarity index 59% rename from Capy64/Runtime/Libraries/Timer.cs rename to Capy64/Runtime/Libraries/TimerLib.cs index d0f9246..bf36bb6 100644 --- a/Capy64/Runtime/Libraries/Timer.cs +++ b/Capy64/Runtime/Libraries/TimerLib.cs @@ -21,9 +21,15 @@ using System.Collections.Concurrent; namespace Capy64.Runtime.Libraries; -class Timer : IComponent +class TimerLib : IComponent { - private readonly LuaRegister[] TimerLib = new LuaRegister[] + public class Timer + { + public int RemainingTicks = 0; + public TaskMeta.RuntimeTask? Task; + } + + private readonly LuaRegister[] Library = new LuaRegister[] { new() { @@ -47,22 +53,51 @@ class Timer : IComponent private static IGame _game; private static uint _timerId = 0; - private static readonly ConcurrentDictionary timers = new(); - public Timer(IGame game) + private static readonly ConcurrentDictionary timers = new(); + public TimerLib(IGame game) { _game = game; + + _game.EventEmitter.OnTick += OnTick; + } + + private void OnTick(object sender, Eventing.Events.TickEvent e) + { + if (e.IsActiveTick) + { + foreach (var t in timers) + { + var timer = t.Value; + timer.RemainingTicks--; + if (timer.RemainingTicks <= 0) + { + if (timer.Task == null) + { + _game.LuaRuntime.QueueEvent("timer", lk => + { + lk.PushInteger(t.Key); + + return 1; + }); + } + else + { + timer.Task.Fulfill(lk => + { + lk.PushInteger(t.Key); + }); + } + + timers.TryRemove(t.Key, out _); + } + } + } } public void LuaInit(Lua state) { _timerId = 0; - foreach (var pair in timers) - { - pair.Value.Stop(); - pair.Value.Dispose(); - } - timers.Clear(); state.RequireF("timer", Open, false); @@ -71,36 +106,23 @@ class Timer : IComponent private int Open(IntPtr state) { var l = Lua.FromIntPtr(state); - l.NewLib(TimerLib); + l.NewLib(Library); return 1; } + + private static int L_StartTimer(IntPtr state) { var L = Lua.FromIntPtr(state); var delay = L.CheckNumber(1); - L.ArgumentCheck(delay > 0, 1, "delay must be greater than 0"); var timerId = _timerId++; - var timer = new System.Timers.Timer + + timers[timerId] = new Timer { - AutoReset = false, - Enabled = true, - Interval = delay, - }; - - timers[timerId] = timer; - - timer.Elapsed += (o, e) => - { - _game.LuaRuntime.QueueEvent("timer", lk => - { - lk.PushInteger(timerId); - - return 1; - }); - timers.TryRemove(timerId, out _); + RemainingTicks = (int)(delay * Capy64.Instance.TickRate) }; L.PushInteger(timerId); @@ -112,27 +134,15 @@ class Timer : IComponent var L = Lua.FromIntPtr(state); var delay = L.CheckNumber(1); - L.ArgumentCheck(delay > 0, 1, "delay must be greater than 0"); var task = TaskMeta.Push(L, "timer"); var timerId = _timerId++; - var timer = new System.Timers.Timer - { - AutoReset = false, - Enabled = true, - Interval = delay, - }; - timers[timerId] = timer; - - timer.Elapsed += (o, e) => + timers[timerId] = new Timer { - task.Fulfill(lk => - { - lk.PushInteger(timerId); - }); - timers.TryRemove(timerId, out _); + RemainingTicks = (int)(delay * Capy64.Instance.TickRate), + Task = task, }; return 1; diff --git a/Capy64/Runtime/Objects/Task.cs b/Capy64/Runtime/Objects/Task.cs index 745b17a..9134581 100644 --- a/Capy64/Runtime/Objects/Task.cs +++ b/Capy64/Runtime/Objects/Task.cs @@ -255,7 +255,7 @@ public class TaskMeta : IComponent private static void WaitForTask(Lua L) { - L.PushCFunction(Libraries.Event.L_Pull); + L.PushCFunction(Libraries.EventLib.L_Pull); L.PushString("task_finish"); L.CallK(1, 4, 0, LK_Await); } diff --git a/Capy64/Runtime/Objects/WebSocketClient.cs b/Capy64/Runtime/Objects/WebSocketClient.cs index c3e7e47..55379c0 100644 --- a/Capy64/Runtime/Objects/WebSocketClient.cs +++ b/Capy64/Runtime/Objects/WebSocketClient.cs @@ -152,7 +152,7 @@ public class WebSocketClient : IComponent }); }); - HTTP.WebSocketConnections.Remove(client); + HTTPLib.WebSocketConnections.Remove(client); return 0; } diff --git a/Capy64/Runtime/PanicScreen.cs b/Capy64/Runtime/PanicScreen.cs index ee4dcfd..2f1e513 100644 --- a/Capy64/Runtime/PanicScreen.cs +++ b/Capy64/Runtime/PanicScreen.cs @@ -25,29 +25,29 @@ public class PanicScreen public static void Render(string error, string details = null) { - Term.ForegroundColor = ForegroundColor; - Term.BackgroundColor = BackgroundColor; - Term.SetCursorBlink(false); - Term.SetSize(57, 23); - Term.Clear(); + TermLib.ForegroundColor = ForegroundColor; + TermLib.BackgroundColor = BackgroundColor; + TermLib.SetCursorBlink(false); + TermLib.SetSize(57, 23); + TermLib.Clear(); var title = " Capy64 "; - var halfX = (Term.Width / 2) + 1; - Term.SetCursorPosition(halfX - (title.Length / 2), 2); - Term.ForegroundColor = BackgroundColor; - Term.BackgroundColor = ForegroundColor; - Term.Write(title); + var halfX = (TermLib.Width / 2) + 1; + TermLib.SetCursorPosition(halfX - (title.Length / 2), 2); + TermLib.ForegroundColor = BackgroundColor; + TermLib.BackgroundColor = ForegroundColor; + TermLib.Write(title); - Term.ForegroundColor = ForegroundColor; - Term.BackgroundColor = BackgroundColor; - Term.SetCursorPosition(1, 4); + TermLib.ForegroundColor = ForegroundColor; + TermLib.BackgroundColor = BackgroundColor; + TermLib.SetCursorPosition(1, 4); Print(error + '\n'); if (details is not null) { Print(details); } - Term.SetCursorPosition(1, 23); + TermLib.SetCursorPosition(1, 23); Print("Hold CTRL + ALT + INSERT to reboot."); } @@ -55,12 +55,12 @@ public class PanicScreen { foreach (var ch in txt) { - Term.Write(ch.ToString()); - if (Term.CursorPosition.X >= Term.Width || ch == '\n') + TermLib.Write(ch.ToString()); + if (TermLib.CursorPosition.X >= TermLib.Width || ch == '\n') { - Term.SetCursorPosition(1, (int)Term.CursorPosition.Y + 1); + TermLib.SetCursorPosition(1, (int)TermLib.CursorPosition.Y + 1); } } - Term.SetCursorPosition(1, (int)Term.CursorPosition.Y + 1); + TermLib.SetCursorPosition(1, (int)TermLib.CursorPosition.Y + 1); } } diff --git a/Capy64/Runtime/RuntimeManager.cs b/Capy64/Runtime/RuntimeManager.cs index 9ef93fb..16ec597 100644 --- a/Capy64/Runtime/RuntimeManager.cs +++ b/Capy64/Runtime/RuntimeManager.cs @@ -145,12 +145,12 @@ internal class RuntimeManager : IComponent emitter.Register(); - if (!File.Exists(Path.Combine(FileSystem.DataPath, "init.lua"))) + if (!File.Exists(Path.Combine(FileSystemLib.DataPath, "init.lua"))) { throw new LuaException("Operating System not found\nMissing init.lua"); } - var initContent = File.ReadAllText(Path.Combine(FileSystem.DataPath, "init.lua")); + var initContent = File.ReadAllText(Path.Combine(FileSystemLib.DataPath, "init.lua")); var status = luaState.Thread.LoadString(initContent, "=init.lua"); if (status != LuaStatus.OK) { @@ -180,14 +180,14 @@ internal class RuntimeManager : IComponent var installedFilePath = Path.Combine(Capy64.AppDataPath, ".installed"); if (!File.Exists(installedFilePath) || force) { - FileSystem.CopyDirectory("Assets/Lua/CapyOS", FileSystem.DataPath, true, true); + FileSystemLib.CopyDirectory("Assets/Lua/CapyOS", FileSystemLib.DataPath, true, true); File.Create(installedFilePath).Dispose(); } } private static int L_OpenDataFolder(IntPtr state) { - var path = FileSystem.DataPath; + var path = FileSystemLib.DataPath; switch (Environment.OSVersion.Platform) { case PlatformID.Win32NT: diff --git a/Capy64/Runtime/Sandbox.cs b/Capy64/Runtime/Sandbox.cs index 87f2db1..f021e6f 100644 --- a/Capy64/Runtime/Sandbox.cs +++ b/Capy64/Runtime/Sandbox.cs @@ -192,7 +192,7 @@ internal class Sandbox var errorMessage = new StringBuilder(); foreach (var possiblePath in possiblePaths) { - var path = FileSystem.Resolve(possiblePath); + var path = FileSystemLib.Resolve(possiblePath); var info = new FileInfo(path); if (!info.Exists) { @@ -229,7 +229,7 @@ internal class Sandbox bool hasMode = !L.IsNone(2); bool hasEnv = !L.IsNone(3); - var path = FileSystem.Resolve(filename); + var path = FileSystemLib.Resolve(filename); var fileInfo = new FileInfo(path); if (!fileInfo.Exists)