mirror of
https://github.com/Ale32bit/Capy64.git
synced 2025-01-18 18:46:43 +00:00
Add machine.setRPC to shell.lua
This commit is contained in:
parent
9b5d463f4a
commit
68f4f17f35
2 changed files with 15 additions and 7 deletions
|
@ -1,6 +1,7 @@
|
||||||
local term = require("term")
|
local term = require("term")
|
||||||
local colors = require("colors")
|
local colors = require("colors")
|
||||||
local fs = require("fs")
|
local fs = require("fs")
|
||||||
|
local machine = require("machine")
|
||||||
|
|
||||||
local exit = false
|
local exit = false
|
||||||
local shell = {}
|
local shell = {}
|
||||||
|
@ -10,9 +11,13 @@ shell.homePath = "/home"
|
||||||
|
|
||||||
local currentDir = shell.homePath
|
local currentDir = shell.homePath
|
||||||
|
|
||||||
local function buildEnvironment()
|
local function buildEnvironment(path, args)
|
||||||
|
local arg = { table.unpack(args, 2) }
|
||||||
|
arg[0] = path
|
||||||
|
|
||||||
return setmetatable({
|
return setmetatable({
|
||||||
shell = shell,
|
shell = shell,
|
||||||
|
arg = arg
|
||||||
}, { __index = _G })
|
}, { __index = _G })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -76,7 +81,7 @@ function shell.run(...)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local env = buildEnvironment()
|
local env = buildEnvironment(command, args)
|
||||||
|
|
||||||
local func, err = loadfile(path, "t", env)
|
local func, err = loadfile(path, "t", env)
|
||||||
|
|
||||||
|
@ -105,6 +110,8 @@ end
|
||||||
local history = {}
|
local history = {}
|
||||||
local lastExecSuccess = true
|
local lastExecSuccess = true
|
||||||
while not exit do
|
while not exit do
|
||||||
|
machine.setRPC(os.version(), "On shell")
|
||||||
|
|
||||||
term.setBackground(colors.black)
|
term.setBackground(colors.black)
|
||||||
term.setForeground(colors.white)
|
term.setForeground(colors.white)
|
||||||
io.write(":")
|
io.write(":")
|
||||||
|
@ -130,6 +137,7 @@ while not exit do
|
||||||
end
|
end
|
||||||
|
|
||||||
if line:match("%S") then
|
if line:match("%S") then
|
||||||
|
machine.setRPC(os.version(), "Running: " .. line)
|
||||||
lastExecSuccess = shell.run(line)
|
lastExecSuccess = shell.run(line)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
local version = "0.0.2"
|
||||||
|
|
||||||
print("Starting CapyOS")
|
print("Starting CapyOS")
|
||||||
|
|
||||||
local term = require("term")
|
local term = require("term")
|
||||||
|
@ -20,7 +22,7 @@ local function showError(err)
|
||||||
end
|
end
|
||||||
|
|
||||||
function os.version()
|
function os.version()
|
||||||
return "CapyOS 0.0.2"
|
return "CapyOS " .. version
|
||||||
end
|
end
|
||||||
|
|
||||||
term.setSize(51, 19)
|
term.setSize(51, 19)
|
||||||
|
@ -30,18 +32,16 @@ term.setPos(1, 1)
|
||||||
term.write(_HOST)
|
term.write(_HOST)
|
||||||
|
|
||||||
local files = fs.list("/boot/autorun")
|
local files = fs.list("/boot/autorun")
|
||||||
for k, v in ipairs(files) do
|
for i = 1, #files do
|
||||||
local func, err = loadfile("/boot/autorun/" .. v)
|
local func, err = loadfile("/boot/autorun/" .. files[i])
|
||||||
if not func then
|
if not func then
|
||||||
showError(err)
|
showError(err)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
local ok, err = pcall(func)
|
local ok, err = pcall(func)
|
||||||
|
|
||||||
if not ok then
|
if not ok then
|
||||||
showError(debug.traceback(err))
|
showError(debug.traceback(err))
|
||||||
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue