lua-users home
lua-l archive

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

import(io) -- localize all string-key values in the io table

Even if it were possible, I don't think this is a good idea.  It would encourage people to dump unnecessary locals into their scripts -- inflating the generated byte code for no terribly good reason.  When reading a script, programmers wouldn't be able to tell whether a given "global" was actually global, or was being shadowed by an implicitly added local.

I want to create locals in batch and not simply modify the _ENV to "pass through" to the 'table' table (hah).  Sometimes modifying _ENV is not an option or is just ~inappropriate~.

If what you want is convenience, there's any number of neat _ENV tricks than can help here.  For example, if you don't want to pass definitions through to the original table, you can do something like:

local _ENV = setmetatable({env=_ENV},{__index=_ENV})

But if what you're after is efficiency, I suspect wildcard localizing would hurt more than it helps.