[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: syntactic sugar for imports and exports
- From: Daurnimator <quae@...>
- Date: Thu, 20 Oct 2011 11:02:29 +1100
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.
- 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