Added firmware file to add default Lua function

This commit is contained in:
Alessandro Proto 2023-05-10 12:52:19 +02:00
parent 589042ca38
commit efe510d0da
2 changed files with 34 additions and 1 deletions

View file

@ -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(...) function event.pull(...)
local ev = table.pack(coroutine.yield(...)) local ev = table.pack(coroutine.yield(...))
if ev[1] == "interrupt" then if ev[1] == "interrupt" then
@ -12,6 +29,8 @@ function event.pullRaw(...)
return coroutine.yield(...) return coroutine.yield(...)
end end
-- Set task awaiter
local function awaiter(task) local function awaiter(task)
local status = task:getStatus() local status = task:getStatus()
local uuid = task:getID() local uuid = task:getID()

View file

@ -113,6 +113,8 @@ internal class RuntimeManager : IComponent
emitter.Register(); emitter.Register();
LoadFirmware();
luaState.Thread.PushCFunction(L_OpenDataFolder); luaState.Thread.PushCFunction(L_OpenDataFolder);
luaState.Thread.SetGlobal("openDataFolder"); luaState.Thread.SetGlobal("openDataFolder");
@ -145,6 +147,8 @@ internal class RuntimeManager : IComponent
emitter.Register(); emitter.Register();
LoadFirmware();
if (!File.Exists(Path.Combine(FileSystemLib.DataPath, "init.lua"))) if (!File.Exists(Path.Combine(FileSystemLib.DataPath, "init.lua")))
{ {
throw new LuaException("Operating System not found\nMissing 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() public static void Reset()
{ {
close = true; close = true;