LUA function question

are there any functional/scope differences between how these 2 functions (bar1, bar2) are defined?

[code]
local foo = function(params)
local bar1 = function()
print(“bar1!”)
end

function bar2()
print(“bar2!”)
end

end
[/code] [import]uid: 107352 topic_id: 18748 reply_id: 318748[/import]

bar1 is a function local to foo. You cannot access it outside.
bar2 is a global function. [import]uid: 64174 topic_id: 18748 reply_id: 72128[/import]

how could I call bar2() from outside foo? foo is defined as a function.

is defining global functions inside function a bad idea? not a good practice?

thanks in advance, [import]uid: 107352 topic_id: 18748 reply_id: 72131[/import]

I’d say it’s bad practice to declare global functions from inside another function, even if it’s possible.

Take a look at this:

local foo = function(params)  
  
 local bar1 = function()  
 print("bar1!")  
 end  
 function bar2()  
 print("bar2!")  
 end  
  
 bar1() -- is local, only works here  
end  
  
foo() -- must be called to declare bar2()...  
bar2() -- ...to make this work  

-finefin [import]uid: 70635 topic_id: 18748 reply_id: 72148[/import]

Yupp, avoid declaring global function bodies at anywhere but global scope to avoid confusion with local functions. If I see a global function body declared inside another function I presume it’s a mistake. [import]uid: 58849 topic_id: 18748 reply_id: 72268[/import]