[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A major problem with the Lua ecosystem
- From: Sean Conner <sean@...>
- Date: Thu, 1 Feb 2018 15:46:46 -0500
It was thus said that the Great Tim Hill once stated:
> > On Feb 1, 2018, at 8:41 AM, Sean Conner <sean@conman.org> wrote:
> > It was thus said that the Great Dibyendu Majumdar once stated:
> >>
> >> Sorry I should know the answer to this but I don't. Does Lua support
> >> dotted module names... i.e. map to directory path?
> >
> > You mean something like:
> >
> > net = require "org.conman.net" --?
> >
> > If so, then yes, Lua does.
>
> This cleanly solves the external namespace, assuming someone can promote
> some form of standardization around whatever convention is agreed
> (LuaRocks team???). But it leaves open that global variable used for the
> assignment target. If I control the whole corpus of Lua code in a project,
> then I can control the internal global namespace, but if I’m using 3rd
> party Lua code which ITSELF using require(), how to I handle namespace
> collisions on these globals?
That's really only an issue with lua 5.1, which *will always* create a
global when loading a module. Lua 5.2+ will no longer create the global and
it's up to the programmer to cache the value from require() into some
variable.
So yes, this also works:
local net = require "org.conman.net"
Lua 5.1 will still create a global "org", inside which is "conman" and
inside that "net". Lua 5.2+ won't do that.
-spc