ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Aditya Mahajan <adityam@umich.edu>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Saving module data in tuc file
Date: Sat, 3 Dec 2011 19:20:47 -0500 (EST)	[thread overview]
Message-ID: <alpine.LNX.2.02.1112031857270.2243@ybpnyubfg.ybpnyqbznva> (raw)

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

             reply	other threads:[~2011-12-04  0:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-04  0:20 Aditya Mahajan [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LNX.2.02.1112031857270.2243@ybpnyubfg.ybpnyqbznva \
    --to=adityam@umich.edu \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).