From abfd4e5196da3569372598f058fc0ddf4ab3311e Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Thu, 21 Apr 2022 20:33:32 -0400 Subject: [PATCH] fix(util): SetField on a table with a metatable causing panic --- util/util.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/util/util.go b/util/util.go index c1688e0..e46d4b2 100644 --- a/util/util.go +++ b/util/util.go @@ -29,12 +29,16 @@ func SetField(rtm *rt.Runtime, module *rt.Table, field string, value rt.Value, d if mt == nil { mt = rt.NewTable() - docProp := rt.NewTable() - mt.Set(rt.StringValue("__docProp"), rt.TableValue(docProp)) module.SetMetatable(mt) } + docProp := mt.Get(rt.StringValue("__docProp")) + if docProp == rt.NilValue { + docPropTbl := rt.NewTable() + mt.Set(rt.StringValue("__docProp"), rt.TableValue(docPropTbl)) + docProp = mt.Get(rt.StringValue("__docProp")) + } docProp.AsTable().Set(rt.StringValue(field), rt.StringValue(doc)) module.Set(rt.StringValue(field), value)