[Dev-luatex] Callbacks in Lua wrapper of mplib

luigi scarso luigi.scarso at gmail.com
Wed Nov 7 13:00:50 CET 2018


On Wed, Nov 7, 2018 at 12:18 PM Marcel Kr├╝ger <tex at 2krueger.de> wrote:

> Hi,
>
> I recently discovered that the Lua wrapper of mplib registers all
> callbacks globally
> such that creating multiple mplib instances with different callbacks
> breaks.
>
>
why not this ?

 \directlua{
      local current_instance
      local custom_find_file =  custom_find_file or {}
      local mp_find_file_driver = function(name, mode, type) print("I am
",current_instance) if custom_find_file[current_instance] then return
custom_find_file[current_instance](name, mode, type) else  return
"unregistered" end end
      custom_find_file['mp1'] = function(name, mode, type) return name end
      custom_find_file['mp2'] = function(name, mode, type) if name ==
'cmr10' then print'This should not happen' end return name end


      local mp1 = mplib.new{
        find_file = mp_find_file_driver
      }

      local mp2 = mplib.new{
          find_file = mp_find_file_driver
        }
      current_instance = "mp1"
      mp1:execute[[
        input cmr10;
      ]]

      current_instance = "mp2"
      mp2:execute[[
        input cmr10;
      ]]


    }
    \bye

-- 
luigi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ntg.nl/pipermail/dev-luatex/attachments/20181107/7f8cff5e/attachment.html>


More information about the dev-luatex mailing list