summaryrefslogtreecommitdiff
path: root/luatexbase-loader.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'luatexbase-loader.dtx')
-rw-r--r--luatexbase-loader.dtx102
1 files changed, 28 insertions, 74 deletions
diff --git a/luatexbase-loader.dtx b/luatexbase-loader.dtx
index 2635c54..5550fdf 100644
--- a/luatexbase-loader.dtx
+++ b/luatexbase-loader.dtx
@@ -133,27 +133,22 @@ See the aforementioned source file(s) for copyright and licensing information.
% when the library is initialised (which is always the case in \tex mode,
% unless explicitly disabled by the user). However, it did not respect the
% Lua convention that |require("foo.bar")| should look for |foo/bar.lua| until
-% version 0.60. This package adds such behaviour to older versions of \luatex.
-%
-% More precisely, it implements a new kpse searcher that looks for file
-% |foo/bar| using Kpathsea with the format |lua| (that is, search along
-% |LUAINPUTS| and try the following extensions: |.luc|, |.luctex|, |.texluc|,
-% |.lua|, |.luatex|, |.texlua|). If this search fails, it falls back to
-% |foo.bar| (along the same path with the same extensions).
-%
-% Also, older versions of \luatex, such as 0.25.4 (\texlive 2008), don't know
-% about the |lua| format for kpse searching. So, an emulator for this function
-% is provided. The emulator is not perfect, in particular it may find more
-% results than the normal |lua| format search.\footnote{And may also fail to
-% find the file in particular cases, see comments in the implementation for
-% details.} In order to ensure more homogeneous results across versions, this
-% emulator is used as a fall-back when the real |lua| format search doesn't
-% find any result.
-%
-% Finally, a combined version of this new kpse searcher and the original
-% function at |package.loaders[2]| (using first the new loader, then the old
-% one if the new doesn't return any result) is installed as
-% |package.loaders[2]|.
+% version 0.60. \luatex 0.74 ships with Lua 5.2 that has a different loading
+% system.
+%
+% The aim of this package is to have a coherent behaviour between versions of
+% LuaTeX. The first versions did ensure backward compatibilty to \luatex 0.25
+% but as \luatex development is quite fast, this version supports only \luatex
+% 0.45 and higher.
+%
+% More precisely, when asked for |foo.bar| (or |foo.bar.lua|), it first looks
+% for file |foo/bar| using Kpathsea with the format |lua|, and then for
+% |foo.bar|.
+%
+% As |oberdiek.luatex.lua| from |luatex.sty| also registers a loader, we
+% make a combined version of the new kpse searcher of this package and the
+% function registered in |oberdiek.luatex.lua| (registered in
+% |package.searchers[2]|) and register it in |package.searchers[2]|.
%
% \section{Implementation}
%
@@ -266,7 +261,7 @@ See the aforementioned source file(s) for copyright and licensing information.
% \begin{macrocode}
\luatexbase@directlua{%
local file = "luatexbase.loader.lua"
- local path = assert(kpse.find_file(file, 'tex'),
+ local path = assert(kpse.find_file(file, 'lua'),
"File '"..file.."' not found")
texio.write_nl("("..path..")")
dofile(path)}
@@ -291,8 +286,7 @@ module('luatexbase', package.seeall)
% approximate |LUAINPUTS|. But we need to handle suffixes ourselves.
%
% |lua_suffixes| is taken verbatim from Kpathsea's source
-% (\file{tex-file.c}, constant |LUA_SUFFIXES|).\footnote{Unchanged since
-% 2007-07-06, last checked 2010-05-10.}
+% (\file{tex-file.c}, constant |LUA_SUFFIXES|).\footnote{Last checked 2013-04-12.}
%
% \begin{macrocode}
local lua_suffixes = {
@@ -308,68 +302,28 @@ local function ends_with(suffix, name)
end
% \end{macrocode}
%
-% The search function first builds the list of filenames to be search. For
-% the lua format, kpse always adds a suffix if no (known) suffix is
-% present, so we do the same.
+% Auxiliary function for suffixes: returns the basename of a file if it end
+% by one of the suffixes.
%
% \begin{macrocode}
-local function find_file_lua_emul(name)
- local search_list = {}
+local function basename(name)
for _, suffix in ipairs(lua_suffixes) do
if ends_with(suffix, name) then
- search_list = { name }
- break
- else
- table.insert(search_list, name..suffix)
- end
- end
-% \end{macrocode}
-%
-% Now look for each file in this list.
-%
-% \begin{macrocode}
- for _, search_name in ipairs(search_list) do
- local f = kpse.find_file(search_name, 'texmfscripts')
- or kpse.find_file(search_name, 'tex')
-% \end{macrocode}
-%
-% There is a problem with using the |tex| search format: kpse will try to
-% add suffixes from the |TEX_SUFFIXES| list, which may lead to problems
-% if a file like \meta{name}|.lua.tex| exists. We prevent that by checking if
-% the file found ends with the required name. So \meta{name}|.lua| will
-% still be hidden by \meta{name}.|lua.tex| but it seems less bad not to
-% find it than to return an incorrect result.
-%
-% \begin{macrocode}
- if f and ends_with(search_name, f) then
- return f
+ return name:sub(1, -(suffix:len()+1))
end
end
+ return name
end
% \end{macrocode}
%
-% If lua search format is available, use it with emulation as a fall-back,
-% or just use emulation.
-%
-% \begin{macrocode}
-local find_file_lua
-if pcall(kpse.find_file, 'dummy', 'lua') then
- find_file_lua = function (name)
- return kpse.find_file(name, 'lua') or find_file_lua_emul(name)
- end
-else
- find_file_lua = function (name)
- return find_file_lua_emul(name)
- end
-end
-% \end{macrocode}
-%
-% Find the full path corresponding to a module name.
+% The main function. Currently it emulates the behaviour |x.y->x/y.lua|
+% for compatibility with \luatex prior to 0.60, but this behaviour
+% should be considered deprecated and will disapear in the next release.
%
% \begin{macrocode}
local function find_module_file(mod)
- return find_file_lua(mod:gsub('%.', '/'), 'lua')
- or find_file_lua(mod, 'lua')
+ local compat = basename(mod):gsub('%.', '/')
+ return kpse.find_file(compat, 'lua') or kpse.find_file(mod, 'lua')
end
% \end{macrocode}
%