OSDN Git Service

Babel 3.44 inserts \textdir
[luatex-ja/luatexja.git] / src / luatexja.lua
1
2 require('lualibs')
3
4 ------------------------------------------------------------------------
5 local function load_lua(fn)
6    local found = kpse.find_file(fn, 'tex')
7    if not found then
8       tex.error("LuaTeX-ja error: File `" .. fn .. "' not found")
9    else
10       texio.write_nl('(' .. found .. ')')
11       dofile(found)
12    end
13 end
14 luatexja.load_lua = load_lua
15 function luatexja.load_module(name)
16    require('ltj-' .. name.. '.lua')
17 end
18
19 do
20     local setfield = node.direct.setfield
21     luatexja.setglue = node.direct.setglue or
22     function(g,w,st,sh,sto,sho)
23         setfield(g,'width', w or 0)
24         setfield(g,'stretch',st or 0)
25         setfield(g,'shrink', sh or 0)
26         setfield(g,'stretch_order',sto or 0)
27         setfield(g,'shrink_order', sho or 0)
28     end
29     local getfield = node.direct.getfield
30     luatexja.getglue = node.direct.getglue or
31     function(g)
32         return getfield(g,'width'),
33                getfield(g,'stretch'),
34                getfield(g,'shrink'),
35                getfield(g,'stretch_order'),
36                getfield(g,'shrink_order')
37     end
38 end
39
40 --- 以下は全ファイルで共有される定数
41 local icflag_table = {}
42 luatexja.icflag_table = icflag_table
43 icflag_table.ITALIC          = 1
44 icflag_table.PACKED          = 2
45 icflag_table.KINSOKU         = 3
46 icflag_table.FROM_JFM        = 4
47 -- FROM_JFM: 4, 5, 6, 7, 8 →優先度高(伸びやすく,縮みやすい)
48 -- 6 が標準
49 icflag_table.KANJI_SKIP      = 68 -- = 4+64
50 icflag_table.KANJI_SKIP_JFM  = 69
51 icflag_table.XKANJI_SKIP     = 70
52 icflag_table.XKANJI_SKIP_JFM = 71
53 icflag_table.LINEEND         = 72
54 icflag_table.PROCESSED       = 73
55 icflag_table.IC_PROCESSED    = 74
56 icflag_table.BOXBDD          = 75
57 icflag_table.PROCESSED_BEGIN_FLAG = 4096 -- sufficiently large power of 2
58
59 local stack_table_index = {}
60 luatexja.stack_table_index = stack_table_index
61 stack_table_index.PRE  = 0x200000 -- characterごと
62 stack_table_index.POST = 0x400000 -- characterごと
63 stack_table_index.KCAT = 0x600000 -- characterごと
64 stack_table_index.XSP  = 0x800000 -- characterごと
65 stack_table_index.RIPRE  = 0xA00000 -- characterごと,ruby pre
66 stack_table_index.RIPOST = 0xC00000 -- characterごと,ruby post
67 stack_table_index.JWP  = 0 -- これだけ
68 stack_table_index.KSK  = 1 -- これだけ
69 stack_table_index.XSK  = 2 -- これだけ
70 stack_table_index.MJT  = 0x100 -- 0--255
71 stack_table_index.MJS  = 0x200 -- 0--255
72 stack_table_index.MJSS = 0x300 -- 0--255
73 stack_table_index.KSJ  = 0x400 -- 0--9
74
75 local userid_table = {}
76 luatexja.userid_table = userid_table
77 userid_table.IHB  = luatexbase.newuserwhatsitid('inhibitglue',  'luatexja') -- \inhibitglue
78 userid_table.STCK = luatexbase.newuserwhatsitid('stack_marker', 'luatexja') -- スタック管理
79 userid_table.BPAR = luatexbase.newuserwhatsitid('begin_par',    'luatexja') -- 「段落始め」
80 userid_table.DIR  = luatexbase.newuserwhatsitid('direction',    'luatexja') -- 組方向
81 userid_table.BOXB = luatexbase.newuserwhatsitid('box_boundary', 'luatexja') -- 「ボックス始め・終わり」
82 userid_table.JA_AL_BDD = luatexbase.newuserwhatsitid('ja_al_boundary', 'luatexja')
83
84 local dir_table = {}
85 luatexja.dir_table = dir_table
86 dir_table.dir_dtou = 1
87 dir_table.dir_tate = 3
88 dir_table.dir_yoko = 4
89 dir_table.dir_math_mod    = 8
90 dir_table.dir_node_auto   = 128 -- 組方向を合わせるために自動で作られたもの
91 dir_table.dir_node_manual = 256 -- 寸法代入によって作られたもの
92 dir_table.dir_utod = dir_table.dir_tate + dir_table.dir_math_mod
93    -- 「縦数式ディレクション」 in pTeX
94 --- 定義終わり
95
96 local load_module = luatexja.load_module
97 load_module('base');      local ltjb = luatexja.base
98 load_module('rmlgbm');    local ltjr = luatexja.rmlgbm -- must be 1st
99
100 if luatexja_debug then load_module('debug') end
101
102 load_module('lotf_aux');  local ltju = luatexja.lotf_aux
103 load_module('charrange'); local ltjc = luatexja.charrange
104 load_module('stack');     local ltjs = luatexja.stack
105 load_module('direction'); local ltjd = luatexja.direction -- +1 hlist +1 attr_list
106 load_module('lineskip');  local ltjl = luatexja.lineskip -- +1 hlist +1 attr_list
107 load_module('jfont');     local ltjf = luatexja.jfont
108 load_module('inputbuf');  local ltji = luatexja.inputbuf
109 load_module('pretreat');  local ltjp = luatexja.pretreat
110 load_module('setwidth');  local ltjw = luatexja.setwidth
111 load_module('jfmglue');   local ltjj = luatexja.jfmglue -- +1 glue +1 gs +1 attr_list
112 load_module('math');      local ltjm = luatexja.math
113 load_module('base');      local ltjb = luatexja.base
114
115
116 local attr_jchar_class = luatexbase.attributes['ltj@charclass']
117 local attr_jchar_code = luatexbase.attributes['ltj@charcode']
118 local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
119 local attr_yablshift = luatexbase.attributes['ltj@yablshift']
120 local attr_icflag = luatexbase.attributes['ltj@icflag']
121 local attr_uniqid = luatexbase.attributes['ltj@uniqid']
122 local attr_dir = luatexbase.attributes['ltj@dir']
123 local cat_lp = luatexbase.catcodetables['latex-package']
124
125 -- Three aux. functions, bollowed from tex.web
126
127 local unity=65536
128 local floor = math.floor
129
130 local function print_scaled(s)
131    local out=''
132    local delta=10
133    if s<0 then
134       out=out..'-'; s=-s
135    end
136    out=out..tostring(floor(s/unity)) .. '.'
137    s=10*(s%unity)+5
138    repeat
139       if delta>unity then s=s+32768-50000 end
140       out=out .. tostring(floor(s/unity))
141       s=10*(s%unity)
142       delta=delta*10
143    until s<=delta
144    return out
145 end
146 luatexja.print_scaled = print_scaled
147
148 local function print_glue(d,order)
149    local out=print_scaled(d)
150    if order>0 then
151       out=out..'fi'
152       while order>1 do
153          out=out..'l'; order=order-1
154       end
155    else
156       out=out..'pt'
157    end
158    return out
159 end
160
161 local function print_spec(p)
162    local out=print_scaled(p.width)..'pt'
163    if p.stretch~=0 then
164       out=out..' plus '..print_glue(p.stretch,p.stretch_order)
165    end
166    if p.shrink~=0 then
167       out=out..' minus '..print_glue(p.shrink,p.shrink_order)
168    end
169 return out
170 end
171
172
173 ------------------------------------------------------------------------
174 -- CODE FOR GETTING/SETTING PARAMETERS
175 ------------------------------------------------------------------------
176
177 -- EXT: print parameters that don't need arguments
178 do
179    local tex_getattr = tex.getattribute
180    local function getattr(a)
181       local r = tex.getattribute(a)
182       return (r==-0x7FFFFFFF) and 0 or r
183    end 
184    luatexja.unary_pars = {
185       yalbaselineshift = function(t)
186          return print_scaled(getattr('ltj@yablshift'))..'pt'
187       end,
188       yjabaselineshift = function(t)
189          return print_scaled(getattr('ltj@ykblshift'))..'pt'
190       end,
191       talbaselineshift = function(t)
192          return print_scaled(getattr('ltj@tablshift'))..'pt'
193       end,
194       tjabaselineshift = function(t)
195          return print_scaled(getattr('ltj@tkblshift'))..'pt'
196       end,
197       kanjiskip = function(t)
198          return print_spec(ltjs.get_stack_skip(stack_table_index.KSK, t))
199       end,
200       xkanjiskip = function(t)
201          return print_spec(ltjs.get_stack_skip(stack_table_index.XSK, t))
202       end,
203       jcharwidowpenalty = function(t)
204          return ltjs.get_stack_table(stack_table_index.JWP, 0, t)
205       end,
206       autospacing = function(t)
207          return getattr('ltj@autospc')
208       end,
209       autoxspacing = function(t)
210          return getattr('ltj@autoxspc')
211       end,
212       differentjfm = function(t)
213          local f, r = luatexja.jfmglue.diffmet_rule, '???'
214          if f == math.max then r = 'large'
215          elseif f == math.min then r = 'small'
216          elseif f == math.two_average then r = 'average'
217          elseif f == math.two_paverage then r = 'paverage'
218          elseif f == math.two_pleft then r = 'pleft'
219          elseif f == math.two_pright then r = 'pright'
220          elseif f == math.two_add then r = 'both'
221          end
222          return r
223       end,
224       direction = function()
225          local v = ltjd.get_dir_count()
226          if math.abs(tex.nest[tex.nest.ptr].mode) == ltjs.mmode and v == dir_table.dir_tate then
227             v = dir_table.dir_utod
228          end
229          return v
230       end,
231       adjustdir = ltjd.get_adjust_dir_count,
232    }
233
234    local unary_pars = luatexja.unary_pars
235    local scan_arg = token.scan_argument
236    function luatexja.ext_get_parameter_unary()
237       local k= scan_arg()
238       if unary_pars[k] then
239          tex.write(tostring(unary_pars[k](tex.getcount('ltj@@stack'))))
240       end
241       ltjb.stop_time_measure('get_par')
242    end
243 end
244
245
246 -- EXT: print parameters that need arguments
247 do
248    luatexja.binary_pars = {
249       jacharrange = function(c, t)
250          if type(c)~='number' or c<-1 or c>31*ltjc.ATTR_RANGE then
251             -- 0, -1 はエラーにしない(隠し)
252             ltjb.package_error('luatexja',
253                                'invalid character range number (' .. tostring(c) .. ')',
254                                'A character range number should be in the range 1..'
255                                   .. 31*ltjc.ATTR_RANGE .. ",\n"..
256                                   'So I changed this one to ' .. 31*ltjc.ATTR_RANGE .. ".")
257             c=0 -- external range 217 == internal range 0
258          elseif c==31*ltjc.ATTR_RANGE then c=0
259          end
260       -- 負の値は <U+0080 の文字の文字範囲,として出てくる.この時はいつも欧文文字なので 1 を返す
261          return (c<0) and 1 or ltjc.get_range_setting(c)
262       end,
263       prebreakpenalty = function(c, t)
264          return ltjs.get_stack_table(stack_table_index.PRE
265                                           + ltjb.in_unicode(c, true), 0, t)
266       end,
267       postbreakpenalty = function(c, t)
268          return ltjs.get_stack_table(stack_table_index.POST
269                                           + ltjb.in_unicode(c, true), 0, t)
270       end,
271       kcatcode = function(c, t)
272          return ltjs.get_stack_table(stack_table_index.KCAT
273                                           + ltjb.in_unicode(c, false), 0, t)
274       end,
275       chartorange = function(c, t)
276          return ltjc.char_to_range(ltjb.in_unicode(c, false))
277       end,
278       jaxspmode = function(c, t)
279          return ltjs.get_stack_table(stack_table_index.XSP
280                                           + ltjb.in_unicode(c, true), 3, t)
281       end,
282       boxdir = function(c, t)
283          if type(c)~='number' or c<0 or c>65535 then
284             ltjb.package_error('luatexja',
285                                'Bad register code (' .. tostring(c) .. ')',
286                                'A register must be between 0 and 65535.\n'..
287                                   'I changed this one to zero.')
288             c=0
289          end
290          return ltjd.get_register_dir(c)
291       end,
292    }
293    local binary_pars = luatexja.binary_pars
294    local scan_arg, scan_int = token.scan_argument, token.scan_int
295    binary_pars.alxspmode = binary_pars.jaxspmode
296    function luatexja.ext_get_parameter_binary(k, c)
297       if binary_pars[k] then
298          tex.write(tostring(binary_pars[k](c,tex.getcount('ltj@@stack'))))
299       end
300       ltjb.stop_time_measure('get_par')
301    end
302 end
303
304 -- EXT: print \global if necessary
305 function luatexja.ext_print_global()
306    if luatexja.isglobal=='global' then tex.sprint(cat_lp, '\\global') end
307 end
308
309
310 -- main process
311 do
312    local start_time_measure, stop_time_measure
313       = ltjb.start_time_measure, ltjb.stop_time_measure
314    local nullfunc = function (n) return n end
315    local to_node = node.direct.tonode
316    local to_direct = node.direct.todirect
317    local ensure_tex_attr = ltjb.ensure_tex_attr
318
319    -- mode = true iff main_process is called from pre_linebreak_filter
320    local function main_process(head, mode, dir, gc)
321       ensure_tex_attr(attr_icflag, 0)
322       if gc == 'fin_row' then return head
323       else
324             --luatexja.ext_show_node_list(head, 'T> ', print)
325             start_time_measure('jfmglue')
326             local p = ltjj.main(to_direct(head),mode, dir)
327             stop_time_measure('jfmglue')
328             return to_node(p)
329       end
330    end
331
332    local function adjust_icflag(h)
333       -- kern from luaotfload will have icflag = 1
334       -- (same as italic correction)
335       ensure_tex_attr(attr_icflag, 1)
336       return h
337    end
338
339    -- callbacks
340    ltjb.add_to_callback(
341       'pre_linebreak_filter',
342       function (head,groupcode)
343          return main_process(head, true, tex.textdir, groupcode)
344       end,'ltj.main',
345       luatexbase.priority_in_callback('pre_linebreak_filter', 'luaotfload.node_processor')+1)
346    ltjb.add_to_callback(
347       'hpack_filter',
348       function (head,groupcode,size,packtype, dir)
349          return main_process(head, false, dir, groupcode)
350       end,'ltj.main',
351       luatexbase.priority_in_callback('hpack_filter', 'luaotfload.node_processor')+1)
352    ltjb.add_to_callback('pre_linebreak_filter', adjust_icflag, 'ltj.adjust_icflag', 1)
353    ltjb.add_to_callback('hpack_filter', adjust_icflag, 'ltj.adjust_icflag', 1)
354
355 end
356
357 -- cleanup process
358 function luatexja.ext_cleanup()
359    ltjf.cleanup_size_cache()
360    ltjd.remove_end_whatsit()
361 end
362
363
364 -- lastnodechar
365 do
366    local id_glyph = node.id('glyph')
367    function luatexja.pltx_composite_last_node_char()
368       local n = tex.nest[tex.nest.ptr].tail
369       local r = '-1'
370       if n then
371          if n.id==id_glyph then
372             while n.componetns and  n.subtype and n.subtype%4 >= 2 do
373                n = node.tail(n)
374             end
375             r = tostring(n.char)
376          end
377       end
378       tex.sprint(r)
379    end
380 end
381
382 -- debug
383
384 do
385
386 local node_type = node.type
387 local node_next = node.next
388 local has_attr = node.has_attribute
389
390 local id_penalty = node.id('penalty')
391 local id_glyph = node.id('glyph')
392 local id_glue = node.id('glue')
393 local id_kern = node.id('kern')
394 local id_hlist = node.id('hlist')
395 local id_vlist = node.id('vlist')
396 local id_rule = node.id('rule')
397 local id_math = node.id('math')
398 local id_whatsit = node.id('whatsit')
399 local sid_user = node.subtype('user_defined')
400
401 local function get_attr_icflag(p)
402    return (has_attr(p, attr_icflag) or 0) % icflag_table.PROCESSED_BEGIN_FLAG
403 end
404
405 local prefix, inner_depth
406 local utfchar = utf.char
407 local function debug_show_node_X(p,print_fn, limit, inner_depth)
408    local k = prefix
409    local s
410    local pt=node_type(p.id)
411    local base = prefix .. string.format('%X', get_attr_icflag(p))
412    .. ' ' .. pt .. ' ' .. tostring(p.subtype) .. ' '
413    if pt == 'glyph' then
414       s = base .. ' ' .. 
415          (p.char<0xF0000 and utfchar(p.char) or '') 
416          .. string.format(' (U+%X) ', p.char)
417          .. tostring(p.font) .. ' (' .. print_scaled(p.height) .. '+'
418          .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width)
419       if p.xoffset~=0 or p.yoffset~=0 then
420          s = s .. ' off: (' .. print_scaled(p.xoffset)
421                .. ',' .. print_scaled(p.yoffset) .. ')'
422       end
423       print_fn(s)
424    elseif pt=='hlist' or pt=='vlist' or pt=='unset'or pt=='ins' then
425       if pt=='ins' then
426          s = base .. '(' .. print_scaled(p.height) .. '+'
427             .. print_scaled(p.depth) .. ')'
428             .. ', dir=' .. tostring(node.has_attribute(p, attr_dir))
429       else
430          s = base .. '(' .. print_scaled(p.height) .. '+'
431             .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width)
432             .. ', dir=' .. tostring(node.has_attribute(p, attr_dir))
433       end
434       if (p.shift or 0)~=0 then
435          s = s .. ', shifted ' .. print_scaled(p.shift)
436       end
437       if p.glue_set and p.glue_sign ==2 or ( p.glue_sign==1 and p.glue_set>0) then
438          s = s .. ' glue set '
439          if p.glue_sign == 2 then s = s .. '-' end
440          s = s .. tostring(floor(p.glue_set*10000)/10000)
441          if p.glue_order == 0 then
442             s = s .. 'pt'
443          else
444             s = s .. 'fi'
445             for i = 2,  p.glue_order do s = s .. 'l' end
446          end
447       end
448       if get_attr_icflag(p) == icflag_table.PACKED then
449          s = s .. ' (packed)'
450       end
451       print_fn(s);
452       local bid = inner_depth
453       prefix, inner_depth = prefix.. '.', inner_depth + 1
454       if inner_depth < limit then
455          for q in node.traverse(p.head) do
456             debug_show_node_X(q, print_fn, limit, inner_depth)
457          end
458       end
459       prefix=k
460    elseif pt=='rule' then
461       s = base .. '(' .. print_scaled(p.height) .. '+'
462          .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width)
463          .. ', dir=' .. tostring(node.has_attribute(p, attr_dir))
464       print_fn(s)
465    elseif pt=='disc' then
466       print_fn(s)
467       local bid = inner_depth
468       if inner_depth < limit then
469          prefix, inner_depth = k.. 'p.', inner_depth + 1
470          for q in node.traverse(p.pre) do
471             debug_show_node_X(q, print_fn, limit, inner_depth)
472          end
473          prefix = k.. 'P.'
474          for q in node.traverse(p.post) do
475             debug_show_node_X(q, print_fn, limit, inner_depth)
476          end
477          prefix = k.. 'R.'
478          for q in node.traverse(p.replace) do
479             debug_show_node_X(q, print_fn, limit, inner_depth)
480          end
481       end
482       prefix=k
483    elseif pt == 'glue' then
484       s = base .. ' ' ..  print_spec(p)
485       if get_attr_icflag(p)>icflag_table.KINSOKU
486          and get_attr_icflag(p)<icflag_table.KANJI_SKIP then
487          s = s .. ' (from JFM: priority ' .. get_attr_icflag(p)-icflag_table.FROM_JFM .. ')'
488       elseif get_attr_icflag(p)==icflag_table.KANJI_SKIP then
489          s = s .. ' (kanjiskip)'
490       elseif get_attr_icflag(p)==icflag_table.KANJI_SKIP_JFM then
491          s = s .. ' (kanjiskip, JFM specified)'
492       elseif get_attr_icflag(p)==icflag_table.XKANJI_SKIP then
493          s = s .. ' (xkanjiskip)'
494       elseif get_attr_icflag(p)==icflag_table.XKANJI_SKIP_JFM then
495          s = s .. ' (xkanjiskip, JFM specified)'
496       end
497       print_fn(s)
498    elseif pt == 'kern' then
499       s = base .. ' ' .. print_scaled(p.kern) .. 'pt'
500       if p.subtype==2 then
501          s = s .. ' (for accent)'
502       elseif get_attr_icflag(p)==icflag_table.IC_PROCESSED then
503          s = s .. ' (italic correction)'
504       elseif get_attr_icflag(p)==icflag_table.LINEEND then
505          s = s .. ' (end-of-line)'
506          -- elseif get_attr_icflag(p)==ITALIC then
507          --    s = s .. ' (italic correction)'
508       elseif get_attr_icflag(p)>icflag_table.KINSOKU
509          and get_attr_icflag(p)<icflag_table.KANJI_SKIP then
510          s = s .. ' (from JFM: priority ' .. get_attr_icflag(p)-icflag_table.FROM_JFM .. ')'
511       end
512       print_fn(s)
513    elseif pt == 'penalty' then
514       s = base .. ' ' .. tostring(p.penalty)
515       if get_attr_icflag(p)==icflag_table.KINSOKU then
516          s = s .. ' (for kinsoku)'
517       end
518       print_fn(s)
519    elseif pt == 'dir' then
520       s = base .. ' ' .. tostring(p.dir) .. ' (level ' .. tostring(p.level) .. ')'
521       print_fn(s)
522    elseif pt == 'whatsit' then
523       s = base
524       if p.subtype==sid_user then
525          local t = tostring(p.user_id) .. ' (' ..
526             luatexbase.get_user_whatsit_name(p.user_id) .. ') '
527          if p.type ~= 110 then
528             s = s .. ' userid:' .. t .. p.value
529             print_fn(s)
530          else
531             s = s .. ' userid:' .. t .. '(node list)'
532             if p.user_id==userid_table.DIR then
533                s = s .. ' dir: ' .. tostring(node.has_attribute(p, attr_dir))
534             end
535             print_fn(s)
536             local bid = inner_depth
537             prefix, inner_depth =prefix.. '.', inner_depth + 1
538             if inner_depth < limit then
539                for q in node.traverse(p.value) do
540                   debug_show_node_X(q, print_fn, limit, inner_depth)
541                end
542             end
543             prefix, inner_depth = k, bid
544          end
545       else
546          s = s .. (node.subtype(p.subtype) or '')
547          if p.subtype==1 then
548             s = s .. ' stream=' .. p.stream
549             print_fn(s)
550             for i=1,#p.data do
551                print_fn(s .. '  [' .. i .. '] = ' .. tostring(p.data[i].csname))
552             end
553          else
554             print_fn(s)
555          end
556       end
557    -------- math node --------
558    elseif pt=='noad' then
559       s = base ; print_fn(s)
560       if p.nucleus then
561          prefix = k .. 'N'; debug_show_node_X(p.nucleus, print_fn, limit, inner_depth);
562       end
563       if p.sup then
564          prefix = k .. '^'; debug_show_node_X(p.sup, print_fn, limit, inner_depth);
565       end
566       if p.sub then
567          prefix = k .. '_'; debug_show_node_X(p.sub, print_fn, limit, inner_depth);
568       end
569       prefix = k;
570    elseif pt=='math_char' then
571       s = base .. ' fam: ' .. p.fam .. ' , char = ' .. utfchar(p.char)
572       print_fn(s)
573    elseif pt=='sub_box' or pt=='sub_mlist' then
574       print_fn(base)
575       if p.head then
576          prefix = k .. '.';
577          for q in node.traverse(p.head) do
578             debug_show_node_X(q, print_fn, limit, inner_depth)
579          end
580       end
581    else
582       print_fn(base)
583    end
584    p=node_next(p)
585 end
586 function luatexja.ext_show_node_list(head,depth,print_fn, lim)
587    prefix = depth
588    inner_depth = 0
589    if head then
590       while head do
591          debug_show_node_X(head, print_fn, lim or 1/0, inner_depth); head = node_next(head)
592       end
593    else
594       print_fn(prefix .. ' (null list)')
595    end
596 end
597 function luatexja.ext_show_node(head,depth,print_fn, lim)
598    prefix = depth
599    inner_depth = 0
600    if head then
601       debug_show_node_X(head, print_fn, lim or 1/0, inner_depth)
602    else
603       print_fn(prefix .. ' (null list)')
604    end
605 end
606
607 end