* Frozen callback. @ 2012-10-01 19:11 Andre Caldas 2012-10-01 20:02 ` Philipp Gesang 2012-10-01 20:49 ` Hans Hagen 0 siblings, 2 replies; 13+ messages in thread From: Andre Caldas @ 2012-10-01 19:11 UTC (permalink / raw) To: ConTeXt users Hello! I am trying to redefine the ’open_read_file’ callback. I am getting this error: callback ’open_read_file’ is frozen Why is it "frozen"? Can I "unfreeze it"? André Caldas. ___________________________________________________________________________________ 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] 13+ messages in thread
* Re: Frozen callback. 2012-10-01 19:11 Frozen callback Andre Caldas @ 2012-10-01 20:02 ` Philipp Gesang 2012-10-02 0:30 ` Andre Caldas 2012-10-01 20:49 ` Hans Hagen 1 sibling, 1 reply; 13+ messages in thread From: Philipp Gesang @ 2012-10-01 20:02 UTC (permalink / raw) To: mailing list for ConTeXt users [-- Attachment #1.1: Type: text/plain, Size: 1300 bytes --] ···<date: 2012-10-01, Monday>···<from: Andre Caldas>··· > I am trying to redefine the ’open_read_file’ callback. Hi André, direct callback access is disabled. There are usually some layers of abstraction on top of them, different ones for different callbacks. Mapping them all is a huge effort, so best refer to the source. In your case the function resolvers.openers.helpers.textopener() takes the place of the open_read_file callback. It can be found in data-tex.lua. Regards Philipp > > I am getting this error: > callback ’open_read_file’ is frozen > > Why is it "frozen"? Can I "unfreeze it"? > > > André Caldas. > ___________________________________________________________________________________ > 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 > ___________________________________________________________________________________ -- () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments [-- Attachment #1.2: Type: application/pgp-signature, Size: 198 bytes --] [-- Attachment #2: 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] 13+ messages in thread
* Re: Frozen callback. 2012-10-01 20:02 ` Philipp Gesang @ 2012-10-02 0:30 ` Andre Caldas 2012-10-02 8:05 ` Hans Hagen 0 siblings, 1 reply; 13+ messages in thread From: Andre Caldas @ 2012-10-02 0:30 UTC (permalink / raw) To: mailing list for ConTeXt users >> I am trying to redefine the ’open_read_file’ callback. > > [...] > direct callback access is disabled. There are usually some layers > of abstraction on top of them, different ones for different > callbacks. Mapping them all is a huge effort, so best refer to > the source. > > In your case the function resolvers.openers.helpers.textopener() > takes the place of the open_read_file callback. It can be found > in data-tex.lua. Shall I simply do something like this? local function textopener(tag, filename, filehandle, coding) result = old_textopener(tag, filename, filehandle, coding) -- Do lots of things return result end resolvers.openers.helpers.textopener = textopener Thank you, André Caldas. ___________________________________________________________________________________ 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] 13+ messages in thread
* Re: Frozen callback. 2012-10-02 0:30 ` Andre Caldas @ 2012-10-02 8:05 ` Hans Hagen 2012-10-02 11:31 ` Andre Caldas 2012-10-02 11:41 ` Andre Caldas 0 siblings, 2 replies; 13+ messages in thread From: Hans Hagen @ 2012-10-02 8:05 UTC (permalink / raw) To: mailing list for ConTeXt users On 2-10-2012 02:30, Andre Caldas wrote: >>> I am trying to redefine the ’open_read_file’ callback. >> >> [...] >> direct callback access is disabled. There are usually some layers >> of abstraction on top of them, different ones for different >> callbacks. Mapping them all is a huge effort, so best refer to >> the source. >> >> In your case the function resolvers.openers.helpers.textopener() >> takes the place of the open_read_file callback. It can be found >> in data-tex.lua. > > Shall I simply do something like this? > > local function textopener(tag, filename, filehandle, coding) > result = old_textopener(tag, filename, filehandle, coding) > -- Do lots of things > return result > end > > resolvers.openers.helpers.textopener = textopener this is not the recommended way .. better do somethign like this: \starttext \startluacode function document.MyCharacterMess(str,filename) if file.nameonly(filename) == "ward" then str = table.concat(string.totable(str,"."), " + ") end return str end local textfileactions = resolvers.openers.helpers.textfileactions utilities.sequencers.appendaction(textfileactions,"system","document.MyCharacterMess") \stopluacode \input ward \input knuth \stoptext ----------------------------------------------------------------- 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] 13+ messages in thread
* Re: Frozen callback. 2012-10-02 8:05 ` Hans Hagen @ 2012-10-02 11:31 ` Andre Caldas 2012-10-02 12:02 ` Sietse Brouwer 2012-10-02 12:13 ` Philipp Gesang 2012-10-02 11:41 ` Andre Caldas 1 sibling, 2 replies; 13+ messages in thread From: Andre Caldas @ 2012-10-02 11:31 UTC (permalink / raw) To: Hans Hagen; +Cc: mailing list for ConTeXt users Hello, Hans! >> Shall I simply do something like this? >> >> [...] > > this is not the recommended way .. better do somethign like this: > [...] > function document.MyCharacterMess(str,filename) Loved your function naming! :-) What is this "str"? > if file.nameonly(filename) == "ward" then > str = table.concat(string.totable(str,"."), " + ") What is this doing? > [...] > utilities.sequencers.appendaction(textfileactions, > "system","document.MyCharacterMess") Why is "document.MyCharacterMess" a string? Isn't it less error-prone to use the function itself, instead of its name? Sorry for my naive basic questions... :-) Cheers, André Caldas. ___________________________________________________________________________________ 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] 13+ messages in thread
* Re: Frozen callback. 2012-10-02 11:31 ` Andre Caldas @ 2012-10-02 12:02 ` Sietse Brouwer 2012-10-02 12:13 ` Philipp Gesang 1 sibling, 0 replies; 13+ messages in thread From: Sietse Brouwer @ 2012-10-02 12:02 UTC (permalink / raw) To: mailing list for ConTeXt users Hello, Andre! Andre Caldas wrote: >> function document.MyCharacterMess(str,filename) > > What is this "str"? This is a function that takes two variables; the first one it calls 'str', the second one 'filename'. Example: function f(a, b) return a/b end function(8,2) --> 4, not 0.25 I do not know what sort of str and filename are being passed to document.MyCharacterMess. (To all the action functions in utilities.sequencers.appendaction, in fact). >> if file.nameonly(filename) == "ward" then >> str = table.concat(string.totable(str,"."), " + ") > What is this doing? file.nameonly strips path and extenstion, e.g. file.nameonly('a/b/cod.doc') returns 'cod'. You can see the file.* functions in l-file.lua. string.totable splits a string, and returns the pieces as an array. In this case, the string is split at the periods. table.concat combines a table into a string, optionally putting a string (" + ", in this case) where the pieces join. so the `str = ...` line turns "Hello. I am Sam. You are also Sam." into "Hello + I am Sam + You are also Sam" or "hello.txt" into "hello + txt" > Why is "document.MyCharacterMess" a string? Isn't it less error-prone > to use the function itself, instead of its name? No idea. Cheers, and good luck, Sietse ___________________________________________________________________________________ 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] 13+ messages in thread
* Re: Frozen callback. 2012-10-02 11:31 ` Andre Caldas 2012-10-02 12:02 ` Sietse Brouwer @ 2012-10-02 12:13 ` Philipp Gesang 2012-10-02 12:37 ` Hans Hagen 1 sibling, 1 reply; 13+ messages in thread From: Philipp Gesang @ 2012-10-02 12:13 UTC (permalink / raw) To: mailing list for ConTeXt users [-- Attachment #1.1: Type: text/plain, Size: 1530 bytes --] ···<date: 2012-10-02, Tuesday>···<from: Andre Caldas>··· > > function document.MyCharacterMess(str,filename) > > What is this "str"? The raw file content as a Lua string. You can examine the arguments you get like so: ······································································· \startluacode document.arg_test = function (s, ...) table.print({...}, "file_content") return s end local textfileactions = resolvers.openers.helpers.textfileactions utilities.sequencers.appendaction(textfileactions,"system","document.arg_test") \stopluacode \starttext \input ward \input knuth \stoptext ······································································· > > if file.nameonly(filename) == "ward" then > > str = table.concat(string.totable(str,"."), " + ") > > What is this doing? Split the input at every byte and re-concatenate using "+" as delimiter. (It’s a bit confusing as string.totable() takes only one argument ;-) ) > > [...] > > utilities.sequencers.appendaction(textfileactions, > > "system","document.MyCharacterMess") > > Why is "document.MyCharacterMess" a string? The sequencers use loadstring() internally (util-seq.lua), so you need to supply the namespace as a string. This happens all over the place with action/callbacks. Regards Philipp [-- Attachment #1.2: Type: application/pgp-signature, Size: 198 bytes --] [-- Attachment #2: 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] 13+ messages in thread
* Re: Frozen callback. 2012-10-02 12:13 ` Philipp Gesang @ 2012-10-02 12:37 ` Hans Hagen 2012-10-10 19:40 ` Andre Caldas 0 siblings, 1 reply; 13+ messages in thread From: Hans Hagen @ 2012-10-02 12:37 UTC (permalink / raw) To: mailing list for ConTeXt users On 2-10-2012 14:13, Philipp Gesang wrote: >> Why is "document.MyCharacterMess" a string? > > The sequencers use loadstring() internally (util-seq.lua), so you > need to supply the namespace as a string. This happens all over > the place with action/callbacks. more flexible this way (one can redefine, nil or whatever such functions) ----------------------------------------------------------------- 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] 13+ messages in thread
* Re: Frozen callback. 2012-10-02 12:37 ` Hans Hagen @ 2012-10-10 19:40 ` Andre Caldas 0 siblings, 0 replies; 13+ messages in thread From: Andre Caldas @ 2012-10-10 19:40 UTC (permalink / raw) To: mailing list for ConTeXt users >>> Why is "document.MyCharacterMess" a string? >> >> The sequencers use loadstring() internally (util-seq.lua), so you >> need to supply the namespace as a string. This happens all over >> the place with action/callbacks. > > more flexible this way (one can redefine, nil or whatever such functions) It is like a "pointer to a pointer". Or a reference to a reference, since we do not use pointers in Lua. ___________________________________________________________________________________ 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] 13+ messages in thread
* Re: Frozen callback. 2012-10-02 8:05 ` Hans Hagen 2012-10-02 11:31 ` Andre Caldas @ 2012-10-02 11:41 ` Andre Caldas 2012-10-02 11:54 ` Wolfgang Schuster 2012-10-02 12:27 ` Hans Hagen 1 sibling, 2 replies; 13+ messages in thread From: Andre Caldas @ 2012-10-02 11:41 UTC (permalink / raw) To: Hans Hagen; +Cc: mailing list for ConTeXt users >>>> I am trying to redefine the ’open_read_file’ callback. > [...] > utilities.sequencers.appendaction(textfileactions, > "system","document.MyCharacterMess") All I want is to get the full path (or path relative to lfs.currentdir()). Is "textfileactions" the action I should trap? Also, shall I use "after" or "before" instead of "system"? Since it is a module, probably I should use "system", right? Just want to be sure... Thank you all! André Caldas. ___________________________________________________________________________________ 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] 13+ messages in thread
* Re: Frozen callback. 2012-10-02 11:41 ` Andre Caldas @ 2012-10-02 11:54 ` Wolfgang Schuster 2012-10-02 12:27 ` Hans Hagen 1 sibling, 0 replies; 13+ messages in thread From: Wolfgang Schuster @ 2012-10-02 11:54 UTC (permalink / raw) To: mailing list for ConTeXt users Am 02.10.2012 um 13:41 schrieb Andre Caldas <andre.em.caldas@gmail.com>: >>>>> I am trying to redefine the ’open_read_file’ callback. > >> [...] >> utilities.sequencers.appendaction(textfileactions, >> "system","document.MyCharacterMess") > > All I want is to get the full path (or path relative to > lfs.currentdir()). Is "textfileactions" the action I should trap? \starttext \startluacode function document.MyCharacterMess(str,filename) local path = "Path: " .. file.dirname(filename) local text = "Text: " .. str return table.concat({path,text},"\n\n") end local textfileactions = resolvers.openers.helpers.textfileactions utilities.sequencers.appendaction(textfileactions,"system","document.MyCharacterMess") \stopluacode \input ward \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] 13+ messages in thread
* Re: Frozen callback. 2012-10-02 11:41 ` Andre Caldas 2012-10-02 11:54 ` Wolfgang Schuster @ 2012-10-02 12:27 ` Hans Hagen 1 sibling, 0 replies; 13+ messages in thread From: Hans Hagen @ 2012-10-02 12:27 UTC (permalink / raw) To: Andre Caldas; +Cc: mailing list for ConTeXt users On 2-10-2012 13:41, Andre Caldas wrote: >>>>> I am trying to redefine the ’open_read_file’ callback. > >> [...] >> utilities.sequencers.appendaction(textfileactions, >> "system","document.MyCharacterMess") > > All I want is to get the full path (or path relative to > lfs.currentdir()). Is "textfileactions" the action I should trap? > > Also, shall I use "after" or "before" instead of "system"? Since it is > a module, probably I should use "system", right? Just want to be > sure... \startluacode resolvers.installinputfilehandler("before",function(str,filename,...) logs.report(string.format("path: %s",file.dirname(filename))) return str, filename, ... end) \stopluacode ----------------------------------------------------------------- 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] 13+ messages in thread
* Re: Frozen callback. 2012-10-01 19:11 Frozen callback Andre Caldas 2012-10-01 20:02 ` Philipp Gesang @ 2012-10-01 20:49 ` Hans Hagen 1 sibling, 0 replies; 13+ messages in thread From: Hans Hagen @ 2012-10-01 20:49 UTC (permalink / raw) To: mailing list for ConTeXt users On 1-10-2012 21:11, Andre Caldas wrote: > Hello! > > I am trying to redefine the ’open_read_file’ callback. > > I am getting this error: > callback ’open_read_file’ is frozen > > Why is it "frozen"? Can I "unfreeze it"? because it's the only way we can guarantee some features working well (but one can plug in additional code before/after the built-in filters) 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] 13+ messages in thread
end of thread, other threads:[~2012-10-10 19:40 UTC | newest] Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2012-10-01 19:11 Frozen callback Andre Caldas 2012-10-01 20:02 ` Philipp Gesang 2012-10-02 0:30 ` Andre Caldas 2012-10-02 8:05 ` Hans Hagen 2012-10-02 11:31 ` Andre Caldas 2012-10-02 12:02 ` Sietse Brouwer 2012-10-02 12:13 ` Philipp Gesang 2012-10-02 12:37 ` Hans Hagen 2012-10-10 19:40 ` Andre Caldas 2012-10-02 11:41 ` Andre Caldas 2012-10-02 11:54 ` Wolfgang Schuster 2012-10-02 12:27 ` Hans Hagen 2012-10-01 20:49 ` Hans Hagen
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).