Object Oriented Programming - ADA-Funni/PsychEngine-Lua-Classes GitHub Wiki
How to add OOP (Object Oriented Programming) to your "class"
Big thanks to @voxov_tired for this part.
YourObject = {}
YourObject.__index = YourObject
--- @param tag string
--[[
This function creates your object.
]]--
function YourObject.new(tag)
local self = setmetatable({}, YourObject)
self.tag = tag
-- Code goes here.
return self
end
Name YourObject
the name of your script, only uppercase.
Leave YourObject
blank, it gets filled in when you call new()
.
(e.g. if your script is called "object_oriented_programming"
,
YourObject
should be named ObjectOrientedProgramming
.)
How to make an OOP (Object Oriented Programming) function
You're supposed to format it like this:
--- @param printEnabled boolean
--[[
This function does something.
]]--
function YourObject:functionName(printEnabled)
if printEnabled == true then
print(self.tag)
end
end