OSDN Git Service

Fix #39431: support notdef=... (introduced in luaotfload v2.98)
[luatex-ja/luatexja.git] / src / ltj-base.lua
index f48c2ab..4182a60 100644 (file)
@@ -156,20 +156,6 @@ ltjb.mprint = mprint
 -------------------- Handling of TeX values
 do
 
-  local glue_spec_id = node.id("glue_spec")
-
-  local function copy_skip(s1, s2)
-    if not s1 then
-      s1 = node.new(glue_spec_id)
-    end
-    s1.width = s2.width or 0
-    s1.stretch = s2.stretch or 0
-    s1.stretch_order = s2.stretch_order or 0
-    s1.shrink = s2.shrink or 0
-    s1.shrink_order = s2.shrink_order or 0
-    return s1
-  end
-
 --! ixbase.to_dimen() と同じ
   local function to_dimen(val)
     if val == nil then
@@ -192,44 +178,7 @@ do
     return tex.sp(val), fil
   end
 
---! ixbase.to_skip() と同じ
-  local function to_skip(val)
-    if type(val) == "userdata" then
-      return val
-    end
-    local res = node.new(glue_spec_id)
-    if val == nil then
-      res.width = 0
-    elseif type(val) == "number" then
-      res.width = val
-    elseif type(val) == "table" then
-      copy_skip(res, val)
-    else
-      local t = tostring(val):lower():explode()
-      local w, p, m = t[1], t[3], t[5]
-      if t[2] == "minus" then
-        p, m = nil, t[3]
-      end
-      res.width = tex.sp(t[1])
-      if p then
-        res.stretch, res.stretch_order = parse_dimen(p)
-      end
-      if m then
-        res.shrink, res.shrink_order = parse_dimen(m)
-      end
-    end
-    return res
-  end
-
-  local function dump_skip(s)
-    print(("%s+%s<%s>-%s<%s>"):format(
-      s.width or 0, s.stretch or 0, s.stretch_order or 0,
-      s.shrink or 0, s.shrink_order or 0))
-  end
-
   ltjb.to_dimen = to_dimen
-  ltjb.dump_skip = dump_skip
-  ltjb.to_skip = to_skip
 end
 
 -------------------- Virtual table for LaTeX counters
@@ -308,7 +257,7 @@ do
       if lfs.isdir(testpath) then savepath = testpath; break end
    end
 
-   save_cache_luc = function (filename, t, serialized)
+   local function save_cache_luc(filename, t, serialized)
       local fullpath = savepath .. '/' ..  filename .. luc_suffix
       local s = serialized or serialize(t, 'return', false)
       if s then
@@ -322,7 +271,7 @@ do
       end
    end
 
-   save_cache = function (filename, t)
+   local function save_cache(filename, t)
       local fullpath = savepath .. '/' ..  filename .. '.lua'
       local s = serialize(t, 'return', false)
       if s then
@@ -336,7 +285,7 @@ do
       end
    end
 
-   local function load_cache_a (filename, outdate)
+   local function load_cache_a(filename, outdate)
       local result
       for _,v in pairs(path) do
         local fn = join(v, cache_dir, filename)
@@ -353,7 +302,7 @@ do
       end
    end
    
-   load_cache = function (filename, outdate)
+   local function load_cache(filename, outdate)
       local r = load_cache_a(filename ..  luc_suffix, outdate)
       if r then 
         return r
@@ -364,6 +313,17 @@ do
       end
    end
 
+   local function remove_file_if_exist(name)
+     if os.rename(name,name) then os.remove(name) end
+   end
+   local function remove_cache (filename)
+      local fullpath_wo_ext = savepath .. '/' ..  filename .. '.lu'
+      remove_file_if_exist(fullpath_wo_ext .. 'a')
+      remove_file_if_exist(fullpath_wo_ext .. 'b')
+      remove_file_if_exist(fullpath_wo_ext .. 'c')
+   end
+
+   ltjb.remove_cache = remove_cache
    ltjb.load_cache = load_cache
    ltjb.save_cache_luc = save_cache_luc
    ltjb.save_cache = save_cache
@@ -400,6 +360,33 @@ ltjb.generic_info_no_line = generic_info_no_line
 ltjb.ltj_warning_no_line = ltj_warning_no_line
 ltjb.ltj_error = ltj_error
 
+---- deterministic version of luatexbase.add_to_callback
+function ltjb.add_to_callback(name,fun,description,priority)
+    local priority= priority
+    if priority==nil then
+       priority=#luatexbase.callback_descriptions(name)+1
+    end
+    if(luatexbase.callbacktypes[name] == 3 and
+    priority == 1 and
+    #luatexbase.callback_descriptions(name)==1) then
+       luatexbase.module_warning("luatexbase",
+       "resetting exclusive callback: " .. name)
+       luatexbase.reset_callback(name)
+    end
+    local saved_callback={},ff,dd
+    for k,v in ipairs(luatexbase.callback_descriptions(name)) do
+       if k >= priority then
+           ff,dd= luatexbase.remove_from_callback(name, v)
+           saved_callback[#saved_callback+1]={ff,dd}
+       end
+    end
+    luatexbase.base_add_to_callback(name,fun,description)
+    for _,v in ipairs(saved_callback) do
+       luatexbase.base_add_to_callback(name,v[1],v[2])
+    end
+    return
+end
+
 -------------------- mock of debug logger
 if not ltjb.out_debug then
    local function no_op() end