lua-users home
lua-l archive

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


level is defined inside the function, it's an argument.

There is an implicit declaration

   local thing, level = <arg1>, <arg2>

at the beginning of the function. 'level' will have the value 'nil' if the caller does not pass in two or more arguments, but it's always defined and

   level = level or 1

just assigns  to this local variable.

argument lists and 'local' declarations create a scope for the names they introduce that runs to the end of the function or block they're contained in.

Ge'

spir wrote:
Hello,

output = function(thing, level)
   level = level or 1
   -- or
   if not level then level = 1
   ...
end

Is here 'level' local in the case it was not defined inthe calling expression? Or should I write:
   local level = level or 1
   -- or
   if not level then local level = 1
to ensure its "local-ity"?

The point imo is, if level is undef, then there is no reason for an assignment to implicitely make it local -- except if the compiler deduces this quality from the fact that the name happens to be the same as the one of a parameter. Or do I miss the point?

Denis
________________________________

la vita e estrany

http://spir.wikidot.com/