mirror of
https://github.com/CCLeonOS/LeonOS.git
synced 2026-03-03 15:17:01 +00:00
feat: 初始提交 LeonOS 实现
添加 LeonOS 的基本实现,包括: - 核心 API 模块(colors, disk, gps, keys, multishell, parallel, rednet, redstone, settings, vector) - 命令行程序(about, alias, bg, clear, copy, delete, edit, fg, help, list, lua, mkdir, move, paint, peripherals, programs, reboot, set, shutdown, threads) - 系统启动脚本和包管理 - 文档(README.md, LICENSE) - 开发工具(devbin)和更新程序 实现功能: - 完整的线程管理系统 - 兼容 ComputerCraft 的 API 设计 - 改进的 shell 和命令补全系统 - 多标签终端支持 - 设置管理系统
This commit is contained in:
89
data/computercraft/lua/rom/programs/devbin.lua
Normal file
89
data/computercraft/lua/rom/programs/devbin.lua
Normal file
@@ -0,0 +1,89 @@
|
||||
-- devbin (like pastebin)
|
||||
|
||||
if not package.loaded.http then
|
||||
error("HTTP is not enabled in the ComputerCraft configuration", 0)
|
||||
end
|
||||
|
||||
local http = require("http")
|
||||
local json = require("rc.json")
|
||||
local shell = require("shell")
|
||||
|
||||
local args = {...}
|
||||
|
||||
if #args < (args[1] == "get" and 3 or 2) then
|
||||
io.stderr:write([[
|
||||
Usage:
|
||||
devbin put <filename>
|
||||
devbin get <code> <filename>
|
||||
devbin run <code> [argument ...]
|
||||
]])
|
||||
return
|
||||
end
|
||||
|
||||
local paste = "https://devbin.dev/api/v3/paste"
|
||||
local key = "aNVXl8vxYGWcZGvMnuJTzLXH53mGWOuQtBXU025g8YDAsZDu"
|
||||
|
||||
local function get(code)
|
||||
local handle, err, rerr = http.get("https://devbin.dev/raw/"..code)
|
||||
if not handle then
|
||||
if rerr then rerr.close() end
|
||||
error(err, 0)
|
||||
end
|
||||
|
||||
local data = handle.readAll()
|
||||
handle.close()
|
||||
|
||||
return data
|
||||
end
|
||||
|
||||
if args[1] == "put" then
|
||||
local handle, err = io.open(shell.resolve(args[2]), "r")
|
||||
if not handle then error(err, 0) end
|
||||
local data = handle:read("a")
|
||||
handle:close()
|
||||
|
||||
if (not data) or #data == 0 then
|
||||
error("cannot 'put' empty file", 0)
|
||||
end
|
||||
|
||||
local request = json.encode({
|
||||
title = args[2],
|
||||
syntaxName = "lua",
|
||||
exposure = 0,
|
||||
content = data,
|
||||
asGuest = true
|
||||
})
|
||||
|
||||
local response, rerr, rerr2 = http.post(paste, request,
|
||||
{["Content-Type"]="application/json", Authorization = key}, true)
|
||||
if not response then
|
||||
local _rerr2 = rerr2.readAll()
|
||||
if rerr2 then rerr2.close() end
|
||||
print(_rerr2)
|
||||
error(rerr, 0)
|
||||
--("%q: %q"):format(rerr, (rerr2 and rerr2.readAll()) or ""), 0)
|
||||
end
|
||||
|
||||
local rdata = response.readAll()
|
||||
|
||||
local code, message = response.getResponseCode()
|
||||
response.close()
|
||||
if code ~= 201 then
|
||||
error(code .. " " .. (message or ""), 0)
|
||||
end
|
||||
|
||||
local decoded = json.decode(rdata)
|
||||
|
||||
print(decoded.code)
|
||||
|
||||
elseif args[1] == "get" then
|
||||
local data = get(args[2])
|
||||
local handle, err = io.open(shell.resolve(args[3]), "w")
|
||||
if not handle then error(err, 0) end
|
||||
handle:write(data)
|
||||
handle:close()
|
||||
|
||||
elseif args[1] == "run" then
|
||||
local data = get(args[2])
|
||||
assert(load(data, "=<devbin-run>", "t", _G))()
|
||||
end
|
||||
Reference in New Issue
Block a user