Skip to content

Commit

Permalink
Revert "Lua 5.1 compatibility"
Browse files Browse the repository at this point in the history
  • Loading branch information
Omikhleia authored Dec 8, 2023
1 parent de7c21e commit e345b37
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 34 deletions.
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@v4
uses: actions/checkout@v3
- name: Luacheck
uses: lunarmodules/luacheck@v1
uses: lunarmodules/luacheck@v0
18 changes: 10 additions & 8 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
std = "min+sile"
std = "max"
include_files = {
"**/*.lua",
"sile.in",
Expand All @@ -11,20 +11,22 @@ exclude_files = {
"compare-*",
"sile-*",
"lua_modules",
"lua-libraries",
".lua",
".luarocks",
".install"
}
files["**/*_spec.lua"] = {
std = "+busted"
}
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
}
globals = {
"SILE",
"SU",
"luautf8",
"pl",
"fluent",
"SYSTEM_SILE_PATH",
"SHARED_LIB_EXT"
}
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 = sile.options or {}
local options = master.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: 2 additions & 3 deletions lua-libraries/README.tinyyaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
The "vendored" version of tinyyaml used here is:
https://github.com/api7/lua-tinyyaml (0.4.4 rockspec)
https://github.com/api7/lua-tinyyaml (0.4.3 rockspec at the time of initial
import)

It's a fork from:
https://github.com/peposso/lua-tinyyaml (which had a 1.0 rockspec earlier)
Expand All @@ -17,5 +18,3 @@ 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: 2 additions & 9 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) * 10^(3 - #f) -- MODIFIED RESILIENT Lua min compat
self.fraction = tonumber(f) * math.pow(10, 3 - #f)
elseif f then
self.fraction = f
else
Expand Down Expand Up @@ -611,10 +611,8 @@ 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, indent2))
tinsert(seq, self:parsescalar(rest, lines))
end
end
return seq
Expand Down Expand Up @@ -775,11 +773,6 @@ 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: 2 additions & 5 deletions packages/resilient/bookmatters/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ 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(
(color.r * 255)^2 * 0.241
+ (color.g * 255)^2 * 0.691
+ (color.b * 255)^2 * 0.068
)
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)
end
local function contrastColor(color)
if not color.r then
Expand Down Expand Up @@ -164,6 +160,7 @@ 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: 1 addition & 3 deletions packages/resilient/poetry/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
--
local ast = require("silex.ast")
local createStructuredCommand = ast.createStructuredCommand
local LOG10 = math.log(10)

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

Expand Down Expand Up @@ -179,8 +178,7 @@ function package:registerCommands ()
digitSize = SILE.shaper:measureChar("0").width
end)
local setback = SILE.length("1.75em"):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()
indent = SILE.length((math.floor(math.log10(nVerse + iVerse)) + 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:tonumber() < 0 then
if hbox.width < 0 then
SU.warn("Negative hbox width should not occur any more, please report an issue")
end
local remainingSpace = hbox.width:tonumber() < 0 and -hbox.width or -beforekern:absolute() - hbox.width
local remainingSpace = hbox.width < 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"):tonumber() <= 0 then
if remainingSpace:tonumber() - SILE.length("1nspc"):absolute() <= 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

0 comments on commit e345b37

Please sign in to comment.