2
2
mirror of https://github.com/Hilbis/Hilbish synced 2025-04-01 19:23:24 +00:00

fix(util): SetField on a table with a metatable causing panic

This commit is contained in:
TorchedSammy 2022-04-21 20:33:32 -04:00
parent bd35e3b871
commit abfd4e5196
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD

View File

@ -29,12 +29,16 @@ func SetField(rtm *rt.Runtime, module *rt.Table, field string, value rt.Value, d
if mt == nil { if mt == nil {
mt = rt.NewTable() mt = rt.NewTable()
docProp := rt.NewTable()
mt.Set(rt.StringValue("__docProp"), rt.TableValue(docProp))
module.SetMetatable(mt) module.SetMetatable(mt)
} }
docProp := mt.Get(rt.StringValue("__docProp")) 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)) docProp.AsTable().Set(rt.StringValue(field), rt.StringValue(doc))
module.Set(rt.StringValue(field), value) module.Set(rt.StringValue(field), value)