lua-users home
lua-l archive

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


2013/3/26 Vadim Peretokin <vperetokin@gmail.com>:
> You can do value = value or default as a pattern to prevent that
> problem.
>
> Otherwise, the only real problem are upvalues, as those can't be
> updated (or easily?).

do
  local x=10
  function diff(y) return y-x end;
  function sum(y) x=20; return y+x end
end

print(diff(100)) --> 90
print(sum(100))  --> 120
print(diff(100)) --> 80