[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Seemingly inconsistency between function in a local variable and local function
- From: Robert Klemme <shortcutter@...>
- Date: Mon, 2 Apr 2012 14:22:25 +0200
Hi,
while musing about http://forum.luahub.com/index.php?topic=3559.0 I
ran across this:
do
--[[ all these do NOT work
local f2
local f2 = nil
local function f2() end
--]]
local function f1()
return f2()
end
local function f2()
return 123
end
function f()
return f1()
end
end
ok, error = pcall(function() print(f()) end)
if ok then
print('--OK')
else
print(error)
end
do
-- this works:
local g2
local function g1()
return g2()
end
--[[
but we cannot do
local function g2()
only if assigned like this:
--]]
g2 = function()
return 123
end
function g()
return g1()
end
end
ok, error = pcall(function() print(g()) end)
if ok then
print('--OK')
else
print(error)
end
Why is that? What did I overlook?
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/