I wish you could access your own locals with an
_LOCAL[idx] that would be faster than debug.getlocal...
Not sure how that'd work if you local x = _LOCAL, or called a
function with _LOCAL...
On 08/06/15 05:53 PM, Oliver Kroth
wrote:
Yes,
the "local" in front of "func1" and "func2" has the effect that
the names "func1" and "func2" are NOT members of _ENV. Instead
they are converted to registers, i.e. anonymous stack offsets.
Removing the "local":
function func1() print("local func1") end
function func2() print("local func2") end
local fn = { "func1", "func2" }
for i = 1, 3 do
local func_name =
fn[i]
pcall(_ENV[func_name])
end
should print
local func1
local func2
until you change the string literals, too :-)
pcall (null), which happens with calling pcall( _ENV( fn[3] ) is
captured and returns false pus a string saying "attempt to call a
nil value", which is ignored
--
Oliver
Am 08.06.2015 um 22:18 schrieb Milind
Gupta:
Is there a problem
doing it this way: ?
local function
func1() print("local func1") end
local function
func2() print("local func2") end
local fn = { "func1", "func2"
}
for i = 1, 3 do
local func_name
= fn[i]
pcall(_ENV[func_name])
end
--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.
|