Nil is a special value denoting the absence of a value, and has the type nil.[1] It is often returned by functions to indicate an error condition, usually along with an error message as the second return value. Such functions include loadfile and loadstring.[2] It is good practice to check if a variable is nil before using it in cases where nil is a possible value, to prevent errors such as "attempt to call nil" or "attempt to index ? (a nil value)", which will happen when a nil value is used regardless. In tables, setting the value of a key to nil will delete the key.[1] Attempting to use nil as a key in a table produces an error.


  1. Ierusalimschy, Roberto (March 2006). Programming in Lua. p. 29. ISBN 8590379825.
  2. Ierusalimschy, Roberto (March 2006). Programming in Lua. p. 83. ISBN 8590379825.
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.