Re: [NTG-context] callback.register

2010-04-09 Thread 李延瑞
2010/4/10 Wolfgang Werners-Lucchini :
>> there are two user hooks:
>>
>> tasks.appendaction("processors","before","modules.mine.whatever_a")
>> tasks.appendaction("processors","after","modules.mine.whatever_b")
>> -
>
> My example looks now
>
> \starttext
> \startluacode
> function MyPreLB(head,gc)
>  texio.write("\n")
>  for n in node.traverse(head) do
>    if node.type(n.id) == "glyph" then
>      texio.write(string.char(n.char))
>    elseif node.type(n.id) == "glue" then
>      texio.write(' ')
>    end
>  end
>  texio.write("\n")
>  return head
> end
> tasks.appendaction("processors","before","MyPreLB")
> \stopluacode
> Dies ist ein Test.
> \stoptext
>
> Is it correct to return 'head'?
>

Maybe 'return head, true', because I found a few functions in the beta
do so. Such as 'scripts.preprocess'.

-- 
Best regards,

Li Yanrui (李延瑞)
___
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] callback.register

2010-04-09 Thread Wolfgang Werners-Lucchini
> there are two user hooks:
> 
> tasks.appendaction("processors","before","modules.mine.whatever_a")
> tasks.appendaction("processors","after","modules.mine.whatever_b")
> -

My example looks now

\starttext
\startluacode
function MyPreLB(head,gc)
  texio.write("\n")
  for n in node.traverse(head) do
if node.type(n.id) == "glyph" then
  texio.write(string.char(n.char))
elseif node.type(n.id) == "glue" then
  texio.write(' ')
end
  end
  texio.write("\n")
  return head
end
tasks.appendaction("processors","before","MyPreLB")
\stopluacode
Dies ist ein Test.
\stoptext

Is it correct to return 'head'?

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] callback.register

2010-04-09 Thread Wolfgang Werners-Lucchini
> Hello,
> 
> Here a patch for luat-cbk.lua:
> 
> function callbacks.register(name,func,freeze)
> if frozen[name] then
> if trace_callbacks then
> frozenmessage("registering",name)
> end
> return nil, name .. " is frozen"
> elseif freeze then
> frozen[name] = (type(freeze) == "string" and freeze) or
> "registered"
> return register_callback(name,func)
> else
> return register_callback(name,func)
> end
> end
> 
> function callback.register(name,func) -- original
> if frozen[name] then
> if trace_callbacks then
> frozenmessage("registering",name)
> end
> return nil, name .. " is frozen"
> else
> return register_callback(name,func)
> end
> end
> 
> (Untested...)
> 
> Cheers, Peter

and

function callbacks.report()
local list = callback.list()
for name, func in table.sortedpairs(list) do
local str = frozen[name]
if str then
logs.report("callbacks","%s: %s -> 
%s",state(name),name,str)
else
logs.report("callbacks","%s: %s",state(name),name)
end
end
end

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] callback.register

2010-04-09 Thread Wolfgang Werners-Lucchini
> > I tried the following
> >
> > --
> > \starttext
> > \startluacode
> > local OldPreLB
> >
> > function MyPreLB(head,gc)
> > ?texio.write_nl("### Here I am!")
> > ?OldPreLB(head,gc)
> > end
> >
> > OldPreLB = callback.find('pre_linebreak_filter')
> > callback.register('pre_linebreak_filter',MyPreLB)
> > \stopluacode
> >
> > Test
> > \stoptext
> > --
> >
> > but MyPreLB() is not called.
> > What I am doing wrong here?
> 
> Hi Wolfgang,
> 
> see http://www.ntg.nl/pipermail/ntg-context/2010/047018.html
> 
> -- 
> Best regards,
> 
> Li Yanrui (???)

I see!

>From the info found there
-
there are two user hooks:

tasks.appendaction("processors","before","modules.mine.whatever_a")
tasks.appendaction("processors","after","modules.mine.whatever_b")
-
it is not clear for me how to use this.

So it seems that the luatex reference is useless for a context user.
Is there an other documentation on this?

I have found an other mechanism in 'luat-cbk.lua' which offers a pair 
of functions 'callbacks.push()' and 'callbacks.pop()'. But I have not 
made any attempts to use them. Are they useable or are they disabled 
too?

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] callback.register

2010-04-08 Thread 李延瑞
2010/4/9 Wolfgang Werners-Lucchini :
> Hallo,
>
> I tried the following
>
> --
> \starttext
> \startluacode
> local OldPreLB
>
> function MyPreLB(head,gc)
>  texio.write_nl("### Here I am!")
>  OldPreLB(head,gc)
> end
>
> OldPreLB = callback.find('pre_linebreak_filter')
> callback.register('pre_linebreak_filter',MyPreLB)
> \stopluacode
>
> Test
> \stoptext
> --
>
> but MyPreLB() is not called.
> What I am doing wrong here?

Hi Wolfgang,

see http://www.ntg.nl/pipermail/ntg-context/2010/047018.html

-- 
Best regards,

Li Yanrui (李延瑞)
___
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] callback.register

2010-04-08 Thread Peter Münster
On Thu, Apr 08 2010, Wolfgang Werners-Lucchini wrote:

> [...]
> 
> but MyPreLB() is not called.
> What I am doing wrong here?

Hello Wolfgang,

I don't know, but I've played a bit with your example file:

\starttext
\startluacode
local OldPreLB
function MyPreLB(head,gc)
  tex.print("Here I am!")
  return OldPreLB(head,gc)
end
local id, error = callback.register('pre_linebreak_filter', MyPreLB)
if id == nil then
   tex.print("Error string:", type(error), "\\par")
end
\stopluacode
Problem: callback.register returns nil, but no error message.
\stoptext

Cheers, Peter

-- 
Contact information: http://pmrb.free.fr/contact/


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