lua-users home
lua-l archive

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


Roberto>  For old libraries and functions, changing nil to false may cause
incompatibilites. New libraries and functions, however, are free
to use false instead of nil. The new function 'debug.setcstacklimit'
in the standard library does that.

Of course no change for existing functions; my question was what is
your suggestion for new code. I guess the 'debug.setcstacklimit'
example is the answer. Thanks.


 Oliver> there are function returning a boolean value, which in case of
 Oliver> failure need to return a third, distinct value. nil. Think of a
 Oliver> function that for a file name returns whether it is a directory
 Oliver> or not.

The idiom being "return false, msg" in case of error,  I guess it
could be used that way:

  local isdir, msg = is_directory(fpath)
  if  isdir and msg then do_error_things(msg)
  elseif  isdir then do_directory_things()
  else fo file_things()
  end

testing for error could  just be testing on msg instead of testing
equality to nil.

Andrew> Ah yes, the classic "true", "false", "FileNotFound"
> https://thedailywtf.com/articles/What_Is_Truth_0x3f_

:-)