[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua as replacement for Bash scripting
- From: David Manura <dm.lua@...>
- Date: Wed, 7 Jul 2010 21:29:09 -0400
On Wed, Jul 7, 2010 at 8:33 PM, Alexander Gladysh <agladysh@gmail.com> wrote:
> On Wed, Jul 7, 2010 at 22:59, Hisham <hisham.hm@gmail.com> wrote:
>> Agreed. I think we could get away with two modules, sh (pure-Lua) and
>> sh.fs (with the optional dependencies).
>
> Hmm... I, usually, do not like putting unrelated things in a single
> namespace :-)
You've come across one confusion that the Lua 5.1 module system
introduces, which is that "sh.fs" could be a module name or a variable
inside the "sh" module or both. This brings up a variety of boring
questions such as
- If a module requires "sh", does "sh.fs" get required as well?
(preferably no, particularly if sh.* modules are many or unrelated.)
- If a module requires "sh" after another module in your program
requires "sh.fs", will sh.fs be visible as a side-effect in the first
module? (preferably no)
- Is there a conflict if sh contains a variable named "fs" and some
module requires the module "sh.fs"? (preferably no)
- Do the designers of modules "fs" and "sh.fs" need to coordinate
variable names to avoid such conflicts? (preferably no)
These concerns are unnecessary. Some other languages use different
naming for module and variable (e.g. "sh::fs::foo" v.s. "sh.fs.foo").
Lua actually offers this as well (e.g. "require 'sh.fs'.foo" v.s.
"sh.fs.foo") if the modules don't utilize the `module` function [1].
The following is then valid:
local shfs = require "sh.fs"
assert(shfs and not sh) -- success
local sh = require "sh"
assert(sh and shfs and not sh.fs) -- success
[1] http://lua-users.org/wiki/LuaModuleFunctionCritiqued