TriggerEvent performing a copy on tables?

It seems that TriggerEvent is performing a copy of tables passed into it, as the table pointer changes and the metatable is not copied over. I can’t find any information about this - is this intended or a bug? Do I need to resort to sending a lookup key through event handlers instead?

local Class = {}

Class.__index = Class

function Class.New()
    local self = setmetatable({}, Class)

    self.data = 123

    print("1", self, getmetatable(self), self.data)

    return self
end

AddEventHandler("TestEvent", function(obj)
    print("3", obj, getmetatable(obj), obj.data)
end)

do
    local o = Class.New();

    print("2", o, getmetatable(o), o.data)

    TriggerEvent("TestEvent", o)

    print("4", o, getmetatable(o), o.data)
end
1        table: 0x7ff380c874c0   table: 0x7ff380c87200   123
2        table: 0x7ff380c874c0   table: 0x7ff380c87200   123 
3        table: 0x7ff382461c90   nil     123
4        table: 0x7ff380c874c0   table: 0x7ff380c87200   123
1 Like