-
Notifications
You must be signed in to change notification settings - Fork 0
5. Importing a Class
Tom O'Sullivan edited this page Nov 3, 2021
·
1 revision
Now that we have more than one class, we're able to import it from a different location. For this example, you'll need to move your Logger class outside of the package the Main class is located in (we'll be using dev.tomdotbat.test.logging
).
Now the Logger is in a different environment, so the Main class won't be able to access it without importing it. The code example below shows how we can import it and change our existing code to use the logger instead:
Import("dev.tomdotbat.test.logging.Logger") --Imports the Logger into the current file's environment, it'll be accessible by referencing `Logger`.
local Start = Singleton()
function Start:Main()
local logger = Logger:New() --Create an instance of the Logger class.
logger:Log("Hello World!")
end
return Start