[luatex] print versus tex.print

Reinhard Kotucha reinhard.kotucha at web.de
Mon Jan 23 22:10:14 CET 2012


On 2012-01-23 at 17:32:37 +0100, Paul Isambert wrote:

 > Herbert Voss <Herbert.Voss at fu-berlin.de> a écrit:
 > > 
 > > Am 23.01.2012 15:47, schrieb Paul Isambert:
 > > 
 > > >> \directlua{table.foreach(os.date("!*t"),function(...)
 > > >> tex.print(tostring(...) end)}
 > > >> \bye
 > > >
 > > > Or use a test like "type(<arg>) == 'boolean'". Note that table.foreach
 > > 
 > > I alread had tostring() but I thought there might be
 > > an easier solution.
 > > 
 > > > is deprecated in Lua 5.1 and should be removed from 5.2 (see:
 > > > http://lua-users.org/lists/lua-l/2010-11/msg00661.html). And LuaTeX
 > > 
 > > oh, I like that ... :-(
 > 
 > You can easily fake it:
 > 
 > table.foreach = table.foreach or
 >   function (t, f)
 >     for k, v in pairs(t) do
 >       local ret = f(k, v)
 >       if ret then return ret end
 >     end
 >   end
 > 
 > table.foreachi = table.foreach or
 >   function (t, f)
 >     for k, v in ipairs(t) do
 >       local ret = f(k, v)
 >       if ret then return ret end
 >     end
 >   end

AFAIK, ipairs() is deprecated in Lua 5.2 too.  But maybe something like

  for k=1, #t do

is even a little bit faster, though f(k, v) looks nicer than f(k, t[k]).

Regards,
  Reinhard

-- 
----------------------------------------------------------------------------
Reinhard Kotucha                                      Phone: +49-511-3373112
Marschnerstr. 25
D-30167 Hannover                              mailto:reinhard.kotucha at web.de
----------------------------------------------------------------------------
Microsoft isn't the answer. Microsoft is the question, and the answer is NO.
----------------------------------------------------------------------------



More information about the luatex mailing list