summaryrefslogtreecommitdiff
path: root/tex/context/base/core-uti.mkiv
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/core-uti.mkiv')
-rw-r--r--tex/context/base/core-uti.mkiv103
1 files changed, 103 insertions, 0 deletions
diff --git a/tex/context/base/core-uti.mkiv b/tex/context/base/core-uti.mkiv
new file mode 100644
index 000000000..6883f2227
--- /dev/null
+++ b/tex/context/base/core-uti.mkiv
@@ -0,0 +1,103 @@
+%D \module
+%D [ file=core-uti,
+%D version=2006.09.19,
+%D title=\CONTEXT\ Core Macros,
+%D subtitle=Utility File Handling,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\unprotect
+
+\registerctxluafile{core-uti}{1.001}
+
+%D We need a way to pass strings safely to \LUA\ without the
+%D need for tricky escaping. Compare:
+%D
+%D \starttyping
+%D \ctxlua {something("anything tricky can go here")}
+%D \ctxlua {something([\luastringsep[anything tricky can go here]\luastringsep])}
+%D \stoptyping
+
+\def\luastringsep{===} % this permits \typefile{self} otherwise nested b/e sep problems
+
+\edef\!!bs{[\luastringsep[}
+\edef\!!es{]\luastringsep]}
+
+%D We have a the following available as primitive so there is no need
+%D for it:
+%D
+%D \starttyping
+%D \long\edef\luaescapestring#1{\!!bs#1\!!es}
+%D \stoptyping
+
+%D Next we implement a few helpers:
+
+\newwrite\utility@tua
+
+\prependtoks
+ \def \writeutilitytua {\write\utility@tua}
+ \def\immediatewriteutilitytua{\immediate\write\utility@tua}
+\to \everyjob
+
+\let \writeutilitytua\gobbleoneargument
+\let\immediatewriteutilitytua\gobbleoneargument
+
+\appendtoks
+ \immediate\openout\utility@tua=\jobname.tua
+ \immediatewriteutilitytua{-- file\space\space\space: \jobname}%
+ \immediatewriteutilitytua{-- format\space: \contextformat}%
+ \immediatewriteutilitytua{-- stamp\space\space: \contextversion}%
+ \immediatewriteutilitytua{-- escape\space: \!!bs\space...\space\!!es}%
+ \immediatewriteutilitytua{-- version: \utilityversion}%
+ \immediatewriteutilitytua{}%
+ \immediatewriteutilitytua{do}%
+ \immediatewriteutilitytua{if job and job.version and not job.version == "\utilityversion" then return end}%
+ \immediatewriteutilitytua{if not job then job = { } end}%
+ \immediatewriteutilitytua{job.version = "\utilityversion"}%
+\to \everyopenutilities
+
+\appendtoks
+ \immediatewriteutilitytua{end}%
+ %immediate\closeout\utility@tua
+\to \everycloseutilities
+
+% The next file can be in lua or luc format:
+
+\appendtoks
+ \ctxlua { do
+ if not job then job = { } end
+ job.version = "\utilityversion"
+ local settings = loadfile("\jobname.tuc")
+ if settings then settings() end
+ end}%
+\to \everyjob
+
+% variables
+
+\appendtoks
+ \immediatewriteutilitytua{if not job.variables then job.variables = { } end}%
+\to \everyopenutilities
+
+\def\savecurrentvalue#1#2%
+ {\immediatewriteutilitytua{job.initializevariable("\strippedcsname#1","#2")}}
+
+% temp
+
+\let\thisisbytesequence\gobbleoneargument
+
+% wrong place but we need to have it someplace
+
+\appendtoks
+ \ctxlua{input.storage.dump()}%
+\to \everydump
+
+\appendtoks
+ \ctxlua{input.storage.finalize()}%
+\to \everyfinalizeluacode
+
+\protect \endinput