diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/syst-lua.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/syst-lua.lua | 62 |
1 files changed, 29 insertions, 33 deletions
diff --git a/Master/texmf-dist/tex/context/base/syst-lua.lua b/Master/texmf-dist/tex/context/base/syst-lua.lua index 8a5a9531c1b..f735b1962e6 100644 --- a/Master/texmf-dist/tex/context/base/syst-lua.lua +++ b/Master/texmf-dist/tex/context/base/syst-lua.lua @@ -6,55 +6,59 @@ if not modules then modules = { } end modules ['syst-lua'] = { license = "see context related readme files" } -local texsprint, texprint, texwrite, texiowrite_nl = tex.sprint, tex.print, tex.write, texio.write_nl -local format, find = string.format, string.find +local format, find, match, rep = string.format, string.find, string.match, string.rep local tonumber = tonumber -local S, Ct, lpegmatch, lpegsplitat = lpeg.S, lpeg.Ct, lpeg.match, lpeg.splitat +local S, lpegmatch, lpegtsplitat = lpeg.S, lpeg.match, lpeg.tsplitat -local ctxcatcodes = tex.ctxcatcodes +local context = context -commands = commands or { } -- cs = commands -- shorter, maybe some day, not used now +commands = commands or { } function commands.writestatus(...) logs.status(...) end -- overloaded later --- todo: use shorter names i.e. less tokenization +-- todo: use shorter names i.e. less tokenization, like prtcatcodes + f_o_t_a + +local firstoftwoarguments = context.firstoftwoarguments -- context.constructcsonly("firstoftwoarguments" ) +local secondoftwoarguments = context.secondoftwoarguments -- context.constructcsonly("secondoftwoarguments") +local firstofoneargument = context.firstofoneargument -- context.constructcsonly("firstofoneargument" ) +local gobbleoneargument = context.gobbleoneargument -- context.constructcsonly("gobbleoneargument" ) local function testcase(b) - if b then -- looks faster with if than with expression - texsprint(ctxcatcodes,"\\firstoftwoarguments") + if b then + firstoftwoarguments() else - texsprint(ctxcatcodes,"\\secondoftwoarguments") + secondoftwoarguments() end end -commands.testcase = testcase -commands.doifelse = testcase - function commands.doif(b) if b then - texsprint(ctxcatcodes,"\\firstofoneargument") + firstofoneargument() else - texsprint(ctxcatcodes,"\\gobbleoneargument") + gobbleoneargument() end end function commands.doifnot(b) if b then - texsprint(ctxcatcodes,"\\gobbleoneargument") + gobbleoneargument() else - texsprint(ctxcatcodes,"\\firstofoneargument") + firstofoneargument() end end +commands.testcase = testcase +commands.doifelse = testcase + function commands.boolcase(b) - if b then texwrite(1) else texwrite(0) end + context(b and 1 or 0) end function commands.doifelsespaces(str) - return commands.doifelse(find(str,"^ +$")) + return testcase(find(str,"^ +$")) end -local s = Ct(lpegsplitat(",")) +local s = lpegtsplitat(",") local h = { } function commands.doifcommonelse(a,b) @@ -89,19 +93,11 @@ function commands.doifdimenstringelse(str) testcase(lpegmatch(pattern,str)) end -local splitter = lpegsplitat(S(". ")) +function commands.firstinset(str) + local first = match(str,"^([^,]+),") + context(first or str) +end -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) - ) +function commands.ntimes(str,n) + context(rep(str,n or 1)) end |