[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: syntactic sugar for imports and exports
- From: Petite Abeille <petite.abeille@...>
- Date: Thu, 20 Oct 2011 01:30:25 +0200
On Oct 20, 2011, at 12:40 AM, Tony Finch wrote:
> The usual proposal to improve the first two is as follows, but I'm trying
> to find a more general solution.
What about something along these lines:
local function import( aName, ... )
local aModule = require( aName )
local aFunction = debug.getinfo( 2, 'f' ).func
local _, anEnvironement = debug.getupvalue( aFunction, 1 )
for anIndex = 1, select( '#', ... ) do
local aName = select( anIndex, ... )
anEnvironement[ aName ] = aModule[ aName ]
end
end
import( 'math', 'min', 'max' )
print( min )
print( max )
> function: 0x10001af60
> function: 0x10001aee0
- References:
- modules, require, magic, Eduardo Ochs
- Re: modules, require, magic, Javier Guerra Giraldez
- Re: modules, require, magic, Petite Abeille
- Re: modules, require, magic, Sam Roberts
- Re: modules, require, magic, David Manura
- Re: modules, require, magic, Hisham
- Re: modules, require, magic, Tony Finch
- Re: modules, require, magic, Hisham
- Re: modules, require, magic, Tony Finch
- syntactic sugar for imports and exports, Tony Finch