diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2020-11-15 13:37:32 -0500 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2020-11-15 13:37:32 -0500 |
| commit | 621e13d8bed7215a076e505eba998c7a0ec38519 (patch) | |
| tree | 46a8be63ce5fe3c5a38bfbdce6ec269382f39c01 /System/apis/flib.lua | |
| parent | bed8f884aa3acbca1bc5a0772c73d17c373be77e (diff) | |
| download | bits-UI-621e13d8bed7215a076e505eba998c7a0ec38519.tar.gz bits-UI-621e13d8bed7215a076e505eba998c7a0ec38519.tar.bz2 bits-UI-621e13d8bed7215a076e505eba998c7a0ec38519.zip | |
New program system; Capitalized folders
Diffstat (limited to 'System/apis/flib.lua')
| -rw-r--r-- | System/apis/flib.lua | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/System/apis/flib.lua b/System/apis/flib.lua new file mode 100644 index 0000000..c3b7150 --- /dev/null +++ b/System/apis/flib.lua @@ -0,0 +1,124 @@ +--[[ + fLib by NDFJay +]]-- +function exists(path) + local file = assert(io.open(path, "r")) + if file ~= nil then + file:close() + return true + end + + return false +end + +function getTable(path) + if exists(path) then + local file = io.open(path, "r") + local lines = {} + local i = 1 + local line = file:read("*l") + while line ~= nil do + lines[i] = line + line = file:read("*l") + i = i + 1 + end + file:close() + return lines + end + return {} +end + +function getLine(path, n) + if exists(path) then + local lines = getTable(path) + return lines[n] + end + return "" +end + +function getText(path) + if exists(path) then + local file = assert(io.open(path, "r")) + return file:read("*a") + end + return "" +end + +function fappend(path, text) + local file = assert(io.open(path, "a")) + file:write(text.."\n") + file:close() +end + +function fwrite(path, text) + local file = assert(io.open(path, "w")) + file:write(text) + file:close() +end + +function fwriteAtStart(path, text) + local _text = getText(path) + fwrite(path, text.."\n".._text) +end + +function fwriteFromTable(path, t) + local text = "" + for _, line in pairs(t) do + text = text..line.."\n" + end + fwrite(path, text) +end + +function fappendFromTable(path, t) + local text = "" + for _, line in pairs(t) do + text = text..line.."\n" + end + fappend(path, text) +end + +function fwriteAtStartFromTable(path, t) + local text = "" + for _, line in pairs(t) do + text = text..line.."\n" + end + fwriteAtStart(path, text) +end + +function replaceLine(path, n, text) + local lines = getTable(path) + lines[n] = text + fwriteFromTable(path, lines) +end + +function getName(path) + if exists(path) then + local lastSlashPos = 1 + for i = 1, path:len() do + if path:sub(i, i) == "/" then + lastSlashPos = i + end + end + + return path:sub(lastSlashPos + 1) + end + return "" +end + +function getPath(path) + if exists(path) then + local lastSlashPos = 1 + for i = 1, path:len() do + if path:sub(i, i) == "/" then + lastSlashPos = i + end + end + + return path:sub(1, lastSlashPos) + end + return "" +end + +function fremove(path) + os.remove(path) +end
\ No newline at end of file |
