[NTG-context] why nil argument

Hans van der Meer H.vanderMeer at uva.nl
Sun Nov 14 18:55:20 CET 2010

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

The luatex code =
	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"

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

More information about the ntg-context mailing list