Hi,
How does one save and read third-party data in tuc file at the lua end?
I am trying to write a module t-ifchanged that defines a \doiffilechanged
macro that provides the functionality of mtxrun --ifchanged without
calling an external program (This is meant to be a support module for
t-vim, where the external calls to mtxrun are too time consuming).
I can successfully write additional data to the tuc file, but cannot
figure out how to initialize the data from tuc file. (See attached file).
Any hints are welcome.
Aditya
\startmodule[ifchanged]
\startluacode
local collected = {}
local tobesaved = {}
local function initializer()
-- this function is not called!
-- print("<><><><><>",collected)
collected = utilitydata.thirddata.ifchanged.collected
end
job.register('thirddata.ifchanged.collected', tobesaved, initializer)
local function cachedmd5sum(filename)
return collected[filename] or ""
end
function commands.doiffilechangedelse(filename)
local md5sum = md5.HEX(io.loaddata(filename) or "")
local cached = cachedmd5sum(filename)
tobesaved[filename] = md5sum
print(">>>>>>>>>>>>", md5sum)
print("============", cached)
commands.testcase(md5sum == cached)
end
\stopluacode
\def\doiffilechangedelse#1%
{\ctxcommand{doiffilechangedelse("#1")}}
\def\doiffilechanged#1%
{\doiffilechangedelse{#1}\firstofoneargument\gobbleoneargument}
\def\doiffilenotchanged#1%
{\doiffilechangedelse{#1}\gobbleoneargument\firstofoneargument}
\stopmodule
\starttext
\doiffilechanged{test.pdf}{\executesystemcommand{context test}}
\stoptext
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the
Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________