diff options
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | luatexbase-attr.dtx | 20 | ||||
-rw-r--r-- | luatexbase-cctb.dtx | 9 | ||||
-rw-r--r-- | luatexbase-loader.dtx | 3 | ||||
-rw-r--r-- | luatexbase-mcb.dtx | 21 | ||||
-rw-r--r-- | luatexbase-modutils.dtx | 47 |
6 files changed, 61 insertions, 40 deletions
@@ -13,7 +13,6 @@ all or generalise use of qstest - add debug messages to be used in the test suite? - mark all occurences of version-dependent stuff in the code -- quit using module() in favor of locals - support the syntax foo = require"foo" in modutils? How? compat diff --git a/luatexbase-attr.dtx b/luatexbase-attr.dtx index 977ea12..859803e 100644 --- a/luatexbase-attr.dtx +++ b/luatexbase-attr.dtx @@ -355,10 +355,10 @@ local texiowrite = texio.write --- luatex internal types local whatsit_t = nodetype"whatsit" local user_defined_t = nodesubtype"user_defined" ---- module declaration (deprecated in 5.2) -module('luatexbase', package.seeall) + luatexbase = luatexbase or { } local luatexbase = luatexbase + % \end{macrocode} % % This table holds the values of the allocated attributes, indexed by name. @@ -396,7 +396,7 @@ end % % \begin{macrocode} local last_alloc = 0 -function new_attribute(name, silent) +local function new_attribute(name, silent) if last_alloc >= 65535 then if silent then return -1 @@ -420,15 +420,17 @@ function new_attribute(name, silent) end return last_alloc end +luatexbase.new_attribute = new_attribute % \end{macrocode} % % Unset an attribute the correct way depending on \luatex's version. % % \begin{macrocode} local unset_value = (luatexbase.luatexversion < 37) and -1 or -2147483647 -function unset_attribute(name) +local function unset_attribute(name) tex.setattribute(attributes[name], unset_value) end +luatexbase.unset_attribute = unset_attribute % \end{macrocode} % % User whatsit allocation (experimental). @@ -458,7 +460,7 @@ local anonymous_prefix = "anon" % % \begin{macrocode} --- string -> string -> int -new_user_whatsit_id = function (name, package) +local new_user_whatsit_id = function (name, package) if name then if package then name = package .. prefixsep .. name end else -- anonymous @@ -490,7 +492,7 @@ luatexbase.new_user_whatsit_id = new_user_whatsit_id % % \begin{macrocode} --- string -> string -> (node_t -> int) -new_user_whatsit = function (name, package) +local new_user_whatsit = function (name, package) local id = new_user_whatsit_id(name, package) local wi = nodenew(whatsit_t, user_defined_t) wi.user_id = id @@ -504,7 +506,7 @@ luatexbase.new_user_whatsit = new_user_whatsit % % \begin{macrocode} --- string -> string -> int -get_user_whatsit_id = function (name, package) +local get_user_whatsit_id = function (name, package) if package then name = package .. prefixsep .. name end return user_whatsits[name] end @@ -518,7 +520,7 @@ luatexbase.get_user_whatsit_id = get_user_whatsit_id % % \begin{macrocode} --- string -> string -> int -get_user_whatsit_name = function (id) +local get_user_whatsit_name = function (id) return whatsit_ids[id] end luatexbase.get_user_whatsit_name = get_user_whatsit_name @@ -530,7 +532,7 @@ luatexbase.get_user_whatsit_name = get_user_whatsit_name % % \begin{macrocode} --- string -> unit -dump_registered_whatsits = function (package) +local dump_registered_whatsits = function (package) if package then texiowrite_nl("(user whatsit allocation stats for " .. package) else diff --git a/luatexbase-cctb.dtx b/luatexbase-cctb.dtx index f869c5b..8958f20 100644 --- a/luatexbase-cctb.dtx +++ b/luatexbase-cctb.dtx @@ -649,7 +649,8 @@ See the aforementioned source file(s) for copyright and licensing information. % % \begin{macrocode} %<*luamodule> -module('luatexbase', package.seeall) +luatexbase = luatexbase or { } +local luatexbase = { } % \end{macrocode} % % The number associated to a CS name is remembered in the |catcodetables| @@ -657,9 +658,10 @@ module('luatexbase', package.seeall) % % \begin{macrocode} catcodetables = {} -function catcodetabledef_from_tex(name, number) +local function catcodetabledef_from_tex(name, number) catcodetables[name] = tonumber(number) end +luatexbase.catcodetabledef_from_tex = catcodetabledef_from_tex % \end{macrocode} % % The next function creates some shortcuts for better readability in lua @@ -667,7 +669,7 @@ end % |luatexbase.catcodetables.CatcodeTableLaTeX|. % % \begin{macrocode} -function catcodetable_do_shortcuts() +local function catcodetable_do_shortcuts() local cat = catcodetables cat['latex'] = cat.CatcodeTableLaTeX cat['latex-package'] = cat.CatcodeTableLaTeXAtLetter @@ -678,6 +680,7 @@ function catcodetable_do_shortcuts() cat['string'] = cat.CatcodeTableString cat['other'] = cat.CatcodeTableOther end +luatexbase.catcodetable_do_shortcuts = catcodetable_do_shortcuts % \end{macrocode} % % \begin{macrocode} diff --git a/luatexbase-loader.dtx b/luatexbase-loader.dtx index b8e5098..11918a3 100644 --- a/luatexbase-loader.dtx +++ b/luatexbase-loader.dtx @@ -274,7 +274,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} % % Just in case it's called from a \TeX Lua script... diff --git a/luatexbase-mcb.dtx b/luatexbase-mcb.dtx index f4d6448..9070c8f 100644 --- a/luatexbase-mcb.dtx +++ b/luatexbase-mcb.dtx @@ -392,7 +392,8 @@ See the aforementioned source file(s) for copyright and licensing information. % \subsubsection{Module identification} % % \begin{macrocode} -module('luatexbase', package.seeall) +luatexbase = luatexbase or { } +local luatexbase = luatexbase local err, warning, info, log = luatexbase.provides_module({ name = "luatexbase-mcb", version = 0.5, @@ -627,7 +628,7 @@ local handlers = { % Add a function to a callback. First check arguments. % % \begin{macrocode} -function add_to_callback (name,func,description,priority) +local function add_to_callback (name,func,description,priority) if type(func) ~= "function" then return err("unable to add function:\nno proper function passed") end @@ -690,12 +691,13 @@ function add_to_callback (name,func,description,priority) log("inserting '%s'\nat position %s in '%s'", description, priority, name) end +luatexbase.add_to_callback = add_to_callback % \end{macrocode} % % Remove a function from a callback. First check arguments. % % \begin{macrocode} -function remove_from_callback (name, description) +local function remove_from_callback (name, description) if not name or name == "" then err("unable to remove function:\nno proper callback name passed") return @@ -742,13 +744,14 @@ function remove_from_callback (name, description) end return end +luatexbase.remove_from_callback = remove_from_callback % \end{macrocode} % % Remove all the functions registered in a callback. Unregisters the % callback handler unless the callback is user-defined. % % \begin{macrocode} -function reset_callback (name, make_false) +local function reset_callback (name, make_false) if not name or name == "" then err("unable to reset:\nno proper callback name passed") return @@ -767,13 +770,14 @@ function reset_callback (name, make_false) end end end +luatexbase.reset_callback = reset_callback % \end{macrocode} % % Get a function's priority in a callback list, or false if the function is % not in the list. % % \begin{macrocode} -function priority_in_callback (name, description) +local function priority_in_callback (name, description) if not name or name == "" or not callbacktypes[name] or not description then @@ -788,6 +792,7 @@ function priority_in_callback (name, description) end return false end +luatexbase.priority_in_callback = priority_in_callback % \end{macrocode} % % \subsubsection{Public functions for user-defined callbacks} @@ -804,7 +809,7 @@ end % callback must also call it, see next function. % % \begin{macrocode} -function create_callback(name, ctype, default) +local function create_callback(name, ctype, default) if not name then err("unable to call callback:\nno proper name passed", name) return nil @@ -827,13 +832,14 @@ function create_callback(name, ctype, default) lua_callbacks_defaults[name] = default callbacktypes[name] = ctype end +luatexbase.create_callback = create_callback % \end{macrocode} % % This function calls a callback. It can only call a callback created by % the \texttt{create} function. % % \begin{macrocode} -function call_callback(name, ...) +local function call_callback(name, ...) if not name then err("unable to call callback:\nno proper name passed", name) return nil @@ -855,6 +861,7 @@ function call_callback(name, ...) end return f(...) end +luatexbase.call_callback = call_callback % \end{macrocode} % % That's all folks! 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} |