From d638abc7c54b437b9bbe6ebbc04c27a5ec6489f5 Mon Sep 17 00:00:00 2001 From: Mingun Date: Sun, 21 Apr 2024 00:39:03 +0500 Subject: [PATCH] Return the raw value if enum value couldn't be found Fixes https://github.com/kaitai-io/kaitai_struct/issues/778 for Lua --- enum.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/enum.lua b/enum.lua index 53af9ac..0eb2cee 100644 --- a/enum.lua +++ b/enum.lua @@ -17,10 +17,12 @@ function enum.Enum(t) end return setmetatable(e, { + -- Returns an enums instance by a variant name __index = function(table, key) return rawget(table._enums, key) end, + -- Creates an enum instance from the value __call = function(table, value) for k, v in pairs(table._enums) do if v.value == value then @@ -28,7 +30,7 @@ function enum.Enum(t) end end - return nil + return value end, __eq = function(lhs, rhs)