[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: syntactic sugar for imports and exports
- From: Mark Hamburg <mark@...>
- Date: Wed, 19 Oct 2011 17:00:36 -0700
On Oct 19, 2011, at 4:30 PM, Petite Abeille wrote:
>
> 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
That populates the environment but what one probably really wants are locals.
Mark
- 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
- Re: syntactic sugar for imports and exports, Petite Abeille