ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* why nil argument
@ 2010-11-14 17:55 Hans van der Meer
  2010-11-14 19:27 ` Khaled Hosny
  0 siblings, 1 reply; 4+ messages in thread
From: Hans van der Meer @ 2010-11-14 17:55 UTC (permalink / raw)
  To: NTG ConTeXt

In transforming dates through a Lua-call I get a nil error I do not understand.

The luatex code =
\startluacode
	hvdm = hvdm or {}
	require "lpeg"
-- Transform date in Lua from yyyymmdd to dd-mm-yyyy with checks
	hvdm.day = lpeg.R("02") * lpeg.R("09") + lpeg.P("30") + lpeg.P("31") - lpeg.P("00")
	hvdm.month = lpeg.P("0") * lpeg.R("19") + lpeg.P("10") + lpeg.P("11") + lpeg.P("12")
	hvdm.year = lpeg.R("12") * lpeg.R("09") * lpeg.R("09") * lpeg.R("09")
	hvdm.date = lpeg.C(hvdm.year) * lpeg.C(hvdm.month) * lpeg.C(hvdm.day) * -1 / "%3-%2-%1"
\stopluacode
\def\FormatDate#1{\ctxlua{tex.print(tostring(hvdm.date:match(#1)))}}

Calling \FormatDate(1) is OK although it returns "nil" (correct would be #1 = 20101114
Calling \FormatDate(A) is  not OK with the error:
! LuaTeX error <main ctx instance>:1: bad argument #1 to 'match' (string expected, got nil)
stack traceback:
	[C]: in function 'match'
	<main ctx instance>:1: in main chunk.

It is no problem if the function returns the string "nil" from tostring() but an error like this I would like to avoid.

Hans van der Meer



___________________________________________________________________________________
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] 4+ messages in thread

* Re: why nil argument
  2010-11-14 17:55 why nil argument Hans van der Meer
@ 2010-11-14 19:27 ` Khaled Hosny
  2010-11-14 19:47   ` Hans van der Meer
  0 siblings, 1 reply; 4+ messages in thread
From: Khaled Hosny @ 2010-11-14 19:27 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Sun, Nov 14, 2010 at 06:55:20PM +0100, Hans van der Meer wrote:
> In transforming dates through a Lua-call I get a nil error I do not understand.
> 
> The luatex code =
> \startluacode
> 	hvdm = hvdm or {}
> 	require "lpeg"
> -- Transform date in Lua from yyyymmdd to dd-mm-yyyy with checks
> 	hvdm.day = lpeg.R("02") * lpeg.R("09") + lpeg.P("30") + lpeg.P("31") - lpeg.P("00")
> 	hvdm.month = lpeg.P("0") * lpeg.R("19") + lpeg.P("10") + lpeg.P("11") + lpeg.P("12")
> 	hvdm.year = lpeg.R("12") * lpeg.R("09") * lpeg.R("09") * lpeg.R("09")
> 	hvdm.date = lpeg.C(hvdm.year) * lpeg.C(hvdm.month) * lpeg.C(hvdm.day) * -1 / "%3-%2-%1"
> \stopluacode
> \def\FormatDate#1{\ctxlua{tex.print(tostring(hvdm.date:match(#1)))}}
> 
> Calling \FormatDate(1) is OK although it returns "nil" (correct would be #1 = 20101114
> Calling \FormatDate(A) is  not OK with the error:

You are passing a undefined variable, A. Your argument should be quoted:

	hvdm.date:match("#1")

Regards,
 Khaled

-- 
 Khaled Hosny
 Arabic localiser and member of Arabeyes.org team
 Free font developer
___________________________________________________________________________________
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] 4+ messages in thread

* Re: why nil argument
  2010-11-14 19:27 ` Khaled Hosny
@ 2010-11-14 19:47   ` Hans van der Meer
  2010-11-14 19:53     ` Khaled Hosny
  0 siblings, 1 reply; 4+ messages in thread
From: Hans van der Meer @ 2010-11-14 19:47 UTC (permalink / raw)
  To: mailing list for ConTeXt users


On 14 nov 2010, at 20:27, Khaled Hosny wrote:

> On Sun, Nov 14, 2010 at 06:55:20PM +0100, Hans van der Meer wrote:
>> In transforming dates through a Lua-call I get a nil error I do not understand.
>> 
>> The luatex code =
>> \startluacode
>> 	hvdm = hvdm or {}
>> 	require "lpeg"
>> -- Transform date in Lua from yyyymmdd to dd-mm-yyyy with checks
>> 	hvdm.day = lpeg.R("02") * lpeg.R("09") + lpeg.P("30") + lpeg.P("31") - lpeg.P("00")
>> 	hvdm.month = lpeg.P("0") * lpeg.R("19") + lpeg.P("10") + lpeg.P("11") + lpeg.P("12")
>> 	hvdm.year = lpeg.R("12") * lpeg.R("09") * lpeg.R("09") * lpeg.R("09")
>> 	hvdm.date = lpeg.C(hvdm.year) * lpeg.C(hvdm.month) * lpeg.C(hvdm.day) * -1 / "%3-%2-%1"
>> \stopluacode
>> \def\FormatDate#1{\ctxlua{tex.print(tostring(hvdm.date:match(#1)))}}
>> 
>> Calling \FormatDate(1) is OK although it returns "nil" (correct would be #1 = 20101114
>> Calling \FormatDate(A) is  not OK with the error:
> 
> You are passing a undefined variable, A. Your argument should be quoted:
> 
> 	hvdm.date:match("#1")
> 

I would think that is not the case. 
For one, because then calling with argument 1 would fail in the same manner as argument A does; which does not happen.
Secondly, the call originates from
  \startxmlsetups xml:case:burned
    \xmldoifelsetext{#1}{}{\FormatDate{\xmlflush{#1}}}{\currentdate}
  \stopxmlsetups
This does makes it a string already.
Something else must happen here, I guess.

Hans van der Meer


___________________________________________________________________________________
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] 4+ messages in thread

* Re: why nil argument
  2010-11-14 19:47   ` Hans van der Meer
@ 2010-11-14 19:53     ` Khaled Hosny
  0 siblings, 0 replies; 4+ messages in thread
From: Khaled Hosny @ 2010-11-14 19:53 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Sun, Nov 14, 2010 at 08:47:30PM +0100, Hans van der Meer wrote:
> 
> On 14 nov 2010, at 20:27, Khaled Hosny wrote:
> 
> > On Sun, Nov 14, 2010 at 06:55:20PM +0100, Hans van der Meer wrote:
> >> In transforming dates through a Lua-call I get a nil error I do not understand.
> >> 
> >> The luatex code =
> >> \startluacode
> >> 	hvdm = hvdm or {}
> >> 	require "lpeg"
> >> -- Transform date in Lua from yyyymmdd to dd-mm-yyyy with checks
> >> 	hvdm.day = lpeg.R("02") * lpeg.R("09") + lpeg.P("30") + lpeg.P("31") - lpeg.P("00")
> >> 	hvdm.month = lpeg.P("0") * lpeg.R("19") + lpeg.P("10") + lpeg.P("11") + lpeg.P("12")
> >> 	hvdm.year = lpeg.R("12") * lpeg.R("09") * lpeg.R("09") * lpeg.R("09")
> >> 	hvdm.date = lpeg.C(hvdm.year) * lpeg.C(hvdm.month) * lpeg.C(hvdm.day) * -1 / "%3-%2-%1"
> >> \stopluacode
> >> \def\FormatDate#1{\ctxlua{tex.print(tostring(hvdm.date:match(#1)))}}
> >> 
> >> Calling \FormatDate(1) is OK although it returns "nil" (correct would be #1 = 20101114
> >> Calling \FormatDate(A) is  not OK with the error:
> > 
> > You are passing a undefined variable, A. Your argument should be quoted:
> > 
> > 	hvdm.date:match("#1")
> > 
> 
> I would think that is not the case. 
> For one, because then calling with argument 1 would fail in the same manner as argument A does; which does not happen.

No, match(1) will match an integer 1, match("1") matches a string "1",
while match(A) will match a variable A which is not what you are after,
while match("A") will match a string "A".

> Secondly, the call originates from
>   \startxmlsetups xml:case:burned
>     \xmldoifelsetext{#1}{}{\FormatDate{\xmlflush{#1}}}{\currentdate}
>   \stopxmlsetups
> This does makes it a string already.

TeX is not lua, the concepts are completely and totally different.

> Something else must happen here, I guess.

No, there isn't.

Regards,
 Khaled

-- 
 Khaled Hosny
 Arabic localiser and member of Arabeyes.org team
 Free font developer
___________________________________________________________________________________
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] 4+ messages in thread

end of thread, other threads:[~2010-11-14 19:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-14 17:55 why nil argument Hans van der Meer
2010-11-14 19:27 ` Khaled Hosny
2010-11-14 19:47   ` Hans van der Meer
2010-11-14 19:53     ` Khaled Hosny

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