[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Microlight (was Re: paving cowpaths with libraries)
- From: Miles Bader <miles@...>
- Date: Fri, 17 Feb 2012 17:00:34 +0900
Dirk Laurie <dirk.laurie@gmail.com> writes:
>> You can make ml.table callable, so that one can skip the 'export'.
>
> require 'ml.table'(_ENV)
> require 'ml.table'() -- put it in the local function environment
One could actually just use the first form always for maximum
portability: "_ENV" in Lua 5.1 is just nil, so the exporter function
can simply test for nil and stick the result in the caller's fenv in
that case (and maybe signal an error in 5.2, since it doesn't have
fenvs).
> mlt = require 'ml.table'{} -- put it in a forgettable table
Hmm, that's generally not required though, right (since one can just
use the shared table directly in most cases)?
Is the "put into _ENV" variant really all that useful in practice,
since function names intended for "module.function" usage are often
likely to be short and prone to namespace conflicts if injected into a
common environment...?
Being able to specify a limited set of function to inject, possibly
with some renaming, would maybe be more controllable.
E.g.,:
require 'blah.barf' (_ENV, { "fun1", "fun2" }, "prefix_")
... or... something...
:/
-Miles
--
If you can't beat them, arrange to have them beaten. [George Carlin]