The '#pure' directive - jpbubble/NIL-isn-t-Lua GitHub Wiki

The pure directive just causes NIL to ignore most of itself (except for lines prefixed with a '#' and macros), and will just copy the next lines into Lua until '#endpure' was found.

In some situations using NIL just isn't the best thing to do, and leaving it then to Lua itself can be a better option.

CAUTION

Using "#pure" is a pretty dangerous thing to do. Especially for large parts of code it should NOT be done (importing a Lua script with #use can then be a better option really). #pure stops all NIL checkups so once "#endpure" is encountered NIL will not know what you all did, and just assume you did nothing at all, and that can lead to pretty funny, sometimes impossible to debug situations.

For example, this WILL cause an error:

if myvar==1 
   print("Hello")
   #pure
   print("Anybody, home?")
end
#endpure

NIL must be able to check if the "if" statement started in NIL code is properly ended with the "end" keyword (when dealing with classes or switch statements NIL can't rely on Lua for this, plus since NIL also checks if all locals are declared, it needs to know when a local no longer exists, so that's why it checks).

And this also won't work:

void WontWork()
  #pure
  local a=1
  #endpure
  print(a)
end

But this will

void WillWork()
  int a=1
  #pure
  print(a)
  #endpure
end

There is no way NIL can know that you declared a local within the #pure block. Even globals created in pure-blocks cannot be read, as NIL can only update its globals list when the translation has been completed and been compiled by Lua, and all what #pure does is just copy the lines into the translation, but that does not complete it.

Altogether it's best to avoid using #pure as much as possible, and even better not to use it at all, unless you know what you are doing, and when you are pro enough to deal with the risks you take by using it.