Modules - Saskyc/Lunacity-Wiki GitHub Wiki

What are modules?

Modules are scope seperators used to organise classes, static field & static properties under shared name.

Defining module

Firstly use the keyword module then name and double dot defining scope, lastly don't forget about end keyword to close the scope.

module Lorem:
end

Communication between modules

First definition:

Lorem => Module
Ipsum => Class
Dolor => Method

Second definition:

Sit => Module
Amet => Class
Dolor => Method

Defined method Consectetur (second definition) accesses method Dolor firstly through its module, secondly class and then its definition.

module Lorem:
	public class Ipsum:
		public static method Dolor()
		end
	end
end

module Sit:
    public class Amet:
		public static method Consectetur()
			Lorem.Ipsum.Dolor();
		end
    end
end

File based modules

File based module is defined once on top of the file and everything under is included in the module.

  • This type of definition doesn't require end keyword to close the scope.
module Lorem;
public class Ipsum:
	public static method Dolor()
	end
end

Invalid case

Only one file based module can be defined for this entire file.

  • When defining another one under it will not compile with exception %exceptionHere%
module Lorem;
public class Ipsum:
	public static method Dolor()
	end
end

module Sit;
public class Amet:
	public static method Consectetur()
		Lorem.Ipsum.Dolor();
	end
end

Family modules

  • Adipiscing and Elit are in family Sit.
module Sit;
module Sit.Adipiscing;
module Sit.Elit;