lua-users home
lua-l archive

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


By the way... having a default argument for a boolean:

  function Show(show=true)
    -- ...
  end

  Show(nil)   --> Show(true)  -- use default
  Show(true)  --> Show(true)  -- arg not nil, use arg
  Show(false) --> Show(false) -- arg not nil, use arg

should behave differently from simply using 'or' on the argument:

  function Show(show)
    show = show or true -- (not a good idea!)
    -- ...
  end

  Show(nil)   --> Show(true) -- use default
  Show(true)  --> Show(true) -- arg not nil/false, use arg
  Show(false) --> Show(true) -- unintentionally use default (oops)

--
  Enrico