Modules - jpbubble/NIL-isn-t-Lua GitHub Wiki

Modules are in NIL almost the same as classes, but where classes are initially just meant as a datatype, modules are more meant to be exported/imported as kind of libraries.

MyMod.nil

module MyMod

   void Hello()
        print("Hello World!")
   end

end

main.lua

NIL = require "NIL"
MyMod = NIL.Use("MyMod.nil")
M = MyMod.NEW()
M.Hello()

Or in pure NIL: main.nil

#use MyMod
var M
M = MyMod.NEW()
M.Hello()

NOTES:

  • In the original design multiple modules in a NIL file were supposed to be possible. This has been scrapped due to bugs and other issues.
  • When a module ends it will immediately be returned, meaning that if a module has its own classes and variables and stuff outside the module class, it must be declared first and the module itself must always be last.