[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: 'in' keyword today (was Re: mathlib)
- From: steve donovan <steve.j.donovan@...>
- Date: Wed, 9 Apr 2014 11:32:07 +0200
On Wed, Apr 9, 2014 at 10:33 AM, steve donovan
<steve.j.donovan@gmail.com> wrote:
> But this cure is arguably uglier than the disease...
Ah, but it doesn't look so bad if you let it run onto one line:
local insert, concat = slots(2) from (table)
local sin, cos = slots(2) from (math)
And here is an implementation sketch; a more optimized one would keep
track of the last slot used for a particular function, and call
require() if passed a string. Not terribly fast, but probably ok for
once-off initializations in a module.
It works, but ... just for entertainment value, you know ;) (Easy to
port to 5.2)
-----------------
local nslots
function slots (n)
nslots = n
local res = {}
for i = 1,n do res[i] = true end
return unpack(res)
end
function from (T)
local slot = 1
-- collect all the active locals
local locals, append = {}, table.insert
while true do
local loc,v = debug.getlocal(2,slot)
if not loc then break end
append(locals,loc)
slot = slot + 1
end
-- and set the last ones
for i = #locals-nslots+1,#locals do
debug.setlocal(2,i,T[locals[i]])
end
end
--------------
- References:
- Re: mathlib, Roberto Ierusalimschy
- Re: mathlib, Luiz Henrique de Figueiredo
- Re: mathlib, Roberto Ierusalimschy
- Re: mathlib, Christopher Berardi
- Re: mathlib, steve donovan
- Re: mathlib, Christopher Berardi
- Re: mathlib, Sean Conner
- Re: mathlib, Coroutines
- Re: mathlib, Sean Conner
- Re: mathlib, Christopher Berardi
- Re: mathlib, steve donovan
- Re: mathlib, Coroutines
- Re: mathlib, steve donovan
- Re: mathlib, Coroutines
- 'in' keyword today (was Re: mathlib), Petite Abeille
- Re: 'in' keyword today (was Re: mathlib), Rena
- Re: 'in' keyword today (was Re: mathlib), Philipp Janda
- Re: 'in' keyword today (was Re: mathlib), Coroutines
- Re: 'in' keyword today (was Re: mathlib), Dirk Laurie
- Re: 'in' keyword today (was Re: mathlib), steve donovan