9

I'm developing a plugin for Oxide 2. I've been learning from other plugins and I've noticed that some of them use null instead of nil. For example:

if args[1] == null then

Oxide 2 is written in C#, so I assume that null is defined in C# or in Lua Interface.

Is there any difference between them?


Update: I've somewhere read that it can be used for check, if MySQL column is NULL. Is that true?

Genhis
  • 1,484
  • 3
  • 27
  • 29
  • You mean `var = nil` as well as `var = null`? Barring any special embedded details `null` is just a variable (that probably has no value and so will be `nil`) but could be assigned to normally otherwise. Try `print(null); null = "foo"; print(null)` in a normal lua interpreter for example. – Etan Reisner Jul 09 '15 at 16:39
  • @EtanReisner At first it printed `null`, but after modification it printed `foo`. So it seems to be a normal variable. – Genhis Jul 09 '15 at 16:53
  • In normal lua it is. I can't speak to what Oxide did when they embedded it or if some library uses `null` as some special sentinel. – Etan Reisner Jul 09 '15 at 17:24

1 Answers1

20

nil is a value in the Lua language.

null is a variable name. What value does it contain? You can easily check that. We cannot. If it turns out to be nil, then using null is pointless, probably a mistake made by someone context switching between C# and Lua code which accidentally works because an undefined variable will evaluate to nil.

Mud
  • 28,277
  • 11
  • 59
  • 92