Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua 5.1 compatibility #70

Merged
merged 7 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/luacheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Luacheck
uses: lunarmodules/luacheck@v0
uses: lunarmodules/luacheck@v1
18 changes: 8 additions & 10 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
std = "max"
std = "min+sile"
include_files = {
"**/*.lua",
"sile.in",
Expand All @@ -11,22 +11,20 @@ exclude_files = {
"compare-*",
"sile-*",
"lua_modules",
"lua-libraries",
".lua",
".luarocks",
".install"
}
files["**/*_spec.lua"] = {
std = "+busted"
}
globals = {
"SILE",
"SU",
"luautf8",
"pl",
"fluent",
"SYSTEM_SILE_PATH",
"SHARED_LIB_EXT"
files["lua-libraries"] = {
-- matter of taste and not harmful
ignore = {
"211", -- unused function / unused variable
"212/self", -- unused argument self
"412", --variable was previously defined as an argument
}
}
max_line_length = false
ignore = {
Expand Down
2 changes: 1 addition & 1 deletion inputters/silm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ function inputter:parse (doc)
end

-- Document wrap-up
local options = master.sile.options or {}
local options = sile.options or {}
local classopts = isRoot and {
class = options.class or "resilient.book", -- Sane default. We Are Resilient.
papersize = options.papersize,
Expand Down
5 changes: 3 additions & 2 deletions lua-libraries/README.tinyyaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
The "vendored" version of tinyyaml used here is:
https://github.com/api7/lua-tinyyaml (0.4.3 rockspec at the time of initial
import)
https://github.com/api7/lua-tinyyaml (0.4.4 rockspec)

It's a fork from:
https://github.com/peposso/lua-tinyyaml (which had a 1.0 rockspec earlier)
Expand All @@ -18,3 +17,5 @@ RESILIENT was to avoid a C binding dependency, since style files are
reasonably small theoretically (so performance do not really matter) and
only need a subset of YAML (so a pure-Lua implementation, even possibly
incomplete, ought to be sufficient.)

Modications are marked with comments MODIFIED RESILIENT
11 changes: 9 additions & 2 deletions lua-libraries/resilient-tinyyaml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function types.timestamp:__init(y, m, d, h, i, s, f, z)
self.minute = tonumber(i or 0)
self.second = tonumber(s or 0)
if type(f) == 'string' and sfind(f, '^%d+$') then
self.fraction = tonumber(f) * math.pow(10, 3 - #f)
self.fraction = tonumber(f) * 10^(3 - #f) -- MODIFIED RESILIENT Lua min compat
elseif f then
self.fraction = f
else
Expand Down Expand Up @@ -611,8 +611,10 @@ function Parser:parseseq(line, lines, indent)
error("did not find expected alphabetic or numeric character")
elseif rest then
-- Array entry with a value
local nextline = lines[1]
local indent2 = countindent(nextline)
tremove(lines, 1)
tinsert(seq, self:parsescalar(rest, lines))
tinsert(seq, self:parsescalar(rest, lines, indent2))
end
end
return seq
Expand Down Expand Up @@ -773,6 +775,11 @@ end
-- : (list<str>)->dict
function Parser:parsedocuments(lines)
lines = compactifyemptylines(lines)
-- BEGIN MODIFIED RESILIENT
if #lines == 0 then
return {}
end
-- END MODIFIED RESILIENT

if sfind(lines[1], '^%%YAML') then tremove(lines, 1) end

Expand Down
7 changes: 5 additions & 2 deletions packages/resilient/bookmatters/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ end

-- Source: https://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx
local function weightedColorDistanceIn3D (color)
return math.sqrt(math.pow(color.r * 255, 2) * 0.241 + math.pow(color.g * 255, 2) * 0.691 + math.pow(color.b * 255, 2) * 0.068)
return math.sqrt(
(color.r * 255)^2 * 0.241
+ (color.g * 255)^2 * 0.691
+ (color.b * 255)^2 * 0.068
)
end
local function contrastColor(color)
if not color.r then
Expand Down Expand Up @@ -160,7 +164,6 @@ function package:registerCommands ()
end

if metadata["meta:isbn"] then
-- local H = SILE.measurement("100%fh"):tonumber() - SILE.measurement("40mm"):tonumber()
SILE.call("skip", { height = offset })
SILE.call("kern", { width = SILE.nodefactory.hfillglue() })
SILE.call("framebox", { fillcolor = "white", padding = pad1, borderwidth = 0 }, {
Expand Down
4 changes: 3 additions & 1 deletion packages/resilient/poetry/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
--
local ast = require("silex.ast")
local createStructuredCommand = ast.createStructuredCommand
local LOG10 = math.log(10)

local base = require("packages.resilient.base")

Expand Down Expand Up @@ -178,7 +179,8 @@ function package:registerCommands ()
digitSize = SILE.shaper:measureChar("0").width
end)
local setback = SILE.length("1.75em"):absolute()
indent = SILE.length((math.floor(math.log10(nVerse + iVerse)) + 1) * digitSize):absolute()
local logv = math.floor(math.log(nVerse + iVerse) / LOG10) -- Reminder: math.log10 is not in Lua "min" profiile
indent = SILE.length((logv + 1) * digitSize):absolute()
+ setback
+ SILE.length(SILE.settings:get("document.parindent")):absolute()
end
Expand Down
6 changes: 3 additions & 3 deletions packages/resilient/styles/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -563,14 +563,14 @@ function package:registerCommands ()
local hbox = SILE.typesetter:makeHbox(function ()
SILE.call("style:apply", { name = name }, { text })
end)
if hbox.width < 0 then
if hbox.width:tonumber() < 0 then
SU.warn("Negative hbox width should not occur any more, please report an issue")
end
local remainingSpace = hbox.width < 0 and -hbox.width or -beforekern:absolute() - hbox.width
local remainingSpace = hbox.width:tonumber() < 0 and -hbox.width or -beforekern:absolute() - hbox.width

-- We want at least the space of a figure digit between the number
-- and the text.
if remainingSpace:tonumber() - SILE.length("1nspc"):absolute() <= 0 then
if remainingSpace:tonumber() - SILE.length("1nspc"):tonumber() <= 0 then
-- It's not the case, the number goes beyond the available space.
-- So add a fixed interword space after it.
SILE.call("style:apply", { name = name }, { text })
Expand Down