I’ve been trying to add methods to Vector3 and CFrame to make some of my code a little neater. However since they’re read-only tables, I can’t add to them. Is there a way to get around this?
This is what I’m trying to do:
function Vector3:DotSelf()
return self:Dot(self);
end;
local function MakeEditable(...)
local Args, Return=table.pack(...), {}
for Index=1, #Args, 1 do
local Item=Args[Index]
if type(Item)=="table" then
local New=setmetatable({}, {__index=Item})
Return[Index]=New
elseif (Item~=nil and type(tostring(Item))=="string" and type(getfenv()[tostring(Item)]=="table")) then
local Old=getfenv()[tostring(Item)]
getfenv()[tostring(Item)]=setmetatable({}, {__index=Old})
Return[Index]=Old
end
end
return table.unpack(Return)
end
MakeEditable("string", "table", "Vector3", "CFrame")