[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Putting version information, description, copright into modules
- From: Daurnimator <quae@...>
- Date: Fri, 12 Feb 2016 10:57:14 +1100
On 11 February 2016 at 21:08, Marc Balmer <marc@msys.ch> wrote:
> We usually put some information strings into our modules, e.g.
>
> lua_pushliteral(L, "_COPYRIGHT");
> lua_pushliteral(L, "Copyright (C) 2014 micro systems marc balmer");
> lua_settable(L, -3);
> lua_pushliteral(L, "_DESCRIPTION");
> lua_pushliteral(L, "EAN support functions");
> lua_settable(L, -3);
> lua_pushliteral(L, "_VERSION");
> lua_pushliteral(L, "ean 1.0.1");
> lua_settable(L, -3);
>
> How do other module-writer handle such? Do you put such information into modules? Do you think it makes sense? Is it of any use at all? Is it common practice? (yes, I am considering removing it...)
I find that I don't want it in *all* modules, but just for a project as a whole.
e.g. having `require"luatz"._VERSION` would be reasonable, but
`require "luatz.timetable"._VERSION` is a waste.
With lua-http I took a slightly different approach, and have a module
`require"http.version"`. This let me keep the version in one place,
while requiring it in from others (e.g. I pull it in to use as part of
the default user agent).
The other thing to note is that fields starting with '_' are
customarily reserved. From
http://www.lua.org/manual/5.3/manual.html#3.1:
"As a convention, programs should avoid creating names that start with
an underscore followed by one or more uppercase letters (such as
_VERSION)."
That said, if you do have these fields, it makes sense to use the
convention started by the old module() function. From
http://www.lua.org/manual/5.1/manual.html#pdf-module:
"initializes t._NAME with the given name, t._M with the module (t
itself), and t._PACKAGE with the package name (the full module name
minus last component; see below)"
Personally I haven't bothered adding in the fields for many of my
projects. Perhaps I should, depending on the outcome of this
thread....