[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Convention for naming Lua Module files
- From: Ross Berteig <Ross@...>
- Date: Wed, 6 Apr 2016 16:25:45 -0700
On 4/6/2016 2:46 PM, Hisham wrote:
On 6 April 2016 at 14:37, Derek Bailey <email@example.com> wrote:
Is there a convention or pattern for naming Lua Module files (.dll) that
indicate which Lua version they are built against?
I built a module on Windows that targets Lua 5.1, 5.2, and 5.3, but I end up
naming the resulting module file the same in all three cases (e.g.,
mymodule.dll). So I just place them in three separate directories
(51/mymodule.dll, 52/mymodule.dll, 53/mymodule.dll).
Should I append the Lua version in the output file name somehow?
(mymodule52.dll) The issue with that is the require() statement in the code
now needs be updated to reflect that name change.
The convention on Unix is to use lib/5.1/mymodule.so,
lib/5.2/mymodule.so and lib/5.3/mymodule.so. Keeping the name as
mymodule.<extension> saves troubles with require() as you said, and
then it becomes only a matter of making LUA_CPATH (or LUA_CPATH_5_3
etc.) point to the right places (which is something you'll have to
deal with on Windows, anyway).
A convention followed on Windows in the Lua for Windows distribution is
to note that package.cpath (and LUA_CPATH as well) can include part of
the file name in each matching path segment. The compiled in default for
package.cpath (after expanding the part derived from the path to
lua.exe) looks like this on my PC:
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
C:\Users\Ross\>lua -e "print(package.cpath:gsub(';',';\n'))"
C:\Program Files (x86)\Lua\5.1\?.dll;
C:\Program Files (x86)\Lua\5.1\?51.dll;
C:\Program Files (x86)\Lua\5.1\clibs\?.dll;
C:\Program Files (x86)\Lua\5.1\clibs\?51.dll;
C:\Program Files (x86)\Lua\5.1\loadall.dll;
C:\Program Files (x86)\Lua\5.1\clibs\loadall.dll 7
The entries for ?52.dll allow require"iup" to match the provided iup51.dll.
Like so many things in Lua, there really is more than one way to do it,
and the "official" way is left up to the packager or platform policy.
So in short, yeah, it's best to leave versioning to the directory name
and not the filename of the module.
Ross Berteig Ross@CheshireEng.com
Cheshire Engineering Corp. http://www.CheshireEng.com/