On Tue, Mar 30 2010, Hans van der Meer wrote:

> called through:
>       \def\callf#1#2{\ctxlua{f("#1","#2")}}
>
> and do this actually with one argument:
>       \callf{one}
>
> then I find that the absent argument b in f(a,b) is not nil but a string of 
> length 1.

Hello Hans,

You want probably something like this:

\startluacode
userdata = userdata or {}
function userdata.f(a, b)
        b = b or "default value"
        tex.print(string.format("a = '%s' and b = '%s'\\par", a, b))
end
\stopluacode
\def\callf{\dodoubleempty\docallf}
\def\docallf[#1][#2]{\ctxlua{userdata.f("#1"\ifsecondargument, "#2"\fi)}}
\starttext
\callf[one]
\callf[one][two]
\callf[one][]
\callf[][]
\callf[][two]
\callf[]
\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
___________________________________________________________________________________

Reply via email to