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

* Re: Saving module data in tuc file
  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
  2 siblings, 1 reply; 7+ messages in thread
From: luigi scarso @ 2011-12-04  1:36 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Sun, Dec 4, 2011 at 1:20 AM, Aditya Mahajan <adityam@umich.edu> wrote:
> Hi,
>
> How does one save and read third-party data in tuc file at the lua end?
You can read the data with loadfile or dofile:
utilitydata=dofile('test.tuc')
and then you have the table stored into utilitydata
See for the difference with loadfile
http://www.lua.org/pil/8.html

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

* Re: Saving module data in tuc file
  2011-12-04  1:36 ` luigi scarso
@ 2011-12-04  2:31   ` Aditya Mahajan
  0 siblings, 0 replies; 7+ messages in thread
From: Aditya Mahajan @ 2011-12-04  2:31 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Sun, 4 Dec 2011, luigi scarso wrote:

> On Sun, Dec 4, 2011 at 1:20 AM, Aditya Mahajan <adityam@umich.edu> wrote:
>> Hi,
>>
>> How does one save and read third-party data in tuc file at the lua end?
> You can read the data with loadfile or dofile:
> utilitydata=dofile('test.tuc')

But doesn't ConTeXt already read the tuc file at \starttext? I don't want 
to load the file again.

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

* Re: Saving module data in tuc file
  2011-12-04  0:20 Saving module data in tuc file Aditya Mahajan
  2011-12-04  1:36 ` luigi scarso
@ 2011-12-04  9:36 ` Wolfgang Schuster
  2011-12-04 10:59 ` Hans Hagen
  2 siblings, 0 replies; 7+ messages in thread
From: Wolfgang Schuster @ 2011-12-04  9:36 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 04.12.2011 um 01:20 schrieb Aditya Mahajan:

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

\definetwopasslist{test}

\newcount\testcount

\starttext

\immediatesavetwopassdata{test}{}{First Entry}

One: \gettwopassdata{test}\twopassdata

\startluacode
commands.savetwopassdata("test","Second Entry")
\stopluacode

Two: \ctxlua{commands.gettwopassdata("test")}

\stoptext

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

* Re: Saving module data in tuc file
  2011-12-04  0:20 Saving module data in tuc file Aditya Mahajan
  2011-12-04  1:36 ` luigi scarso
  2011-12-04  9:36 ` Wolfgang Schuster
@ 2011-12-04 10:59 ` Hans Hagen
  2011-12-04 19:31   ` Aditya Mahajan
  2 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen @ 2011-12-04 10:59 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 4-12-2011 01:20, Aditya Mahajan wrote:
> 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).

This is why we have a mechanism built in (used for graphics).

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

There is:

jobfiles.run("yourfile.xxx","vim --something yourfile.xxx")

I'll adapt this to accept a function as second argument.

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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

* Re: Saving module data in tuc file
  2011-12-04 10:59 ` Hans Hagen
@ 2011-12-04 19:31   ` Aditya Mahajan
  2011-12-04 20:40     ` Aditya Mahajan
  0 siblings, 1 reply; 7+ messages in thread
From: Aditya Mahajan @ 2011-12-04 19:31 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Sun, 4 Dec 2011, Hans Hagen wrote:

> On 4-12-2011 01:20, Aditya Mahajan wrote:
>> 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).
>
> This is why we have a mechanism built in (used for graphics).

Ah, I didn't know that.

>> 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.
>
> There is:
>
> jobfiles.run("yourfile.xxx","vim --something yourfile.xxx")

This works in a standalone file, but not the way I am calling the 
function.


\def\executeCommand
     {\doifmode{*first}
         {\ctxlua{job.files.run(\!!bs\externalfiter::input_file\!!es,
                                \!!bs\externalfiltercommand\!!es)}}}


The solution is to remove the test for the first mode. Needs a bit of 
refactoring to ensure that the solution still works for MkII. (Does anyone 
use the filter module with MkII?)

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

* Re: Saving module data in tuc file
  2011-12-04 19:31   ` Aditya Mahajan
@ 2011-12-04 20:40     ` Aditya Mahajan
  0 siblings, 0 replies; 7+ messages in thread
From: Aditya Mahajan @ 2011-12-04 20:40 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Sun, 4 Dec 2011, Aditya Mahajan wrote:

> \def\executeCommand
>    {\doifmode{*first}
>        {\ctxlua{job.files.run(\!!bs\externalfiter::input_file\!!es,
>                               \!!bs\externalfiltercommand\!!es)}}}
>
>
> The solution is to remove the test for the first mode. Needs a bit of 
> refactoring to ensure that the solution still works for MkII. (Does anyone 
> use the filter module with MkII?)

The new version of the filter module uses job.files.run in the background 
(when continue=yes is set) instead of mtxrun --ifchanged. This should 
considerably speed up the vim module when using a lot of code snippets.

Aditya
___________________________________________________________________________________
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).