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 colors = require("colors")
|
||||
local fs = require("fs")
|
||||
local machine = require("machine")
|
||||
|
||||
local exit = false
|
||||
local shell = {}
|
||||
|
@ -10,9 +11,13 @@ shell.homePath = "/home"
|
|||
|
||||
local currentDir = shell.homePath
|
||||
|
||||
local function buildEnvironment()
|
||||
local function buildEnvironment(path, args)
|
||||
local arg = { table.unpack(args, 2) }
|
||||
arg[0] = path
|
||||
|
||||
return setmetatable({
|
||||
shell = shell,
|
||||
arg = arg
|
||||
}, { __index = _G })
|
||||
end
|
||||
|
||||
|
@ -76,7 +81,7 @@ function shell.run(...)
|
|||
return false
|
||||
end
|
||||
|
||||
local env = buildEnvironment()
|
||||
local env = buildEnvironment(command, args)
|
||||
|
||||
local func, err = loadfile(path, "t", env)
|
||||
|
||||
|
@ -105,6 +110,8 @@ end
|
|||
local history = {}
|
||||
local lastExecSuccess = true
|
||||
while not exit do
|
||||
machine.setRPC(os.version(), "On shell")
|
||||
|
||||
term.setBackground(colors.black)
|
||||
term.setForeground(colors.white)
|
||||
io.write(":")
|
||||
|
@ -130,6 +137,7 @@ while not exit do
|
|||
end
|
||||
|
||||
if line:match("%S") then
|
||||
machine.setRPC(os.version(), "Running: " .. line)
|
||||
lastExecSuccess = shell.run(line)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local version = "0.0.2"
|
||||
|
||||
print("Starting CapyOS")
|
||||
|
||||
local term = require("term")
|
||||
|
@ -20,7 +22,7 @@ local function showError(err)
|
|||
end
|
||||
|
||||
function os.version()
|
||||
return "CapyOS 0.0.2"
|
||||
return "CapyOS " .. version
|
||||
end
|
||||
|
||||
term.setSize(51, 19)
|
||||
|
@ -30,18 +32,16 @@ term.setPos(1, 1)
|
|||
term.write(_HOST)
|
||||
|
||||
local files = fs.list("/boot/autorun")
|
||||
for k, v in ipairs(files) do
|
||||
local func, err = loadfile("/boot/autorun/" .. v)
|
||||
for i = 1, #files do
|
||||
local func, err = loadfile("/boot/autorun/" .. files[i])
|
||||
if not func then
|
||||
showError(err)
|
||||
break
|
||||
end
|
||||
|
||||
local ok, err = pcall(func)
|
||||
|
||||
if not ok then
|
||||
showError(debug.traceback(err))
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue