summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElie Roux <elie.roux@telecom-bretagne.eu>2013-05-04 17:09:58 +0200
committerElie Roux <elie.roux@telecom-bretagne.eu>2013-05-04 17:09:58 +0200
commit5aaa7476b5734c8d7611e7ebf2c6d609dea09064 (patch)
tree7292c2d12aaed30750e61915478acc3eb801d56a
parentf848294da11121e5a1943e22055265266f6aff66 (diff)
downloadluatexbase-5aaa7476b5734c8d7611e7ebf2c6d609dea09064.tar.gz
Adding a few auxiliary functions for module availability and version checking
-rw-r--r--luatexbase-modutils.dtx82
1 files changed, 82 insertions, 0 deletions
diff --git a/luatexbase-modutils.dtx b/luatexbase-modutils.dtx
index 0645e1b..2851286 100644
--- a/luatexbase-modutils.dtx
+++ b/luatexbase-modutils.dtx
@@ -229,6 +229,14 @@ See the aforementioned source file(s) for copyright and licensing information.
% standard Lua function, so you may want to avoid overwriting it, hence the
% use of |err| in the above example.)
%
+% \begin{qcode}
+% local module_info = luatexbase.get_module_info(\meta{name})
+% local version = luatexbase.get_module_version(\meta{name})
+% local is_loaded = luatexbase.is_module_loaded(\meta{name})
+% \end{qcode}
+% These functions check for the availability or version of a module, and can
+% even return a copy of the |module_info| table.
+%
% \subsection{Templates}
%
% Let me emphasize again that, while |luatexbase.require_module()| is meant to
@@ -587,6 +595,73 @@ end
luatexbase.provides_module = provides_module
% \end{macrocode}
%
+% \subsubsection{module availability and version checking}
+%
+% A simple table copy function.
+%
+% \begin{macrocode}
+local fastcopy = table.fastcopy or function(old)
+ if old then
+ local new = { }
+ for k,v in next, old do
+ if type(v) == "table" then
+ new[k] = fastcopy(v)
+ else
+ new[k] = v
+ end
+ end
+ local mt = getmetatable(old)
+ if mt then
+ setmetatable(new,mt)
+ end
+ return new
+ else
+ return { }
+ end
+end
+% \end{macrocode}
+%
+% Gives the table of the infos on a module, as given in |provides_module|.
+%
+% \begin{macrocode}
+local function get_module_info(name)
+ local module_table = modules[name]
+ if not module_table then
+ return nil
+ else
+ return fastcopy(module_table)
+ end
+end
+luatexbase.get_module_info = get_module_info
+% \end{macrocode}
+%
+% Gives the version of a module, or nil if the module is not loaded.
+%
+% \begin{macrocode}
+function get_module_version(name)
+ local module_table = modules[name]
+ if not module_table then
+ return nil
+ else
+ return module_table.version
+ end
+end
+luatexbase.get_module_version = get_module_version
+% \end{macrocode}
+%
+% Returns true if the module is loaded, false otherwise.
+%
+% \begin{macrocode}
+function is_module_loaded(name)
+ if modules[name] then
+ return true
+ else
+ return false
+ end
+end
+luatexbase.is_module_loaded = is_module_loaded
+% \end{macrocode}
+%
% \begin{macrocode}
%</luamodule>
% \end{macrocode}
@@ -605,6 +680,13 @@ local err, warn, info, log = luatexbase.provides_module {
}
info('It works!\nOh, rly?\nYeah rly!')
log("I'm a one-line info.")
+info("1 = "..luatexbase.get_module_version('test-modutils'))
+if is_module_loaded('test-modutils') then
+ info("ok!")
+else
+ err("problem!")
+end
+info("2000/01/01 = "..luatexbase.get_module_info('test-modutils').date)
%</testdummy>
% \end{macrocode}
%