[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Versioning libraries
- From: David Manura <dm.lua@...>
- Date: Thu, 6 Aug 2009 20:51:16 -0400
On Thu, Aug 6, 2009 at 5:31 PM, Luiz Henrique de Figueiredo wrote:
>> I'm trying to find a way to allow Lua to load different versions of a library but only one per process. [...] I'm probably going to rewrite the require function to enable this requirement.
>
> require already does support versions albeit in an awkward way:
>
> "Moreover, if the module name has a hyphen, its prefix up to (and
> including) the first hyphen is removed. For instance, if the module name
> is a.v1-b.c, the function name will be luaopen_b_c."
If you have two versions of a library, you can rename them (e.g. foo1
and foo2) and then simply do require "foo1" and require "foo2". In
some cases, the two versions can exist in memory simultaneously this
way.
If you don't want to rename the libraries, you may store the libraries
in different folders and set package.path and package.cpath search
paths so that require "foo" picks the library from a certain folder
(possibly preferentially from the current working directory, otherwise
from a global location).
These solutions require no change to require.