I kind of have an idea of what it is, only because of code I've looked at with wrapper in the title. However, I'm really not exactly sure what it is. It seems like a way to make proxy methods that interact with an original value, but that would be a complete guess.
According to past content I've seen, would this random example I made qualify as a wrapper? This would just be a function that adds a method called PrintName to an object.
function wrap(obj)
local new = {}
-- The custom method
function new:PrintName()
print(obj.Name)
end
-- Returning default methods / properties
local t = setmetatable(new,{
__index = function(t,k)
local v = obj[k]
if type(v) == 'function' then
return function(_,...)
v(obj,...)
end
else
return obj[k]
end
end
})
-- Return it
return t
end
local p = wrap(Instance.new("Part",workspace))
p:PrintName() -- call added method
p:Destroy() -- use built-in method
I've provided code similar to this before, however the question was a lot different. I would just like to know if this qualifies as a wrapper, or if there's a lot more to it than that.
If anyone could explain this concept, or even give an example, I'd really appreciate it. Thanks for reading!
