# HG changeset patch # User Kim Alvefur # Date 1679829211 -7200 # Node ID 2cf8d98d8a283c7ded00ea5047a17c029664750b # Parent 895a82c5d8d47811cc430e25716ef51b013af58e util.roles: Implement a serialization preparation metamethod Should be able to roundtrip trough serialization. Also nice for debug and logging purposes where you might want more details than what the __tostring method provides. diff -r 895a82c5d8d4 -r 2cf8d98d8a28 util/roles.lua --- a/util/roles.lua Sun Mar 26 13:07:20 2023 +0200 +++ b/util/roles.lua Sun Mar 26 13:13:31 2023 +0200 @@ -73,6 +73,19 @@ return setmetatable(new_role, role_mt); end +function role_mt:__freeze() + local t = { + id = self.id; + name = self.name; + description = self.description; + default = self.default; + priority = self.priority; + inherits = self.inherits; + permissions = self[permissions_key]; + }; + return t; +end + function role_methods:clone(overrides) return new(self, overrides); end