lua-users home
lua-l archive

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


What about writing your own null checking function?

function isnull(value)
  if value is nullptr: return nil
  if value is nil: return nil
  if not value: return value
  return true
end

Then use it everytime you want to check it.

if isnull(myvaluefromfunction) then ... end

I suppose in Lua convention you can name it "isnil" instead of "isnull".

On Fri, Jun 30, 2017 at 9:24 AM, Duane Leslie <parakleta@darkreality.org> wrote:
> On 30 Jun 2017, at 02:51, ThePhD <jm3689@columbia.edu> wrote:
>
> This prevents me from doing "some_userdata == nil" and having it return true in the case of working with something like a nullptr. I want to keep the ease-of-use/"C-like" style of comparing against Nil, but I cannot invoke a metamethod to check. Does anyone have any suggestions? I'm open to just about anything, and obviously the more elegant/syntax-clean suggestion the better.

I needed the same, and so I run a modified version of the equality test function, attached.  If you control the Lua interpreter you can always tweak it, you just need to be careful to vet any third party packages you use to make sure that your modified behaviour doesn't confuse it.

Regards,

Duane.