ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Saving module data in tuc file
@ 2011-12-04  0:20 Aditya Mahajan
  2011-12-04  1:36 ` luigi scarso
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Aditya Mahajan @ 2011-12-04  0:20 UTC (permalink / raw)
  To: mailing list for ConTeXt users

[-- Attachment #1: Type: TEXT/PLAIN, Size: 537 bytes --]

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

[-- Attachment #2: Type: TEXT/PLAIN, Size: 1134 bytes --]

\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

[-- Attachment #3: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-12-04 20:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-04  0:20 Saving module data in tuc file Aditya Mahajan
2011-12-04  1:36 ` luigi scarso
2011-12-04  2:31   ` Aditya Mahajan
2011-12-04  9:36 ` Wolfgang Schuster
2011-12-04 10:59 ` Hans Hagen
2011-12-04 19:31   ` Aditya Mahajan
2011-12-04 20:40     ` Aditya Mahajan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).