diff options
author | Aylur <[email protected]> | 2024-10-15 13:25:45 +0000 |
---|---|---|
committer | Aylur <[email protected]> | 2024-10-15 13:29:19 +0000 |
commit | bafd48d3df9b43a1d49ec015eff30619d595468b (patch) | |
tree | d5c3788835ca7e50d68cd023026e7738f39f6f71 /lang/lua/astal/file.lua | |
parent | fe11c037bad45697451b7264ff93fa37f1fac78f (diff) |
update lua and gjs layout
installing the gjs package through meson or npm now results in the same
exposed structure
lua: fix rockspec
docs: aur package
Diffstat (limited to 'lang/lua/astal/file.lua')
-rw-r--r-- | lang/lua/astal/file.lua | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lang/lua/astal/file.lua b/lang/lua/astal/file.lua new file mode 100644 index 0000000..e3be783 --- /dev/null +++ b/lang/lua/astal/file.lua @@ -0,0 +1,45 @@ +local lgi = require("lgi") +local Astal = lgi.require("AstalIO", "0.1") +local GObject = lgi.require("GObject", "2.0") + +local M = {} + +---@param path string +---@return string +function M.read_file(path) + return Astal.read_file(path) +end + +---@param path string +---@param callback fun(content: string, err: string): nil +function M.read_file_async(path, callback) + Astal.read_file_async(path, function(_, res) + local content, err = Astal.read_file_finish(res) + callback(content, err) + end) +end + +---@param path string +---@param content string +function M.write_file(path, content) + Astal.write_file(path, content) +end + +---@param path string +---@param content string +---@param callback? fun(err: string): nil +function M.write_file_async(path, content, callback) + Astal.write_file_async(path, content, function(_, res) + if type(callback) == "function" then + callback(Astal.write_file_finish(res)) + end + end) +end + +---@param path string +---@param callback fun(file: string, event: integer): nil +function M.monitor_file(path, callback) + return Astal.monitor_file(path, GObject.Closure(callback)) +end + +return M |