[lltx] lualatex-math cannot find unpack function

Philipp Gesang Philipp.Gesang at alumni.uni-heidelberg.de
Mon Aug 5 23:01:13 CEST 2013


···<Datum: Monday, 05. August 2013>···<Von: Reinhard Kotucha>···

> On 2013-08-05 at 17:51:04 +0300, Wolfgang Jeltsch wrote:
> 
>  > Am Samstag, den 03.08.2013, 21:21 +0200 schrieb Philipp Gesang:
>  > > ···<date: 2013-08-03, Saturday>···<from: Wolfgang Jeltsch>···
>  > > > I think I have found the source of the problem. In Lua 5.1, unpack is a
>  > > > global function, while in Lua 5.2, it is a field of the global variable
>  > > > table. To ensure compatibility with both Lua versions, some Lua files
>  > > > (lualibs-basic-merged.lua, lualibs-lua.lua, and luaotfload-merged.lua)
>  > > > contain the following code:
>  > > > 
>  > > >     if not table.unpack then
>  > > >       table.unpack=_G.unpack
>  > > >     elseif not unpack then
>  > > >       _G.unpack=table.unpack
>  > > >     end
>  > > 
>  > > Packages shouldn’t write to _G.
>  > 
>  > I’m aware that this is an ugly hack, not only because _G is modified,
>  > but also because table is modified. I think it would be more appropriate
>  > to use a local variable unpack defined as follows:
>  > 
>  >     local unpack
>  >     if table.unpack then
>  >         unpack = table.unpack
>  >     else
>  >         unpack = _G.unpack
>  >     end
> 
> I don't think that it's wrong to provide table.unpack if it doesn't
> exist already.  LuaTeX already extends the string library similarly
> (string.explode).

In most documents the fallback is available through luaotfload or
lualibs since l-lua.lua establishes a compatibility layer [1]. In
any case, the *global* “unpack” should only be written to by
low-level packages (ideally by the format, else perhaps
luatexbase).

<... />
>   local unpack=table.unpack
> 
> but it's not necessary to do it globally.  You may want to create a
> local unpack within a function definition or a do-block.

That’s the preferred way, a local copy is faster anyways.

> I'm not sure whether it's necessary to support Lua 5.1 here since TeX
> Live 2012 is frozen.  Backwards compatibility makes only sense if
> there is a severe bug in TL-2012.

Aiming for full compatibility is impractical due to the changes
Lua 5.2 introduced on the syntactical level: newlines preceding
function parameters, the goto statement, and "\z". That aside,
compatibility with earlier versions of Luatex is of value when
testing for regressions. And don’t forget: CTAN still has 0.70.1
[2].

Best regards,
Philipp

[1] https://github.com/lualatex/lualibs/blob/master/lualibs-lua.lua#L87
[2] http://ctan.org/pkg/luatex

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://tug.org/pipermail/lualatex-dev/attachments/20130805/ab99fc06/attachment.bin>


More information about the lualatex-dev mailing list