Hello, I have separated that portion into a model. I will try to be as clear as I can.
What my module does is it will transform proxies, so they look like normal tables. You can use every single service with it and even extend datatypes! You will find a script called âExampleâ.
(We use getfenv() so that it updates the services)
local Proxy = require(script.Parent.Proxy)(getfenv());
--By sending the enviroment we have updated all the services
local myProxy = Proxy.new();
The script above creates a proxy.
So now letâs add a metatable! My module adds a custom meta function called â__updatedâ. This one will fire every time the index already exists but is updated.
local myMetatable = {
__newindex = function(self,k,v)
print("This will fire every new index.");
print("The key is", k, "\nAnd the value is", v);
rawset(self,k,v);
print("-----") --Just a break so that the output is separated neatly
end,
__updated = function(self,k,v)
print("This will fire every index that exists and is updated")
print("The key is", k, "\nAnd the value is", v);
rawset(self,k,v);
print("-----") --Just a break so that the output is separated neatly
end,
__index = function(self,k)
print("This will fire every index")
print("The key is", k);
print("-----") --Just a break so that the output is separated neatly
return "nice"; --since we return nice then all the indexes will return nice
end,
};
setmetatable(myProxy, myMetatable);
Done. Now you can use pairs, ipairs, rawset, rawget and all of those to act as normal. There is also an extra function that is extending datatypes
Did you ever wish you could extend Color3 so it has more properties? Me neither. But this module letâs you do that.
--[[
If you wish to merge different datatypes now you can!!
Proxy.new can take multiple tables at once.
]]
local mySpecialProxy = Proxy.new(Color3.new(), {}); --Since Color3 is passed in first then it will become the
-- main table *Look bellow for the unary operator*
warn("--Special proxy--");
print(mySpecialProxy.R);
mySpecialProxy.Nice = true; -- Nice is a new value so it will put it in the table
mySpecialProxy.R = 255; -- R already exists so it will modify that value
local myPart = Instance.new("Part");
--myPart.Color = mySpecialProxy; // Oh no! This errored, this is because the proxy is still a table
--If you wish to get the color itself you can use the unary operator
myPart.Color = -mySpecialProxy; --This works
print(myPart.Color);
You can also extend as many datatypes as you wish
--// You can also do this
warn("--Extra Special proxy--");
local myExtraSpecialProxy = Proxy.new(Color3.new(), CFrame.new(), {});
print(myExtraSpecialProxy.Position); --Prints the Position
print(myExtraSpecialProxy.R); --Prints R
print(-myExtraSpecialProxy); -- Prints the Color3
Model:
Example.rbxm (6.4 KB)
But mainly you literally only do this:
local myTbl = Proxy.new({
items = {
1, 2, 3, 4, 5
}
});
for _, item in myTbl.items do --> Expected output: 1, 2, 3, 4, 5
print(item)
end