Update of lua-dog to 1.1.0-1
This commit is contained in:
parent
86ed0ecb3e
commit
efa6cd3b69
|
@ -6260,10 +6260,41 @@ do
|
||||||
end
|
end
|
||||||
local fnl = mod
|
local fnl = mod
|
||||||
|
|
||||||
|
-- Variable for storing all the functions
|
||||||
|
local dog = {}
|
||||||
|
|
||||||
|
-- Functions are divided according to the standard library to extend
|
||||||
|
dog.io = {}
|
||||||
|
dog.os = {}
|
||||||
|
dog.string = {}
|
||||||
|
dog.utf8 = {}
|
||||||
|
|
||||||
|
-- Imports dog functions to _G
|
||||||
|
-- Allows using the other functions without a prefix, i.e.:
|
||||||
|
-- dog.os.uname() => os.uname()
|
||||||
|
function dog.import()
|
||||||
|
local msg = "[WARNING] [DOG] "
|
||||||
|
msg = msg .. "Ignoring import: '@1' already exists; use '@2' instead"
|
||||||
|
for libkey, dogfns in pairs(dog) do
|
||||||
|
local lib = _G[libkey]
|
||||||
|
if type(dogfns) == "table" then
|
||||||
|
for fnkey, fn in pairs(dogfns) do
|
||||||
|
if not(lib[fnkey]) then
|
||||||
|
lib[fnkey] = fn
|
||||||
|
else
|
||||||
|
local name = libkey .. "." .. fnkey .. "()"
|
||||||
|
msg = msg:gsub("@1", name):gsub("@2", "dog." .. name)
|
||||||
|
print(msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Tries popen
|
-- Tries popen
|
||||||
-- @param ... string: Chunks for popen
|
-- @param ... string: Chunks for popen
|
||||||
-- @return boolean, string: Status and output of popen
|
-- @return boolean, string: Status and output of popen
|
||||||
function io.try(...)
|
function dog.io.try(...)
|
||||||
local cmd = table.concat({...}, " ") .. " 2>&1"
|
local cmd = table.concat({...}, " ") .. " 2>&1"
|
||||||
local handle = io.popen(cmd)
|
local handle = io.popen(cmd)
|
||||||
local output = handle:read("*a")
|
local output = handle:read("*a")
|
||||||
|
@ -6274,13 +6305,13 @@ end
|
||||||
-- Gets OS short name
|
-- Gets OS short name
|
||||||
-- It is just intented to know if it is Linux, macOS or Windows.
|
-- It is just intented to know if it is Linux, macOS or Windows.
|
||||||
-- @return string: "linux" or "bsd" or "macos" or "windows"
|
-- @return string: "linux" or "bsd" or "macos" or "windows"
|
||||||
function os.uname()
|
function dog.os.uname()
|
||||||
local status, output = io.try("uname")
|
local status, output = dog.io.try("uname")
|
||||||
if status then
|
if status then
|
||||||
output = output:gsub(" .*", ""):lower()
|
output = output:gsub(" .*", ""):lower()
|
||||||
if output ~= "linux" and output:match("bsd") ~= nil then
|
if output ~= "linux" and output:match("bsd") ~= nil then
|
||||||
return "bsd"
|
return "bsd"
|
||||||
elseif out ~= "linux" then
|
elseif output ~= "linux" then
|
||||||
return "macos"
|
return "macos"
|
||||||
end
|
end
|
||||||
return "linux"
|
return "linux"
|
||||||
|
@ -6290,19 +6321,19 @@ end
|
||||||
|
|
||||||
-- Checks if OS is windows
|
-- Checks if OS is windows
|
||||||
-- @return boolean: Windows or not
|
-- @return boolean: Windows or not
|
||||||
function os.iswin()
|
function dog.os.iswin()
|
||||||
return os.uname() == "windows"
|
return dog.os.uname() == "windows"
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Checks if OS is Unix
|
-- Checks if OS is Unix
|
||||||
-- @return boolean: Unix or not
|
-- @return boolean: Unix or not
|
||||||
function os.isunix()
|
function dog.os.isunix()
|
||||||
return os.uname() ~= "windows"
|
return dog.os.uname() ~= "windows"
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Gets OS language
|
-- Gets OS language
|
||||||
-- @return string, string, string: Language, locale and encoding
|
-- @return string, string, string: Language, locale and encoding
|
||||||
function os.lang()
|
function dog.os.lang()
|
||||||
local lang = os.getenv("LANG")
|
local lang = os.getenv("LANG")
|
||||||
if lang ~= nil then
|
if lang ~= nil then
|
||||||
return lang:match("(%w%w)_?(%w?%w?)%.?(.*)")
|
return lang:match("(%w%w)_?(%w?%w?)%.?(.*)")
|
||||||
|
@ -6310,10 +6341,158 @@ function os.lang()
|
||||||
return "en", "US", "UTF-8"
|
return "en", "US", "UTF-8"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Checks if string is empty
|
||||||
|
-- @return boolean: Empty or not
|
||||||
|
function dog.string.isempty(str)
|
||||||
|
return str == ''
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Changes newlines so everything is in one line
|
||||||
|
-- @return string: String with formatted newlines as literal "\n"
|
||||||
|
function dog.string.linearize(str)
|
||||||
|
return str:gsub("\n", "\\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Normalizes string
|
||||||
|
-- @return string: Normalized string
|
||||||
|
function dog.string.normalize(str)
|
||||||
|
str = str:lower()
|
||||||
|
for newchar, chars in pairs(dog.utf8.table()) do
|
||||||
|
for _, oldchar in ipairs(chars) do
|
||||||
|
str = str:gsub(oldchar, newchar)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return str
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Adds indent
|
||||||
|
-- @param num number: Indent size, 2 by default
|
||||||
|
-- @param char string: Indent character, space by default
|
||||||
|
-- @return strin: Indented string
|
||||||
|
function dog.string.indent(str, num, char)
|
||||||
|
num = num or 2
|
||||||
|
char = char or " "
|
||||||
|
char = string.rep(char, num)
|
||||||
|
return char .. str:gsub("\n", "\n" .. char)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Splits the string
|
||||||
|
-- Note: only support splitting by one character.
|
||||||
|
-- Could be solved by slicing with find.
|
||||||
|
-- @param sep string: String separator, space by default
|
||||||
|
-- @return table: String matches
|
||||||
|
function dog.string.split(str, sep)
|
||||||
|
sep = sep or "%s+"
|
||||||
|
local parts = {}
|
||||||
|
for part in str:gmatch("([^" .. sep .. "]+)") do
|
||||||
|
table.insert(parts, part)
|
||||||
|
end
|
||||||
|
return parts
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Removes spaces at the beginning of the string
|
||||||
|
-- @return string: Left stripped string
|
||||||
|
function dog.string.lstrip(str)
|
||||||
|
return str:gsub("^%s+", "")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Removes spaces at the end of the string
|
||||||
|
-- @return string: Right stripped string
|
||||||
|
function dog.string.rstrip(str)
|
||||||
|
return str:gsub("%s+$", "")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Removes spaces at the beginning and at the end of the string
|
||||||
|
-- @return string: Stripped string
|
||||||
|
function dog.string.strip(str)
|
||||||
|
str = dog.string.lstrip(str)
|
||||||
|
return dog.string.rstrip(str)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Alias of strip
|
||||||
|
function dog.string.trim(str)
|
||||||
|
return dog.string.strip(str)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- The following are heavily influenced by Python pathlib
|
||||||
|
-- Check: https://docs.python.org/3/library/pathlib.html
|
||||||
|
|
||||||
|
-- Checks if string is a file or a directory
|
||||||
|
-- @return boolean: Exists or not
|
||||||
|
function dog.string.exists(str)
|
||||||
|
return os.rename(str, str) ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Checks if string is a file
|
||||||
|
-- @return boolean: File or not
|
||||||
|
function dog.string.isfile(str)
|
||||||
|
if dog.string.exists(str) then
|
||||||
|
return io.open(str, "a+") ~= nil
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Checks if string is a directory
|
||||||
|
-- @return boolean: Directory or not
|
||||||
|
function dog.string.isdir(str)
|
||||||
|
if dog.string.exists(str) then
|
||||||
|
return io.open(str, "a+") == nil
|
||||||
|
elseif str == "." or str == ".." then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Reads file content as string
|
||||||
|
-- @return string or nil: File as string or nil
|
||||||
|
function dog.string.readtext(str)
|
||||||
|
if dog.string.exists(str) then
|
||||||
|
return io.open(str):read("*a")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Read file content as lines
|
||||||
|
-- @return table: Table of file lines or nil
|
||||||
|
function dog.string.readlines(str)
|
||||||
|
local lines = {}
|
||||||
|
if dog.string.exists(str) then
|
||||||
|
for line in io.open(str):lines() do
|
||||||
|
table.insert(lines, line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return lines
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Gets file without suffix
|
||||||
|
-- @return string: File wihtout suffix
|
||||||
|
function dog.string.stem(str)
|
||||||
|
return str:gsub("%.%a+$", "")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Gets file extensions
|
||||||
|
-- @return table: List of file extensions
|
||||||
|
function dog.string.suffixes(str)
|
||||||
|
local suffixes = {}
|
||||||
|
for suffix in str:gmatch("%.%a+") do
|
||||||
|
table.insert(suffixes, suffix)
|
||||||
|
end
|
||||||
|
return suffixes
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Gets file final extension
|
||||||
|
-- @return string: Final file extension
|
||||||
|
function dog.string.suffix(str)
|
||||||
|
local suffixes = str:suffixes()
|
||||||
|
if suffixes[#suffixes] then
|
||||||
|
return suffixes[#suffixes]
|
||||||
|
end
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
|
||||||
-- Gets an equivalency table between ASCII and Unicode
|
-- Gets an equivalency table between ASCII and Unicode
|
||||||
-- Note: filled on demand.
|
-- Note: filled on demand.
|
||||||
-- @return table: ASCII-Unicode table equivalency
|
-- @return table: ASCII-Unicode table equivalency
|
||||||
function utf8.table()
|
function dog.utf8.table()
|
||||||
return {
|
return {
|
||||||
["a"] = {"á", "à", "ä"},
|
["a"] = {"á", "à", "ä"},
|
||||||
["e"] = {"é", "è", "ë"},
|
["e"] = {"é", "è", "ë"},
|
||||||
|
@ -6324,155 +6503,7 @@ function utf8.table()
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Checks if string is empty
|
-- Extends Pandoc Library
|
||||||
-- @return boolean: Empty or not
|
|
||||||
function string:isempty()
|
|
||||||
return self == ''
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Changes newlines so everything is in one line
|
|
||||||
-- @return string: String with formatted newlines as literal "\n"
|
|
||||||
function string:linearize()
|
|
||||||
return self:gsub("\n", "\\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Normalizes string
|
|
||||||
-- @return string: Normalized string
|
|
||||||
function string:normalize()
|
|
||||||
self = self:lower()
|
|
||||||
for newchar, chars in pairs(utf8.table()) do
|
|
||||||
for _, oldchar in ipairs(chars) do
|
|
||||||
self = self:gsub(oldchar, newchar)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Adds indent
|
|
||||||
-- @param num number: Indent size, 2 by default
|
|
||||||
-- @param char string: Indent character, space by default
|
|
||||||
-- @return strin: Indented string
|
|
||||||
function string:indent(num, char)
|
|
||||||
num = num or 2
|
|
||||||
char = char or " "
|
|
||||||
char = string.rep(char, num)
|
|
||||||
return char .. self:gsub("\n", "\n" .. char)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Splits the string
|
|
||||||
-- Note: only support splitting by one character.
|
|
||||||
-- Could be solved by slicing with find.
|
|
||||||
-- @param sep string: String separator, space by default
|
|
||||||
-- @return table: String matches
|
|
||||||
function string:split(sep)
|
|
||||||
sep = sep or "%s+"
|
|
||||||
local parts = {}
|
|
||||||
for part in self:gmatch("([^" .. sep .. "]+)") do
|
|
||||||
table.insert(parts, part)
|
|
||||||
end
|
|
||||||
return parts
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Removes spaces at the beginning of the string
|
|
||||||
-- @return string: Left stripped string
|
|
||||||
function string:lstrip()
|
|
||||||
return self:gsub("^%s+", "")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Removes spaces at the end of the string
|
|
||||||
-- @return string: Right stripped string
|
|
||||||
function string:rstrip()
|
|
||||||
return self:gsub("%s+$", "")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Removes spaces at the beginning and at the end of the string
|
|
||||||
-- @return string: Stripped string
|
|
||||||
function string:strip()
|
|
||||||
self = self:lstrip():rstrip()
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Alias of strip
|
|
||||||
function string:trim()
|
|
||||||
return self:strip()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- The following are heavily influenced by Python pathlib
|
|
||||||
-- Check: https://docs.python.org/3/library/pathlib.html
|
|
||||||
|
|
||||||
-- Checks if string is a file or a directory
|
|
||||||
-- @return boolean: Exists or not
|
|
||||||
function string:exists()
|
|
||||||
return os.rename(self, self) ~= nil
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Checks if string is a file
|
|
||||||
-- @return boolean: File or not
|
|
||||||
function string:isfile()
|
|
||||||
if self:exists() then
|
|
||||||
return io.open(self, "a+") ~= nil
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Checks if string is a directory
|
|
||||||
-- @return boolean: Directory or not
|
|
||||||
function string:isdir()
|
|
||||||
if self:exists() then
|
|
||||||
return io.open(self, "a+") == nil
|
|
||||||
elseif self == "." or self == ".." then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Reads file content as string
|
|
||||||
-- @return string or nil: File as string or nil
|
|
||||||
function string:readtext()
|
|
||||||
if self:exists() then
|
|
||||||
return io.open(self):read("*a")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Read file content as lines
|
|
||||||
-- @return table: Table of file lines or nil
|
|
||||||
function string:readlines()
|
|
||||||
local lines = {}
|
|
||||||
if self:exists() then
|
|
||||||
for line in io.open(self):lines() do
|
|
||||||
table.insert(lines, line)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return lines
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Gets file without suffix
|
|
||||||
-- @return string: File wihtout suffix
|
|
||||||
function string:stem()
|
|
||||||
return self:gsub("%.%a+$", "")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Gets file extensions
|
|
||||||
-- @return table: List of file extensions
|
|
||||||
function string:suffixes()
|
|
||||||
local suffixes = {}
|
|
||||||
for suffix in self:gmatch("%.%a+") do
|
|
||||||
table.insert(suffixes, suffix)
|
|
||||||
end
|
|
||||||
return suffixes
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Gets file final extension
|
|
||||||
-- @return string: Final file extension
|
|
||||||
function string:suffix()
|
|
||||||
local suffixes = self:suffixes()
|
|
||||||
if suffixes[#suffixes] then
|
|
||||||
return suffixes[#suffixes]
|
|
||||||
end
|
|
||||||
return ""
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Requires Pandoc
|
|
||||||
-- Check: https://pandoc.org/lua-filters.html#module-pandoc
|
-- Check: https://pandoc.org/lua-filters.html#module-pandoc
|
||||||
|
|
||||||
if pandoc ~= nil then
|
if pandoc ~= nil then
|
||||||
|
@ -6484,8 +6515,8 @@ if pandoc ~= nil then
|
||||||
-- @param file string: File name
|
-- @param file string: File name
|
||||||
-- @return string: File extension according to Pandoc format namespaces
|
-- @return string: File extension according to Pandoc format namespaces
|
||||||
function pandoc.getext(file)
|
function pandoc.getext(file)
|
||||||
local ext = file:suffix():gsub("^.", "")
|
local ext = dog.string.suffix(file):gsub("^.", "")
|
||||||
return ((ext == "md" or ext:isempty()) and "markdown" or ext)
|
return ((ext == "md" or dog.string.isempty(ext)) and "markdown" or ext)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Pandoc converter
|
-- Pandoc converter
|
||||||
|
@ -6499,9 +6530,10 @@ if pandoc ~= nil then
|
||||||
-- @return string: Output file content
|
-- @return string: Output file content
|
||||||
function pandoc.convert(ifile, oformat, ofile, iformat)
|
function pandoc.convert(ifile, oformat, ofile, iformat)
|
||||||
iformat = (iformat == nil and pandoc.getext(ifile) or iformat)
|
iformat = (iformat == nil and pandoc.getext(ifile) or iformat)
|
||||||
local doc = pandoc.write(pandoc.read(ifile:readtext(), iformat), oformat)
|
local itext = pandoc.read(dog.string.readtext(ifile), iformat)
|
||||||
|
local doc = pandoc.write(itext, oformat)
|
||||||
if ofile ~= nil then
|
if ofile ~= nil then
|
||||||
local eol = (os:isunix() and "\n" or "\r\n")
|
local eol = (dog.os:isunix() and "\n" or "\r\n")
|
||||||
io.open(ofile, "w"):write(doc, eol):close()
|
io.open(ofile, "w"):write(doc, eol):close()
|
||||||
end
|
end
|
||||||
return doc
|
return doc
|
||||||
|
@ -6510,7 +6542,7 @@ if pandoc ~= nil then
|
||||||
-- Stringifies Pandoc content
|
-- Stringifies Pandoc content
|
||||||
-- Avoids undesired behavios of pandoc.utils.stringify, such as quotes and
|
-- Avoids undesired behavios of pandoc.utils.stringify, such as quotes and
|
||||||
-- backslashes conversions.
|
-- backslashes conversions.
|
||||||
-- @param content pandoc.MetaValue: Pandoc content value
|
-- @param content pandoc.MetaValue: Pandoc content value
|
||||||
-- @return string: Pandoc stringified value
|
-- @return string: Pandoc stringified value
|
||||||
function pandoc.utils.rawstringify(content)
|
function pandoc.utils.rawstringify(content)
|
||||||
return pandoc.utils.stringify(content:walk {
|
return pandoc.utils.stringify(content:walk {
|
||||||
|
@ -6525,7 +6557,7 @@ if pandoc ~= nil then
|
||||||
RawInline = function(rawinline)
|
RawInline = function(rawinline)
|
||||||
return pandoc.Str(rawinline.text:gsub("\\n", "\n"):gsub("\\t", "\t"))
|
return pandoc.Str(rawinline.text:gsub("\\n", "\n"):gsub("\\t", "\t"))
|
||||||
end,
|
end,
|
||||||
SoftBreak = function(softbreak)
|
SoftBreak = function(_)
|
||||||
return pandoc.Str("\n")
|
return pandoc.Str("\n")
|
||||||
end,
|
end,
|
||||||
Inline = function(inline) return pandoc.utils.stringify(inline) end,
|
Inline = function(inline) return pandoc.utils.stringify(inline) end,
|
||||||
|
@ -6566,6 +6598,8 @@ function nat.get(str)
|
||||||
return str
|
return str
|
||||||
end
|
end
|
||||||
|
|
||||||
|
dog.import()
|
||||||
|
|
||||||
---------------------------------- LITERATE ----------------------------------
|
---------------------------------- LITERATE ----------------------------------
|
||||||
|
|
||||||
-- Variable for all literate stuff
|
-- Variable for all literate stuff
|
||||||
|
|
|
@ -6,9 +6,12 @@ Computable Pandoc:
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
require "fennel"
|
require "fennel"
|
||||||
require "dog"
|
|
||||||
require "nat"
|
require "nat"
|
||||||
|
|
||||||
|
local lua_dog = require("dog")
|
||||||
|
|
||||||
|
dog.import()
|
||||||
|
|
||||||
---------------------------------- LITERATE ----------------------------------
|
---------------------------------- LITERATE ----------------------------------
|
||||||
|
|
||||||
-- Variable for all literate stuff
|
-- Variable for all literate stuff
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
# Lua Dog
|
|
||||||
|
|
||||||
Adds functions to Lua Standard Libraries.
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
luarocks install lua-dog
|
|
||||||
|
|
||||||
## Functions
|
|
||||||
|
|
||||||
Check `src`.
|
|
|
@ -1,9 +0,0 @@
|
||||||
rock_manifest = {
|
|
||||||
doc = {
|
|
||||||
["README.md"] = "907b5c835edf49975acca8a960917c5a"
|
|
||||||
},
|
|
||||||
lua = {
|
|
||||||
["dog.lua"] = "5796081a406363115798e70935347385"
|
|
||||||
},
|
|
||||||
["lua-dog-1.0-0.rockspec"] = "c7c9e3c60f29029838348eb8ecfe3cc9"
|
|
||||||
}
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
# Lua Dog
|
||||||
|
|
||||||
|
Adds functions to Lua Standard Libraries and Pandoc Library.
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
luarocks install lua-dog
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
You can use Lua Dog in 2 ways.
|
||||||
|
|
||||||
|
The laziest way is:
|
||||||
|
|
||||||
|
local dog = require("dog")
|
||||||
|
dog.import()
|
||||||
|
-- Lua Dog 'dog.os.uname()' function was imported as 'os.uname()'
|
||||||
|
os.uname()
|
||||||
|
|
||||||
|
This will import all Lua Dog functions to the Lua Standard Libraries and Pandoc Library.
|
||||||
|
|
||||||
|
If you prefer not to import, the way is:
|
||||||
|
|
||||||
|
require "dog"
|
||||||
|
-- Lua Dog 'dog.os.uname()' function was NOT imported as 'os.uname()'
|
||||||
|
dog.os.uname()
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
|
||||||
|
Check `src`.
|
|
@ -1,12 +1,13 @@
|
||||||
package = "lua-dog"
|
package = "lua-dog"
|
||||||
version = "1.0-0"
|
version = "1.1.0-1"
|
||||||
source = {
|
source = {
|
||||||
url = "https://gitlab.com/perritotuerto/codigo/lua-dog/-/archive/v1.0.0/lua-dog-v1.0.0.tar.gz",
|
url = "https://gitlab.com/perritotuerto/codigo/lua-dog/-/archive/v" ..
|
||||||
|
version .. "/lua-dog-v" .. version .. ".tar.gz",
|
||||||
}
|
}
|
||||||
description = {
|
description = {
|
||||||
summary = "Lua extensions for lazy dogs",
|
summary = "Lua extensions for lazy dogs",
|
||||||
detailed = [[
|
detailed = [[
|
||||||
Adds functions to Lua Standard Libraries.
|
Extends Lua Standard Libraries and Pandoc Library.
|
||||||
]],
|
]],
|
||||||
homepage = "https://gitlab.com/perritotuerto/codigo/lua-dog/",
|
homepage = "https://gitlab.com/perritotuerto/codigo/lua-dog/",
|
||||||
license = "GPLv3",
|
license = "GPLv3",
|
|
@ -0,0 +1,9 @@
|
||||||
|
rock_manifest = {
|
||||||
|
doc = {
|
||||||
|
["README.md"] = "37185e33a737c1f449075b9ca3da5323"
|
||||||
|
},
|
||||||
|
lua = {
|
||||||
|
["dog.lua"] = "6c0d509614d5de3254d649ba0a75c6ee"
|
||||||
|
},
|
||||||
|
["lua-dog-1.1.0-1.rockspec"] = "a979848880cdf078b2c98ce87a37f15a"
|
||||||
|
}
|
|
@ -20,7 +20,7 @@ dependencies = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
["lua-dog"] = {
|
["lua-dog"] = {
|
||||||
["1.0-0"] = {
|
["1.1.0-1"] = {
|
||||||
{
|
{
|
||||||
constraints = {
|
constraints = {
|
||||||
{
|
{
|
||||||
|
@ -43,7 +43,7 @@ dependencies = {
|
||||||
}
|
}
|
||||||
modules = {
|
modules = {
|
||||||
dog = {
|
dog = {
|
||||||
"lua-dog/1.0-0"
|
"lua-dog/1.1.0-1"
|
||||||
},
|
},
|
||||||
fennel = {
|
fennel = {
|
||||||
"fennel/1.3.0-1"
|
"fennel/1.3.0-1"
|
||||||
|
@ -65,7 +65,7 @@ repository = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
["lua-dog"] = {
|
["lua-dog"] = {
|
||||||
["1.0-0"] = {
|
["1.1.0-1"] = {
|
||||||
{
|
{
|
||||||
arch = "installed",
|
arch = "installed",
|
||||||
commands = {},
|
commands = {},
|
||||||
|
|
|
@ -1,7 +1,38 @@
|
||||||
|
-- Variable for storing all the functions
|
||||||
|
local dog = {}
|
||||||
|
|
||||||
|
-- Functions are divided according to the standard library to extend
|
||||||
|
dog.io = {}
|
||||||
|
dog.os = {}
|
||||||
|
dog.string = {}
|
||||||
|
dog.utf8 = {}
|
||||||
|
|
||||||
|
-- Imports dog functions to _G
|
||||||
|
-- Allows using the other functions without a prefix, i.e.:
|
||||||
|
-- dog.os.uname() => os.uname()
|
||||||
|
function dog.import()
|
||||||
|
local msg = "[WARNING] [DOG] "
|
||||||
|
msg = msg .. "Ignoring import: '@1' already exists; use '@2' instead"
|
||||||
|
for libkey, dogfns in pairs(dog) do
|
||||||
|
local lib = _G[libkey]
|
||||||
|
if type(dogfns) == "table" then
|
||||||
|
for fnkey, fn in pairs(dogfns) do
|
||||||
|
if not(lib[fnkey]) then
|
||||||
|
lib[fnkey] = fn
|
||||||
|
else
|
||||||
|
local name = libkey .. "." .. fnkey .. "()"
|
||||||
|
msg = msg:gsub("@1", name):gsub("@2", "dog." .. name)
|
||||||
|
print(msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Tries popen
|
-- Tries popen
|
||||||
-- @param ... string: Chunks for popen
|
-- @param ... string: Chunks for popen
|
||||||
-- @return boolean, string: Status and output of popen
|
-- @return boolean, string: Status and output of popen
|
||||||
function io.try(...)
|
function dog.io.try(...)
|
||||||
local cmd = table.concat({...}, " ") .. " 2>&1"
|
local cmd = table.concat({...}, " ") .. " 2>&1"
|
||||||
local handle = io.popen(cmd)
|
local handle = io.popen(cmd)
|
||||||
local output = handle:read("*a")
|
local output = handle:read("*a")
|
||||||
|
@ -12,13 +43,13 @@ end
|
||||||
-- Gets OS short name
|
-- Gets OS short name
|
||||||
-- It is just intented to know if it is Linux, macOS or Windows.
|
-- It is just intented to know if it is Linux, macOS or Windows.
|
||||||
-- @return string: "linux" or "bsd" or "macos" or "windows"
|
-- @return string: "linux" or "bsd" or "macos" or "windows"
|
||||||
function os.uname()
|
function dog.os.uname()
|
||||||
local status, output = io.try("uname")
|
local status, output = dog.io.try("uname")
|
||||||
if status then
|
if status then
|
||||||
output = output:gsub(" .*", ""):lower()
|
output = output:gsub(" .*", ""):lower()
|
||||||
if output ~= "linux" and output:match("bsd") ~= nil then
|
if output ~= "linux" and output:match("bsd") ~= nil then
|
||||||
return "bsd"
|
return "bsd"
|
||||||
elseif out ~= "linux" then
|
elseif output ~= "linux" then
|
||||||
return "macos"
|
return "macos"
|
||||||
end
|
end
|
||||||
return "linux"
|
return "linux"
|
||||||
|
@ -28,19 +59,19 @@ end
|
||||||
|
|
||||||
-- Checks if OS is windows
|
-- Checks if OS is windows
|
||||||
-- @return boolean: Windows or not
|
-- @return boolean: Windows or not
|
||||||
function os.iswin()
|
function dog.os.iswin()
|
||||||
return os.uname() == "windows"
|
return dog.os.uname() == "windows"
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Checks if OS is Unix
|
-- Checks if OS is Unix
|
||||||
-- @return boolean: Unix or not
|
-- @return boolean: Unix or not
|
||||||
function os.isunix()
|
function dog.os.isunix()
|
||||||
return os.uname() ~= "windows"
|
return dog.os.uname() ~= "windows"
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Gets OS language
|
-- Gets OS language
|
||||||
-- @return string, string, string: Language, locale and encoding
|
-- @return string, string, string: Language, locale and encoding
|
||||||
function os.lang()
|
function dog.os.lang()
|
||||||
local lang = os.getenv("LANG")
|
local lang = os.getenv("LANG")
|
||||||
if lang ~= nil then
|
if lang ~= nil then
|
||||||
return lang:match("(%w%w)_?(%w?%w?)%.?(.*)")
|
return lang:match("(%w%w)_?(%w?%w?)%.?(.*)")
|
||||||
|
@ -48,10 +79,158 @@ function os.lang()
|
||||||
return "en", "US", "UTF-8"
|
return "en", "US", "UTF-8"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Checks if string is empty
|
||||||
|
-- @return boolean: Empty or not
|
||||||
|
function dog.string.isempty(str)
|
||||||
|
return str == ''
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Changes newlines so everything is in one line
|
||||||
|
-- @return string: String with formatted newlines as literal "\n"
|
||||||
|
function dog.string.linearize(str)
|
||||||
|
return str:gsub("\n", "\\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Normalizes string
|
||||||
|
-- @return string: Normalized string
|
||||||
|
function dog.string.normalize(str)
|
||||||
|
str = str:lower()
|
||||||
|
for newchar, chars in pairs(dog.utf8.table()) do
|
||||||
|
for _, oldchar in ipairs(chars) do
|
||||||
|
str = str:gsub(oldchar, newchar)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return str
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Adds indent
|
||||||
|
-- @param num number: Indent size, 2 by default
|
||||||
|
-- @param char string: Indent character, space by default
|
||||||
|
-- @return strin: Indented string
|
||||||
|
function dog.string.indent(str, num, char)
|
||||||
|
num = num or 2
|
||||||
|
char = char or " "
|
||||||
|
char = string.rep(char, num)
|
||||||
|
return char .. str:gsub("\n", "\n" .. char)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Splits the string
|
||||||
|
-- Note: only support splitting by one character.
|
||||||
|
-- Could be solved by slicing with find.
|
||||||
|
-- @param sep string: String separator, space by default
|
||||||
|
-- @return table: String matches
|
||||||
|
function dog.string.split(str, sep)
|
||||||
|
sep = sep or "%s+"
|
||||||
|
local parts = {}
|
||||||
|
for part in str:gmatch("([^" .. sep .. "]+)") do
|
||||||
|
table.insert(parts, part)
|
||||||
|
end
|
||||||
|
return parts
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Removes spaces at the beginning of the string
|
||||||
|
-- @return string: Left stripped string
|
||||||
|
function dog.string.lstrip(str)
|
||||||
|
return str:gsub("^%s+", "")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Removes spaces at the end of the string
|
||||||
|
-- @return string: Right stripped string
|
||||||
|
function dog.string.rstrip(str)
|
||||||
|
return str:gsub("%s+$", "")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Removes spaces at the beginning and at the end of the string
|
||||||
|
-- @return string: Stripped string
|
||||||
|
function dog.string.strip(str)
|
||||||
|
str = dog.string.lstrip(str)
|
||||||
|
return dog.string.rstrip(str)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Alias of strip
|
||||||
|
function dog.string.trim(str)
|
||||||
|
return dog.string.strip(str)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- The following are heavily influenced by Python pathlib
|
||||||
|
-- Check: https://docs.python.org/3/library/pathlib.html
|
||||||
|
|
||||||
|
-- Checks if string is a file or a directory
|
||||||
|
-- @return boolean: Exists or not
|
||||||
|
function dog.string.exists(str)
|
||||||
|
return os.rename(str, str) ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Checks if string is a file
|
||||||
|
-- @return boolean: File or not
|
||||||
|
function dog.string.isfile(str)
|
||||||
|
if dog.string.exists(str) then
|
||||||
|
return io.open(str, "a+") ~= nil
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Checks if string is a directory
|
||||||
|
-- @return boolean: Directory or not
|
||||||
|
function dog.string.isdir(str)
|
||||||
|
if dog.string.exists(str) then
|
||||||
|
return io.open(str, "a+") == nil
|
||||||
|
elseif str == "." or str == ".." then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Reads file content as string
|
||||||
|
-- @return string or nil: File as string or nil
|
||||||
|
function dog.string.readtext(str)
|
||||||
|
if dog.string.exists(str) then
|
||||||
|
return io.open(str):read("*a")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Read file content as lines
|
||||||
|
-- @return table: Table of file lines or nil
|
||||||
|
function dog.string.readlines(str)
|
||||||
|
local lines = {}
|
||||||
|
if dog.string.exists(str) then
|
||||||
|
for line in io.open(str):lines() do
|
||||||
|
table.insert(lines, line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return lines
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Gets file without suffix
|
||||||
|
-- @return string: File wihtout suffix
|
||||||
|
function dog.string.stem(str)
|
||||||
|
return str:gsub("%.%a+$", "")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Gets file extensions
|
||||||
|
-- @return table: List of file extensions
|
||||||
|
function dog.string.suffixes(str)
|
||||||
|
local suffixes = {}
|
||||||
|
for suffix in str:gmatch("%.%a+") do
|
||||||
|
table.insert(suffixes, suffix)
|
||||||
|
end
|
||||||
|
return suffixes
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Gets file final extension
|
||||||
|
-- @return string: Final file extension
|
||||||
|
function dog.string.suffix(str)
|
||||||
|
local suffixes = str:suffixes()
|
||||||
|
if suffixes[#suffixes] then
|
||||||
|
return suffixes[#suffixes]
|
||||||
|
end
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
|
||||||
-- Gets an equivalency table between ASCII and Unicode
|
-- Gets an equivalency table between ASCII and Unicode
|
||||||
-- Note: filled on demand.
|
-- Note: filled on demand.
|
||||||
-- @return table: ASCII-Unicode table equivalency
|
-- @return table: ASCII-Unicode table equivalency
|
||||||
function utf8.table()
|
function dog.utf8.table()
|
||||||
return {
|
return {
|
||||||
["a"] = {"á", "à", "ä"},
|
["a"] = {"á", "à", "ä"},
|
||||||
["e"] = {"é", "è", "ë"},
|
["e"] = {"é", "è", "ë"},
|
||||||
|
@ -62,155 +241,7 @@ function utf8.table()
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Checks if string is empty
|
-- Extends Pandoc Library
|
||||||
-- @return boolean: Empty or not
|
|
||||||
function string:isempty()
|
|
||||||
return self == ''
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Changes newlines so everything is in one line
|
|
||||||
-- @return string: String with formatted newlines as literal "\n"
|
|
||||||
function string:linearize()
|
|
||||||
return self:gsub("\n", "\\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Normalizes string
|
|
||||||
-- @return string: Normalized string
|
|
||||||
function string:normalize()
|
|
||||||
self = self:lower()
|
|
||||||
for newchar, chars in pairs(utf8.table()) do
|
|
||||||
for _, oldchar in ipairs(chars) do
|
|
||||||
self = self:gsub(oldchar, newchar)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Adds indent
|
|
||||||
-- @param num number: Indent size, 2 by default
|
|
||||||
-- @param char string: Indent character, space by default
|
|
||||||
-- @return strin: Indented string
|
|
||||||
function string:indent(num, char)
|
|
||||||
num = num or 2
|
|
||||||
char = char or " "
|
|
||||||
char = string.rep(char, num)
|
|
||||||
return char .. self:gsub("\n", "\n" .. char)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Splits the string
|
|
||||||
-- Note: only support splitting by one character.
|
|
||||||
-- Could be solved by slicing with find.
|
|
||||||
-- @param sep string: String separator, space by default
|
|
||||||
-- @return table: String matches
|
|
||||||
function string:split(sep)
|
|
||||||
sep = sep or "%s+"
|
|
||||||
local parts = {}
|
|
||||||
for part in self:gmatch("([^" .. sep .. "]+)") do
|
|
||||||
table.insert(parts, part)
|
|
||||||
end
|
|
||||||
return parts
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Removes spaces at the beginning of the string
|
|
||||||
-- @return string: Left stripped string
|
|
||||||
function string:lstrip()
|
|
||||||
return self:gsub("^%s+", "")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Removes spaces at the end of the string
|
|
||||||
-- @return string: Right stripped string
|
|
||||||
function string:rstrip()
|
|
||||||
return self:gsub("%s+$", "")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Removes spaces at the beginning and at the end of the string
|
|
||||||
-- @return string: Stripped string
|
|
||||||
function string:strip()
|
|
||||||
self = self:lstrip():rstrip()
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Alias of strip
|
|
||||||
function string:trim()
|
|
||||||
return self:strip()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- The following are heavily influenced by Python pathlib
|
|
||||||
-- Check: https://docs.python.org/3/library/pathlib.html
|
|
||||||
|
|
||||||
-- Checks if string is a file or a directory
|
|
||||||
-- @return boolean: Exists or not
|
|
||||||
function string:exists()
|
|
||||||
return os.rename(self, self) ~= nil
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Checks if string is a file
|
|
||||||
-- @return boolean: File or not
|
|
||||||
function string:isfile()
|
|
||||||
if self:exists() then
|
|
||||||
return io.open(self, "a+") ~= nil
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Checks if string is a directory
|
|
||||||
-- @return boolean: Directory or not
|
|
||||||
function string:isdir()
|
|
||||||
if self:exists() then
|
|
||||||
return io.open(self, "a+") == nil
|
|
||||||
elseif self == "." or self == ".." then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Reads file content as string
|
|
||||||
-- @return string or nil: File as string or nil
|
|
||||||
function string:readtext()
|
|
||||||
if self:exists() then
|
|
||||||
return io.open(self):read("*a")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Read file content as lines
|
|
||||||
-- @return table: Table of file lines or nil
|
|
||||||
function string:readlines()
|
|
||||||
local lines = {}
|
|
||||||
if self:exists() then
|
|
||||||
for line in io.open(self):lines() do
|
|
||||||
table.insert(lines, line)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return lines
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Gets file without suffix
|
|
||||||
-- @return string: File wihtout suffix
|
|
||||||
function string:stem()
|
|
||||||
return self:gsub("%.%a+$", "")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Gets file extensions
|
|
||||||
-- @return table: List of file extensions
|
|
||||||
function string:suffixes()
|
|
||||||
local suffixes = {}
|
|
||||||
for suffix in self:gmatch("%.%a+") do
|
|
||||||
table.insert(suffixes, suffix)
|
|
||||||
end
|
|
||||||
return suffixes
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Gets file final extension
|
|
||||||
-- @return string: Final file extension
|
|
||||||
function string:suffix()
|
|
||||||
local suffixes = self:suffixes()
|
|
||||||
if suffixes[#suffixes] then
|
|
||||||
return suffixes[#suffixes]
|
|
||||||
end
|
|
||||||
return ""
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Requires Pandoc
|
|
||||||
-- Check: https://pandoc.org/lua-filters.html#module-pandoc
|
-- Check: https://pandoc.org/lua-filters.html#module-pandoc
|
||||||
|
|
||||||
if pandoc ~= nil then
|
if pandoc ~= nil then
|
||||||
|
@ -222,8 +253,8 @@ if pandoc ~= nil then
|
||||||
-- @param file string: File name
|
-- @param file string: File name
|
||||||
-- @return string: File extension according to Pandoc format namespaces
|
-- @return string: File extension according to Pandoc format namespaces
|
||||||
function pandoc.getext(file)
|
function pandoc.getext(file)
|
||||||
local ext = file:suffix():gsub("^.", "")
|
local ext = dog.string.suffix(file):gsub("^.", "")
|
||||||
return ((ext == "md" or ext:isempty()) and "markdown" or ext)
|
return ((ext == "md" or dog.string.isempty(ext)) and "markdown" or ext)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Pandoc converter
|
-- Pandoc converter
|
||||||
|
@ -237,9 +268,10 @@ if pandoc ~= nil then
|
||||||
-- @return string: Output file content
|
-- @return string: Output file content
|
||||||
function pandoc.convert(ifile, oformat, ofile, iformat)
|
function pandoc.convert(ifile, oformat, ofile, iformat)
|
||||||
iformat = (iformat == nil and pandoc.getext(ifile) or iformat)
|
iformat = (iformat == nil and pandoc.getext(ifile) or iformat)
|
||||||
local doc = pandoc.write(pandoc.read(ifile:readtext(), iformat), oformat)
|
local itext = pandoc.read(dog.string.readtext(ifile), iformat)
|
||||||
|
local doc = pandoc.write(itext, oformat)
|
||||||
if ofile ~= nil then
|
if ofile ~= nil then
|
||||||
local eol = (os:isunix() and "\n" or "\r\n")
|
local eol = (dog.os:isunix() and "\n" or "\r\n")
|
||||||
io.open(ofile, "w"):write(doc, eol):close()
|
io.open(ofile, "w"):write(doc, eol):close()
|
||||||
end
|
end
|
||||||
return doc
|
return doc
|
||||||
|
@ -248,7 +280,7 @@ if pandoc ~= nil then
|
||||||
-- Stringifies Pandoc content
|
-- Stringifies Pandoc content
|
||||||
-- Avoids undesired behavios of pandoc.utils.stringify, such as quotes and
|
-- Avoids undesired behavios of pandoc.utils.stringify, such as quotes and
|
||||||
-- backslashes conversions.
|
-- backslashes conversions.
|
||||||
-- @param content pandoc.MetaValue: Pandoc content value
|
-- @param content pandoc.MetaValue: Pandoc content value
|
||||||
-- @return string: Pandoc stringified value
|
-- @return string: Pandoc stringified value
|
||||||
function pandoc.utils.rawstringify(content)
|
function pandoc.utils.rawstringify(content)
|
||||||
return pandoc.utils.stringify(content:walk {
|
return pandoc.utils.stringify(content:walk {
|
||||||
|
@ -263,7 +295,7 @@ if pandoc ~= nil then
|
||||||
RawInline = function(rawinline)
|
RawInline = function(rawinline)
|
||||||
return pandoc.Str(rawinline.text:gsub("\\n", "\n"):gsub("\\t", "\t"))
|
return pandoc.Str(rawinline.text:gsub("\\n", "\n"):gsub("\\t", "\t"))
|
||||||
end,
|
end,
|
||||||
SoftBreak = function(softbreak)
|
SoftBreak = function(_)
|
||||||
return pandoc.Str("\n")
|
return pandoc.Str("\n")
|
||||||
end,
|
end,
|
||||||
Inline = function(inline) return pandoc.utils.stringify(inline) end,
|
Inline = function(inline) return pandoc.utils.stringify(inline) end,
|
||||||
|
@ -295,3 +327,5 @@ if pandoc ~= nil then
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return dog
|
||||||
|
|
|
@ -5,7 +5,8 @@ local optpath = "./opt/share/lua/5.4/"
|
||||||
package.path = optpath .. "?.lua;" .. package.path
|
package.path = optpath .. "?.lua;" .. package.path
|
||||||
|
|
||||||
-- Adds Lua custom extensions
|
-- Adds Lua custom extensions
|
||||||
require "dog"
|
local lua_dog = require("dog")
|
||||||
|
lua_dog.import()
|
||||||
|
|
||||||
-- Makes distribution
|
-- Makes distribution
|
||||||
local function make_dist(name, bundle)
|
local function make_dist(name, bundle)
|
||||||
|
@ -22,7 +23,7 @@ local function make_dist(name, bundle)
|
||||||
-- Variables
|
-- Variables
|
||||||
local dist = pandoc.path.join({"dist", name})
|
local dist = pandoc.path.join({"dist", name})
|
||||||
local fnl = chomp(optpath .. "fennel.lua"):gsub("\nreturn mod\n", "\nlocal fnl = mod\n")
|
local fnl = chomp(optpath .. "fennel.lua"):gsub("\nreturn mod\n", "\nlocal fnl = mod\n")
|
||||||
local dog = chomp(optpath .. "dog.lua")
|
local dog = chomp(optpath .. "dog.lua"):gsub("\nreturn dog\n", "")
|
||||||
local nat = chomp("src/natural.lua"):gsub("\nreturn nat\n", "")
|
local nat = chomp("src/natural.lua"):gsub("\nreturn nat\n", "")
|
||||||
local lit = chomp("src/literate.lua"):gsub("#locale%(%)", ("src/locale.yaml"):readtext())
|
local lit = chomp("src/literate.lua"):gsub("#locale%(%)", ("src/locale.yaml"):readtext())
|
||||||
local pan = chomp("src/pandoc.lua")
|
local pan = chomp("src/pandoc.lua")
|
||||||
|
@ -50,8 +51,10 @@ Fennel:
|
||||||
file:write(fnl, dog, nat)
|
file:write(fnl, dog, nat)
|
||||||
else
|
else
|
||||||
file:write("--[[\n", license, "\n]]--\n")
|
file:write("--[[\n", license, "\n]]--\n")
|
||||||
file:write('\nrequire "fennel"\nrequire "dog"\nrequire "nat"\n')
|
file:write('\nrequire "fennel"\nrequire "nat"\n')
|
||||||
|
file:write('\nlocal lua_dog = require("dog")\n')
|
||||||
end
|
end
|
||||||
|
file:write('\ndog.import()\n')
|
||||||
file:write(lit, pan)
|
file:write(lit, pan)
|
||||||
file:close()
|
file:close()
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
package.path = "./opt/share/lua/5.4/?.lua;" .. package.path
|
package.path = "./opt/share/lua/5.4/?.lua;" .. package.path
|
||||||
|
|
||||||
-- Adds Lua custom extensions
|
-- Adds Lua custom extensions
|
||||||
require "dog"
|
local lua_dog = require("dog")
|
||||||
|
lua_dog.import()
|
||||||
|
|
||||||
-- Gets command according to OS
|
-- Gets command according to OS
|
||||||
local function getcmd()
|
local function getcmd()
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package.path = "./opt/share/lua/5.4/?.lua;" .. package.path
|
package.path = "./opt/share/lua/5.4/?.lua;" .. package.path
|
||||||
|
|
||||||
-- Adds Lua custom extensions
|
-- Adds Lua custom extensions
|
||||||
require "dog"
|
|
||||||
require "scripts.make_dist"
|
require "scripts.make_dist"
|
||||||
|
|
||||||
-- Variables
|
-- Variables
|
||||||
|
|
Loading…
Reference in New Issue