[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: syntactic sugar for imports and exports
- From: Josh Simmons <simmons.44@...>
- Date: Thu, 20 Oct 2011 13:51:07 +1100
On Thu, Oct 20, 2011 at 11:02 AM, Daurnimator <quae@daurnimator.com> wrote:
> On 20 October 2011 10:30, Petite Abeille <petite.abeille@gmail.com> wrote:
>>
>> 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 isn't equivalent; we like to have the functions as locals:
>
> local max , min = math.min , math.max
>
> you can't make a function of it, because you can't create/add locals
> in the current point in lua evolution.
>
>
I will note that this has been suggested and implemented before at least once.
http://lua-users.org/lists/lua-l//2005-09/msg00219.html
- 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
- Re: syntactic sugar for imports and exports, Daurnimator