From efe510d0dabaf964c7a1ba70cbdc25aa3db06de8 Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Wed, 10 May 2023 12:52:19 +0200 Subject: [PATCH] Added firmware file to add default Lua function --- .../autorun/01_event.lua => firmware.lua} | 21 ++++++++++++++++++- Capy64/Runtime/RuntimeManager.cs | 14 +++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) rename Capy64/Assets/Lua/{CapyOS/sys/boot/autorun/01_event.lua => firmware.lua} (52%) diff --git a/Capy64/Assets/Lua/CapyOS/sys/boot/autorun/01_event.lua b/Capy64/Assets/Lua/firmware.lua similarity index 52% rename from Capy64/Assets/Lua/CapyOS/sys/boot/autorun/01_event.lua rename to Capy64/Assets/Lua/firmware.lua index ba63155..7c3da51 100644 --- a/Capy64/Assets/Lua/CapyOS/sys/boot/autorun/01_event.lua +++ b/Capy64/Assets/Lua/firmware.lua @@ -1,5 +1,22 @@ -local event = require("event") +-- This file is part of Capy64 - https://github.com/Capy64/Capy64 +-- Copyright 2023 Alessandro "AlexDevs" Proto +-- +-- Licensed under the Apache License, Version 2.0 (the "License"). +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +local event = require("event") +local coroutine = coroutine + +-- Declare event functions function event.pull(...) local ev = table.pack(coroutine.yield(...)) if ev[1] == "interrupt" then @@ -12,6 +29,8 @@ function event.pullRaw(...) return coroutine.yield(...) end +-- Set task awaiter + local function awaiter(task) local status = task:getStatus() local uuid = task:getID() diff --git a/Capy64/Runtime/RuntimeManager.cs b/Capy64/Runtime/RuntimeManager.cs index 16ec597..a8327e9 100644 --- a/Capy64/Runtime/RuntimeManager.cs +++ b/Capy64/Runtime/RuntimeManager.cs @@ -113,6 +113,8 @@ internal class RuntimeManager : IComponent emitter.Register(); + LoadFirmware(); + luaState.Thread.PushCFunction(L_OpenDataFolder); luaState.Thread.SetGlobal("openDataFolder"); @@ -145,6 +147,8 @@ internal class RuntimeManager : IComponent emitter.Register(); + LoadFirmware(); + if (!File.Exists(Path.Combine(FileSystemLib.DataPath, "init.lua"))) { throw new LuaException("Operating System not found\nMissing init.lua"); @@ -158,6 +162,16 @@ internal class RuntimeManager : IComponent } } + private void LoadFirmware() + { + var firmwareContent = File.ReadAllText("Assets/Lua/firmware.lua"); + var errored = luaState.Thread.DoString(firmwareContent); + if(errored) + { + throw new LuaException(luaState.Thread.ToString(-1)); + } + } + public static void Reset() { close = true;