Open goldenstein64 opened 3 years ago
What should happen when Copy.GlobalContext.Keys > {}
? Should keys in the metatable be copied and reassigned too?
I suppose Copy.GlobalContext.Keys > {}
if and only if Copy.GlobalContext.Meta > {}
, and both preferably contain "transform"
. This wouldn't make any sense at all to implement though. I guess I would just tell the end-user to only use it with keys that are uncopyable, like with a symbol.
A function counterpart might also be useful:
it("can use '__copy' as a metamethod", function()
local some = {
_private_property = "value",
_private_method = nil,
public_property = "other value"
}
local mt = {}
function mt.__copy(self, key)
if key:sub(1, 1) == "_" then
return "pass"
else
return "default"
end
end
setmetatable(some, mt)
local new = Copy(some)
expect(new._private_property).to.equal(nil)
expect(new._private_method).to.equal(nil)
expect(new.public_property).to.equal("other value")
end)
It might be more ergonomic to use metatables to describe how table sub-values are copied instead of
Copy:CreateContext
orCopy:BehaveAs
. It would be exactly what a metatable is used for, it would have exactly the same functionality asCopy:BehaveAs
, it would stay connected to the normal table (or multiple tables), and it would stay out of the way very easily.It might also make classes easier to implement?