From 29bee8c9edf934690e25816c001e8afefd942e94 Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Sun, 5 May 2013 15:00:23 +0200 Subject: Adding a few more accessors functions --- luatexbase-modutils.dtx | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'luatexbase-modutils.dtx') diff --git a/luatexbase-modutils.dtx b/luatexbase-modutils.dtx index 9da5605..1a50f24 100644 --- a/luatexbase-modutils.dtx +++ b/luatexbase-modutils.dtx @@ -468,6 +468,7 @@ See the aforementioned source file(s) for copyright and licensing information. %<*luamodule> luatexbase = luatexbase or { } local luatexbase = luatexbase +local string_gsub = string.gsub % \end{macrocode} % % \subsection{Internal functions and data} @@ -484,7 +485,8 @@ local modules = modules or {} % % \begin{macrocode} local function date_to_int(date) - local numbers = string.gsub(date, "(%d+)/(%d+)/(%d+)", "%1%2%3") + if date == '' then return -1 end + local numbers = string_gsub(date, "(%d+)/(%d+)/(%d+)", "%1%2%3") return tonumber(numbers) end % \end{macrocode} @@ -634,7 +636,8 @@ end luatexbase.get_module_info = get_module_info % \end{macrocode} % -% Gives the version of a module, or nil if the module is not loaded. +% Gives the version of a module, nil if the module is not loaded and empty +% string if the module did not set its date. % % \begin{macrocode} function get_module_version(name) @@ -648,6 +651,37 @@ end luatexbase.get_module_version = get_module_version % \end{macrocode} % +% Gives the date string of a module, nil if the module is not loaded and +% empty string of the modules did not set its date. +% +% \begin{macrocode} +function get_module_date(name) + local module_table = modules[name] + if not module_table then + return nil + else + return module_table.date + end +end +luatexbase.get_module_date = get_module_date +% \end{macrocode} +% +% Gives the date number of a module, for date comparison, nil if the +% module is not loaded and -1 if the module did not set its date. The number +% is formated as |yyyymmdd|. +% +% \begin{macrocode} +function get_module_date_int(name) + local module_table = modules[name] + if not module_table then + return nil + else + return module_table.date and date_to_int(module_table.date) + end +end +luatexbase.get_module_date_int = get_module_date_int +% \end{macrocode} +% % Returns true if the module is loaded, false otherwise. % % \begin{macrocode} @@ -677,6 +711,12 @@ local err, warn, info, log = luatexbase.provides_module { version = 1, description = 'dummy test package', } +luatexbase.provides_module { + name = 'test-modutils2', + date = '', + version = 1, + description = 'dummy test package', +} info('It works!\nOh, rly?\nYeah rly!') log("I'm a one-line info.") info("1 = "..luatexbase.get_module_version('test-modutils')) @@ -686,6 +726,8 @@ else err("problem!") end info("2000/01/01 = "..luatexbase.get_module_info('test-modutils').date) +info("20000101 = "..luatexbase.get_module_date_int('test-modutils')) +info("-1 = "..luatexbase.get_module_date_int('test-modutils2')) % % \end{macrocode} % -- cgit v1.2.3 From 2ed4d98b8bd2764d725131e7b73daceb496b68dd Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Mon, 6 May 2013 09:54:48 +0200 Subject: Updating doc --- luatexbase-modutils.dtx | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) (limited to 'luatexbase-modutils.dtx') diff --git a/luatexbase-modutils.dtx b/luatexbase-modutils.dtx index 1a50f24..d4dbef0 100644 --- a/luatexbase-modutils.dtx +++ b/luatexbase-modutils.dtx @@ -144,17 +144,10 @@ See the aforementioned source file(s) for copyright and licensing information. % % \medskip % -% It is important to notice that Lua's standard function |module()| is -% completely orthogonal with the present package. It has nothing to do with -% identification and deals only with namespaces: more precisely, it -% modifies the current environment. So, you should continue to -% use it normally regardless of whether you chose to use this package's -% features for identification. -% -% It is recommended to always use |module()| or any other method that ensure -% the global name space remains clean. For example, you may heavily use the -% |local| keyword and explicitly qualify the name of every non-local symbol. -% Chapter 15 of \href{http://www.lua.org/pil/}{Programming in Lua, 1st ed.} +% It is important to note that Lua's unction |module()| is deprecated in +% Lua 5.2 and should be avoided. For examples of good practices for creating +% modules, see section~\ref{template}. Chapter 15 +% of \href{http://www.lua.org/pil/15.html}{Programming in Lua, 3rd ed.} % discusses various methods for managing packages. % % \subsection{\tex macros} @@ -232,18 +225,14 @@ See the aforementioned source file(s) for copyright and licensing information. % \begin{qcode} % local module_info = luatexbase.get_module_info(\meta{name}) % local version = luatexbase.get_module_version(\meta{name}) +% local date = luatexbase.get_module_date(\meta{name}) +% local date_int = luatexbase.get_module_date_int(\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 -% be used as a replacement for |require()|, the function -% |luatexbase.provides_module()| \emph{is not} a replacement for |module()|: -% they just don't do the same thing (declaring information vs changing the -% current name space). +% \subsection{Templates}\label{template} % % Now, here is a module header template showing all the recommended elements: % \begin{verbatim} -- cgit v1.2.3