summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/syst-lua.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/syst-lua.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/syst-lua.lua52
1 files changed, 25 insertions, 27 deletions
diff --git a/Master/texmf-dist/tex/context/base/syst-lua.lua b/Master/texmf-dist/tex/context/base/syst-lua.lua
index 64028295350..8a5a9531c1b 100644
--- a/Master/texmf-dist/tex/context/base/syst-lua.lua
+++ b/Master/texmf-dist/tex/context/base/syst-lua.lua
@@ -8,33 +8,19 @@ if not modules then modules = { } end modules ['syst-lua'] = {
local texsprint, texprint, texwrite, texiowrite_nl = tex.sprint, tex.print, tex.write, texio.write_nl
local format, find = string.format, string.find
-local lpegmatch = lpeg.match
+local tonumber = tonumber
+local S, Ct, lpegmatch, lpegsplitat = lpeg.S, lpeg.Ct, lpeg.match, lpeg.splitat
local ctxcatcodes = tex.ctxcatcodes
-commands = commands or { } cs = commands -- shorter
+commands = commands or { } -- cs = commands -- shorter, maybe some day, not used now
-function commands.writestatus(a,b,c,...)
- if c then
- texiowrite_nl(format("%-16s: %s\n",a,format(b,c,...)))
- else
- texiowrite_nl(format("%-16s: %s\n",a,b)) -- b can have %'s
- end
-end
-function commands.writedebug(a,b,c,...)
- if c then
- texiowrite_nl(format("%-16s| %s\n",a,format(b,c,...)))
- else
- texiowrite_nl(format("%-16s| %s\n",a,b)) -- b can have %'s
- end
-end
+function commands.writestatus(...) logs.status(...) end -- overloaded later
-function commands.report(s,t,...)
- commands.writestatus("!"..s,format(t,...))
-end
+-- todo: use shorter names i.e. less tokenization
local function testcase(b)
- if b then -- faster with if than with expression
+ if b then -- looks faster with if than with expression
texsprint(ctxcatcodes,"\\firstoftwoarguments")
else
texsprint(ctxcatcodes,"\\secondoftwoarguments")
@@ -51,6 +37,7 @@ function commands.doif(b)
texsprint(ctxcatcodes,"\\gobbleoneargument")
end
end
+
function commands.doifnot(b)
if b then
texsprint(ctxcatcodes,"\\gobbleoneargument")
@@ -67,7 +54,7 @@ function commands.doifelsespaces(str)
return commands.doifelse(find(str,"^ +$"))
end
-local s = lpeg.Ct(lpeg.splitat(","))
+local s = Ct(lpegsplitat(","))
local h = { }
function commands.doifcommonelse(a,b)
@@ -96,14 +83,25 @@ function commands.doifinsetelse(a,b)
return testcase(false)
end
-function commands. def (cs,value) texsprint(ctxcatcodes,format( "\\def\\%s{%s}",cs,value)) end
-function commands.edef (cs,value) texsprint(ctxcatcodes,format("\\edef\\%s{%s}",cs,value)) end
-function commands.gdef (cs,value) texsprint(ctxcatcodes,format("\\gdef\\%s{%s}",cs,value)) end
-function commands.xdef (cs,value) texsprint(ctxcatcodes,format("\\xdef\\%s{%s}",cs,value)) end
-function commands.chardef(cs,value) texsprint(ctxcatcodes,format("\\chardef\\%s=%s\\relax",cs,value)) end
-
local pattern = lpeg.patterns.validdimen
function commands.doifdimenstringelse(str)
testcase(lpegmatch(pattern,str))
end
+
+local splitter = lpegsplitat(S(". "))
+
+function commands.doifolderversionelse(one,two) -- one >= two
+ if not two then
+ one, two = environment.version, one
+ elseif one == "" then
+ one = environment.version
+ end
+ local y_1, m_1, d_1 = lpegmatch(splitter,one)
+ local y_2, m_2, d_2 = lpegmatch(splitter,two)
+ commands.testcase (
+ (tonumber(y_1) or 0) >= (tonumber(y_2) or 0) and
+ (tonumber(m_1) or 0) >= (tonumber(m_2) or 0) and
+ (tonumber(d_1) or 0) >= (tonumber(d_1) or 0)
+ )
+end