Per https://create.roblox.com/docs/luau/metatables
“the code searches through the list for the index, finds nothing, and then checks if there’s a metatable attached to the table, returning nil if there isn’t one.”
Because of this, am I right in assuming that the first option in the example below is more performant than metatable because it avoids the nil index check?
local function Test()
return true
end
local function CreateObject()
local self = {}
self.Test = Test
return self
end
local Object = CreateObject()
print(Object.Test())
---
local OOP = {}
OOP.__index = OOP
function OOP:Test()
return true
end
local function CreateObjectOOP()
local self = {}
setmetatable(self, OOP)
return self
end
local ObjectOOP = CreateObjectOOP()
print(ObjectOOP:Test())