summaryrefslogtreecommitdiff
path: root/luatexbase-modutils.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'luatexbase-modutils.dtx')
-rw-r--r--luatexbase-modutils.dtx47
1 files changed, 28 insertions, 19 deletions
diff --git a/luatexbase-modutils.dtx b/luatexbase-modutils.dtx
index 6f500da..0645e1b 100644
--- a/luatexbase-modutils.dtx
+++ b/luatexbase-modutils.dtx
@@ -237,22 +237,23 @@ See the aforementioned source file(s) for copyright and licensing information.
% they just don't do the same thing (declaring information vs changing the
% current name space).
%
-% Now, here is how you module may begin:
+% Now, here is a module header template showing all the recommended elements:
% \begin{verbatim}
% local err, warn, info, log = luatexbase.provides_module({
% -- required
-% name = 'mymodule',
+% name = 'mymodule',
% -- recommended
-% date = '1970/01/01',
-% version = 0.0, -- or version = '0.0a',
-% description = 'a Lua module template',
+% date = '1970/01/01',
+% version = 0.0, -- or version = '0.0a',
+% description = 'a Lua module template',
% -- optional and ignored
-% author = 'A. U. Thor',
-% licence = 'LPPL v1.3+',
+% author = 'A. U. Thor',
+% licence = 'LPPL v1.3+',
% })
%
-% module('mynamespace', package.seeall)
-% -- or any other method (see chapter 15 of PIL for examples)
+% mynamespace = mynamespace or { }
+% local mynamespace = mynamespace
+%
% \end{verbatim}
%
% Alternatively, if you don't want to assume \pk{luatexbase-modutils} is
@@ -276,8 +277,8 @@ See the aforementioned source file(s) for copyright and licensing information.
% })
% end
%
-% module('mynamespace', package.seeall)
-% -- or any other method (see chapter 15 of PIL for examples)
+% mynamespace = mynamespace or { }
+% local mynamespace = mynamespace
%
% local function err(msg)
% -- etc.
@@ -457,7 +458,8 @@ See the aforementioned source file(s) for copyright and licensing information.
%
% \begin{macrocode}
%<*luamodule>
-module("luatexbase", package.seeall)
+luatexbase = luatexbase or { }
+local luatexbase = luatexbase
% \end{macrocode}
%
% \subsection{Internal functions and data}
@@ -495,44 +497,49 @@ end
local function module_error_int(mod, ...)
error(msg_format('error', mod, ...), 3)
end
-function module_error(mod, ...)
+local function module_error(mod, ...)
module_error_int(mod, ...)
end
+luatexbase.module_error = module_error
% \end{macrocode}
%
% Split the lines explicitly in order not to depend on the value of
% |\newlinechar|.
%
% \begin{macrocode}
-function module_warning(mod, ...)
+local function module_warning(mod, ...)
for _, line in ipairs(msg_format('warning', mod, ...):explode('\n')) do
texio.write_nl(line)
end
end
-function module_info(mod, ...)
+luatexbase.module_warning = module_warning
+local function module_info(mod, ...)
for _, line in ipairs(msg_format('info', mod, ...):explode('\n')) do
texio.write_nl(line)
end
end
+luatexbase.module_info = module_info
% \end{macrocode}
%
% No line splitting or advanced formating here.
%
% \begin{macrocode}
-function module_log(mod, msg, ...)
+local function module_log(mod, msg, ...)
texio.write_nl('log', mod..': '..msg:format(...))
end
+luatexbase.module_log = module_log
% \end{macrocode}
%
% Produce custom versions of the reporting functions.
%
% \begin{macrocode}
-function errwarinf(name)
+local function errwarinf(name)
return function(...) module_error_int(name, ...) end,
function(...) module_warning(name, ...) end,
function(...) module_info(name, ...) end,
function(...) module_log(name, ...) end
end
+luatexbase.errwarinf = errwarinf
% \end{macrocode}
%
% For our own convenience, local functions for warning and errors in the
@@ -547,7 +554,7 @@ local err, warn = errwarinf('luatexbase.modutils')
% Load a module with mandatory name checking and optional version checking.
%
% \begin{macrocode}
-function require_module(name, req_date)
+local function require_module(name, req_date)
require(name)
local info = modules[name]
if not info then
@@ -560,6 +567,7 @@ function require_module(name, req_date)
end
end
end
+luatexbase.require_module = require_module
% \end{macrocode}
%
% Provide identification information for a module. As a bonus, custom
@@ -567,7 +575,7 @@ end
% everything done in |require_module()|.
%
% \begin{macrocode}
-function provides_module(info)
+local function provides_module(info)
if not (info and info.name) then
err('provides_module: missing information')
end
@@ -576,6 +584,7 @@ function provides_module(info)
modules[info.name] = info
return errwarinf(info.name)
end
+luatexbase.provides_module = provides_module
% \end{macrocode}
%
% \begin{macrocode}