-
Notifications
You must be signed in to change notification settings - Fork 0
3. Creating a new Class
Tom O'Sullivan edited this page Nov 2, 2021
·
2 revisions
Creating a new Class is easy. You have two choices with ClassLoader, a Singleton and a regular Class.
Singletons are similar to how static classes work in C#, where your Class can have properties and methods but not be instantiated. For example, the Local User of an application can be represented with a class, but no more than one of them can exist at any time. To prevent multiple from existing we'd want to use a Singleton.
Creating a Singleton or Class works almost the same, however you cannot extend Singletons. Refer to the example below to create a basic logging class:
local Logger = Class() --Starts the definition of a Class.
local print = _G.print
function Logger:Log(msg) --This is an example of a public method that takes a message and logs it to the console.
print(msg)
end
return Logger -Returns the class to the ClassLoader.