formating better for spm packages
This commit is contained in:
18
Src/Hyperion-core/data/lib/colors
Normal file
18
Src/Hyperion-core/data/lib/colors
Normal file
@@ -0,0 +1,18 @@
|
||||
--:Minify:--
|
||||
return {
|
||||
white=0xFFFFFF,
|
||||
red=0xFF0000,
|
||||
green=0x00FF00,
|
||||
blue=0x0000FF,
|
||||
cyan=0x00FFFF,
|
||||
yellow=0xFFFF00,
|
||||
purple=0xFF00FF,
|
||||
black=0x000000,
|
||||
gray=0x888888,
|
||||
lightgrey=0xBBBBBB,
|
||||
darkgrey=0x444444,
|
||||
orange=0xFF8800,
|
||||
mint=0x00FF88,
|
||||
brown=0xa52a2a,
|
||||
chocolate=0xd2691e
|
||||
}
|
||||
143
Src/Hyperion-core/data/lib/fs
Normal file
143
Src/Hyperion-core/data/lib/fs
Normal file
@@ -0,0 +1,143 @@
|
||||
--:Minify:--
|
||||
local fs={}
|
||||
|
||||
-- "open" : open
|
||||
-- "read" : read
|
||||
-- "write" : write
|
||||
-- "close" : close
|
||||
|
||||
function fs.open(path, mode)
|
||||
local fd=syscall.open(path,mode)
|
||||
local ret={
|
||||
close=function()
|
||||
-- close file
|
||||
return syscall.close(fd)
|
||||
end,
|
||||
flush=function()
|
||||
-- close and reopen file to flush buffers
|
||||
syscall.fsync(fd)
|
||||
end
|
||||
}
|
||||
if mode=="r" then
|
||||
ret.read=function(count)
|
||||
local data = syscall.read(fd,count)
|
||||
return data
|
||||
end
|
||||
ret.readAll=function(chunkSize)
|
||||
local chunks={} -- to store read chunks
|
||||
while true do
|
||||
local chunk=syscall.read(fd,chunkSize or 65536)
|
||||
if chunk==nil or #chunk==0 then break end
|
||||
table.insert(chunks,chunk)
|
||||
end
|
||||
return table.concat(chunks)
|
||||
end
|
||||
ret.readLine = function(chunkSize)
|
||||
local buffer = {} -- stores leftover data
|
||||
local buffer_str = "" -- concatenated buffer
|
||||
local chunk_size = chunkSize or 65536 -- adjust chunk size for performance
|
||||
local eof = false
|
||||
|
||||
while true do
|
||||
-- Try to find a newline in the current buffer
|
||||
local line_end = buffer_str:find("\n")
|
||||
if line_end then
|
||||
local line = buffer_str:sub(1, line_end - 1)
|
||||
buffer_str = buffer_str:sub(line_end + 1)
|
||||
return line
|
||||
end
|
||||
|
||||
-- If EOF was reached previously and buffer is empty, stop
|
||||
if eof then
|
||||
if buffer_str ~= "" then
|
||||
local last_line = buffer_str
|
||||
buffer_str = ""
|
||||
return last_line
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
-- Read the next chunk
|
||||
local chunk = syscall.read(fd, chunk_size)
|
||||
if not chunk or chunk == "" then
|
||||
eof = true
|
||||
else
|
||||
buffer_str = buffer_str .. chunk
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif mode=="w" then
|
||||
ret.write=function(data)
|
||||
-- write data to file
|
||||
return syscall.write(fd,data)
|
||||
end
|
||||
elseif mode=="a" then
|
||||
ret.write=function(data)
|
||||
-- append data to file
|
||||
return syscall.write(fd,data)
|
||||
end
|
||||
else
|
||||
error("Invalid mode '"..mode.."'",2)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
function fs.readAllText(path)
|
||||
local file=fs.open(path,"r")
|
||||
if not file then return false end
|
||||
local content=file.readAll()
|
||||
file.close()
|
||||
return content
|
||||
end
|
||||
|
||||
function fs.writeAllText(path, data)
|
||||
local file=fs.open(path,"w")
|
||||
file.write(data)
|
||||
file.close()
|
||||
end
|
||||
|
||||
function fs.appendAllText(path, data)
|
||||
local file=fs.open(path,"a")
|
||||
if not file then return false end
|
||||
file.write(data)
|
||||
file.close()
|
||||
end
|
||||
|
||||
function fs.mkdir(path)
|
||||
return syscall.mkdir(path)
|
||||
end
|
||||
|
||||
function fs.remove(path)
|
||||
return syscall.remove(path)
|
||||
end
|
||||
|
||||
function fs.list(path)
|
||||
return syscall.listdir(path)
|
||||
end
|
||||
|
||||
function fs.type(path)
|
||||
return syscall.type(path)
|
||||
end
|
||||
|
||||
function fs.stat(path)
|
||||
return syscall.stat(path)
|
||||
end
|
||||
|
||||
function fs.exists(path)
|
||||
return syscall.exists(path)
|
||||
end
|
||||
|
||||
function fs.getcwd()
|
||||
return syscall.getcwd()
|
||||
end
|
||||
|
||||
function fs.chdir(path)
|
||||
return syscall.chdir(path)
|
||||
end
|
||||
|
||||
function fs.isDir(path)
|
||||
return syscall.type(path) == "directory"
|
||||
end
|
||||
|
||||
return fs
|
||||
0
Src/Hyperion-core/data/lib/http
Normal file
0
Src/Hyperion-core/data/lib/http
Normal file
6
Src/Hyperion-core/data/lib/io
Normal file
6
Src/Hyperion-core/data/lib/io
Normal file
@@ -0,0 +1,6 @@
|
||||
local io = {}
|
||||
local fs = require("fs")
|
||||
|
||||
function io.open(path, mode)
|
||||
return fs.open(path, mode)
|
||||
end
|
||||
Reference in New Issue
Block a user