Re: [NTG-context] Frozen callback.
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 ___
Re: [NTG-context] Frozen callback.
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 ___
Re: [NTG-context] Frozen callback.
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 ___
Re: [NTG-context] Frozen callback.
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 ___
Re: [NTG-context] Frozen callback.
Am 02.10.2012 um 13:41 schrieb Andre Caldas andre.em.cal...@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 ___
Re: [NTG-context] Frozen callback.
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 ___
Re: [NTG-context] Frozen callback.
···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 pgpBZAUsa1Tuq.pgp Description: PGP signature ___ 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 ___
Re: [NTG-context] Frozen callback.
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 ___
Re: [NTG-context] Frozen callback.
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 ___
[NTG-context] Frozen callback.
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 ___
Re: [NTG-context] Frozen callback.
···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 pgpnJNqVoFhHH.pgp Description: PGP signature ___ 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 ___
Re: [NTG-context] Frozen callback.
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 ___
Re: [NTG-context] Frozen callback.
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 ___