lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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