lua-users home
lua-l archive

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


On Mon, Sep 26, 2011 at 1:05 PM, KR <krunal.rao78@gmail.com> wrote:
> local min, max, sin, cos = ridx(math, "min, max, sin, cos")

Warning, this is a hack:

local function from(t)
  local j, k
  for i=1, math.huge do
    local name = debug.getlocal(2, i)
    if not name then break end
    if name == '_' then j = i end
    k =  i
  end
  assert(j, 'missing variable `_`')
  for i=j+1, k do
    local name = debug.getlocal(2, i)
    debug.setlocal(2, i, t[name])
  end
end

local _, lower, upper from(string)
local _, sqrt, abs from(math)
local x

assert(sqrt(4) == 2 and abs(-2) == 2)
assert(lower('Abc') == 'abc' and upper('Abc') == 'ABC')
assert(x == nil)

print 'DONE'