From a699f41c228b573ff980927d6807ea2b538c0be0 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 26 Oct 2025 01:12:36 +0530 Subject: Move marks into fnl script --- scripts/fnl/lib.fnl | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 scripts/fnl/lib.fnl (limited to 'scripts/fnl') diff --git a/scripts/fnl/lib.fnl b/scripts/fnl/lib.fnl new file mode 100644 index 0000000..100b447 --- /dev/null +++ b/scripts/fnl/lib.fnl @@ -0,0 +1,32 @@ +(local M {}) + +(lambda M.contains? [tbl elem] + (not= nil (table.index-of tbl elem))) + +(lambda M.index-of [tbl elem] + (each [idx value (pairs tbl)] + (when (= value elem) (lua "return idx"))) + nil) + +(lambda M.exec [cmd args] + (var argstr "") + (each [_ arg (ipairs args)] + (set argstr (.. argstr " \"" (string.gsub arg "\"" "\\\"") "\""))) + (local code (os.execute (.. cmd argstr)))) + +(lambda M.read-lines [filepath] + (local file (io.open filepath :r)) + (if file + (do + (local lines []) + (each [line (file:lines)] (table.insert lines line)) + (file:close) + lines) + [])) + +(lambda M.write-lines [filepath lines] + (local file (io.open filepath :w)) + (file:write (table.concat lines "\n")) + (file:close)) + +M -- cgit v1.3.1